Docsity

Lab 4: Variables and Constants in Java Programming, Study notes of Laboratory Practices and Management

Toggle sidebar
bg1
CHAPTER4
MODULE 4
VARIABLES AND CONSTANT
FTKKI, UMT | CSF3034 โ€“PROGRAMMING
1
LAB 4 โ€“Variables and Constant
Objectives:
At the end of this lab, the students are able to:
i. use identifiers to name variables, constants, methods and classes
ii. use operators and expressions in the program
4.1 Activity 1
4.1.1 Objective
Writing pseudocode and Java program by exploiting the use of variables and integer data type.
4.1.2 Problem Description
You are required to write a Java program that asks the user to enter two integers, obtains them from the
user and prints the square of each, the sum of their squares and the difference of the squares (first number
squared minus the second number squared) . In order to solve the problem, you need to do the following
tasks:
i. Design the algorithm in pseudocode.
ii. Write a Java application using Scanner class.
[Estimated Time: 30 minutes]
pf3
pf4

Partial preview of the text

Download Lab 4: Variables and Constants in Java Programming and more Study notes Laboratory Practices and Management in PDF only on Docsity!

MODULE 4 VARIABLES AND CONSTANT

LAB 4 โ€“ Variables and Constant

Objectives:

At the end of this lab, the students are able to: i. use identifiers to name variables, constants, methods and classes ii. use operators and expressions in the program

4.1 Activity 1

4.1.1 Objective

Writing pseudocode and Java program by exploiting the use of variables and integer data type.

4.1.2 Problem Description

You are required to write a Java program that asks the user to enter two integers, obtains them from the user and prints the square of each, the sum of their squares and the difference of the squares (first number squared minus the second number squared). In order to solve the problem, you need to do the following tasks: i. Design the algorithm in pseudocode. ii. Write a Java application using Scanner class. [Estimated Time: 30 minutes]

MODULE 4 VARIABLES AND CONSTANT

4.2 Activity

4.2.1 Objective

Writing pseudocode and Java program by exploiting the use of variables and constants.

4.2.2 Problem Description

Writea programthat inputs from the user the radius of a circle as a String and prints the circle's diameter, circumference and area using the floating-point value. The formulas to calculate the diameter, circumference and area of a circle are given below. The value for ฯ€ is 3.14159. ๐‘‘๐‘–๐‘Ž๐‘š๐‘’๐‘ก๐‘’๐‘Ÿ = 2 ๐‘Ÿ ๐‘๐‘–๐‘Ÿ๐‘๐‘ข๐‘š๐‘“๐‘’๐‘Ÿ๐‘’๐‘›๐‘๐‘’ = 2 ๐œ‹๐‘Ÿ ๐‘Ž๐‘Ÿ๐‘’๐‘Ž = ๐œ‹๐‘Ÿ^2 i. Design the algorithm in pseudocode. ii. Write a Java application using JOptionPane class. [Estimated Time: 30 minutes] 4.3 Activity 3

4.3.1 Objective

Writing pseudocode and Java program by exploiting the use of variables and class String.

4.3.2 Problem Description

Write a Java program that receives identity card (IC) number as a twelve digits string from the user. Then, the program should be able to identify birth date in the formatDD-MM-YYYY by extracting the first six first digits of the IC number. The program also able to calculate the current age based in the birth date extracted. To solve the problem, you are required to: i. Design the algorithm in pseudocode. ii. Write a Java application using JOptionPane class. [Estimated Time: 30 minutes]

MODULE 4 VARIABLES AND CONSTANT

4 .6 Activity 6

4 .6.1 Objective:

Writing pseudocode and Java program by exploiting the use of variables and constants.

4 .6.2 Problem Description:

Develop a Java program to calculate means, variance and standard deviation of the following statistical parameters of three values x 1 , x 2 , x 3. The program should be able toread these values from the keyboard and print the results. a) Mean: ๐œ‡ = ๐‘ฅ 1 +๐‘ฅ 2 +๐‘ฅ 3 3 b) Variance: ๐œŽ^2 = (๐‘ฅ 1 โˆ’๐œ‡)^2 +(๐‘ฅ 2 โˆ’๐œ‡)^2 +(๐‘ฅ 3 โˆ’๐œ‡)^2 3 c) Standard deviation: ๐œŽ = โˆš๐œŽ^2 You are required to: i. Design the algorithm in pseudocode. ii. Write a Java application using Scanner class. [Estimated Time: 50 minutes]