You are on page 1of 5

LAB MODULE

LAB
8
Java Language Programming
3.4 Array
Objective:
• Construct programs that perform one-dimensional array operations for
problems involving frequency and total.
Task 1
Array operation: Maximum value (highest/biggest value)
Problem Statement: Write a complete Java program which initialized a group of marks in an
array as follows:
97.5 75.3 53.1 86.4 64.8 42.0 100.0 57.9 46.8 90.0
Find the highest mark.
Type the following program into TextPad. Then, run and compile the program. Observe the
output.

Expected Output:

SC 015 Page: 1
LAB MODULE
Checkpoint 1:
Write a Java program that will accept 10 integers from user. The input from user will be
stored in an array, integer. The program will display the highest value. Compile and run
the program. Save your program as MaxInteger.java.
Test Data:

Expected Output:

SC 015 Page: 2
LAB MODULE
Task 2
Array operation: Minimum value (lowest/smallest value)
Problem Statement: In a java program, create two arrays, name and height to hold name
and height of students in a class. This program will require user to input name and height in
meter (m) of students in a class into both arrays respectively. At the beginning of program,
user will prompt to input the number of students in a class. This number will become the
array size. Then display the name and height of students with lowest height.
Type the following program into TextPad. Then, run and compile the program. Observe the
output.

Test Data:

Sample Output:

SC 015 Page: 3
LAB MODULE
Checkpoint 2:
Create a Java program that will store temperature (in degree Celsius) for a week. The day and
temperature will be stored in arrays named day and temp respectively. Then display the day
with the lowest temperature. Compile and run the program. Save your program as
LowTemp.java.
Test Data:

Expected Output:

SC 015 Page: 4
LAB MODULE
Exercise
1 The following table shows the sales report of the first half year for a used car sales
company.

Month Jan Feb Mar Apr May Jun

Sales 30 28 35 25 33 18

According to the above table, write a program that takes values from arrays month and
sales. The program should:

a. display the highest sales and month for the first half year.

b. display the lowest sales and month for the first half year.

2 Taming Sari Tower is a 110-meter high tower which is able to rotate 360 degrees for
visitors to see the panorama of the City of Melaka. Write a class passenger in which
total passenger for every month in a year is stored into an array of integer, taming. The
program should calculate and display the following :

a. Total passenger for a year.


b. Average monthly passenger.
c. Number of months that above average
d. List all months that below average
e. The month with highest passenger number.

You are required to write a program to display the following output (sample output).
Sample input Sample output
Enter passenger of month 1: 3000 Total passenger for the year: 51872
Enter passenger of month 2: 3567 Average monthly passenger: 4322
Enter passenger of month 3: 4700 Number of month that has passenger above average: 6
Enter passenger of month 4: 3800 At month 1 the passenger that below average is 3000
Enter passenger of month 5: 5380 At month 2 the passenger that below average is 3567
Enter passenger of month 6: 4500 At month 4 the passenger that below average is 3800
Enter passenger of month 7: 4000 At month 7 the passenger that below average is 4000
Enter passenger of month 8: 4445 At month 9 the passenger that below average is 4200
Enter passenger of month 9: 4200 At month 10 the passenger that below average is 3500
Enter passenger of month 10: 3500 The month with the highest passenger is month 12
Enter passenger of month 11: 5280
Enter passenger of month 12: 5500

SC 015 Page: 5

You might also like