0% found this document useful (0 votes)
4 views4 pages

Java Programming: Variables & Constants Lab

This document outlines a lab module focused on variables and constants in Java programming. It includes six activities that guide students to write pseudocode and Java programs for various tasks, such as calculating the square of integers, circle properties, extracting birth dates from identity card numbers, converting string cases, calculating speed, and statistical parameters. Each activity specifies objectives, problem descriptions, and estimated completion times.

Uploaded by

aiman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Java Programming: Variables & Constants Lab

This document outlines a lab module focused on variables and constants in Java programming. It includes six activities that guide students to write pseudocode and Java programs for various tasks, such as calculating the square of integers, circle properties, extracting birth dates from identity card numbers, converting string cases, calculating speed, and statistical parameters. Each activity specifies objectives, problem descriptions, and estimated completion times.

Uploaded by

aiman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER4

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]

FTKKI, UMT | CSF3034–PROGRAMMING 1


CHAPTER4

MODULE 4 VARIABLES AND CONSTANT

4.2 Activity2

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𝜋𝑟
𝑎𝑟𝑒𝑎 = 𝜋𝑟 !
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]

FTKKI, UMT | CSF3034–PROGRAMMING 2


CHAPTER4

MODULE 4 VARIABLES AND CONSTANT

4.4 Activity 4

4.4.1 Objective

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

4.4.2 Problem Description

Write a Java application that reads a String characters in lowercase and convert the characters to
uppercase and vice versa. 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]

4.5 Activity 5

4.5.1 Objective

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

4.5.2 Problem Description

Write a Java program to obtain distance in meters and time in hours, minutes and seconds from user. The
program then should be able to calculate and display the speed, in meters per second, kilometers per
hour and miles per hour. Note : 1 mile = 1609 meters & 1 kilometer = 1000 meters. You are required to
do

i. Design the algorithm in pseudocode.


iii. Write a Java application using JOptionPane class.

[Estimated Time: 30 minutes]

FTKKI, UMT | CSF3034–PROGRAMMING 3


CHAPTER4

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 x1, x2, x3. The program should be able toread these values from the
keyboard and print the results.

"! #"" #"#


a) Mean: 𝜇 = $

("! &')" #("" &')" #("# &')"


b) Variance: 𝜎 ! = $

c) Standard deviation: 𝜎 = √𝜎 !

You are required to:

i. Design the algorithm in pseudocode.


ii. Write a Java application using Scanner class.

[Estimated Time: 50 minutes]

FTKKI, UMT | CSF3034–PROGRAMMING 4

You might also like