Lab 7
Lab 7
LAB
7
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: Total
Problem Statement: Write a program that creates an array of 10 elements size. Your program
should prompt the user to input integers in array, then calculate and display the total of all
array elements.
Type the following program into TextPad. Then, run and compile the program. Observe the
output.
Test Data:
SC 015 Page: 1
LAB MODULE
Expected Output:
Checkpoint 1:
Miti sells her homemade strawberry jam to her colleagues. The sell price of each bottle of
jam is RM15.50. She needs a program which she can store quantity of bottle sold daily and
display the total sales for a week. Create a Java program that allow Miti to enter quantity of
bottle sold in a week, in an array and display total sales for a week. Compile and run the
program. Save your program as JamTSales.java.
Test Data:
Expected Output:
SC 015 Page: 2
LAB MODULE
Task 2
Array operation: Average (mean)
Problem Statement: In a java program, create an array name height to hold double values.
This program will require user to input height in metre (m) of students in a class into the
array. 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 calculate and display the average height.
Type the following program into TextPad. Then, run and compile the program. Observe the
output.
Test Data:
Sample Output:
Checkpoint 2:
Write a Java program to find average of an array. The array will hold 10 integer values
entered by user. Save your program as IntAverage.java.
Test Data:
SC 015 Page: 3
LAB MODULE
Expected Output:
Exercise
1 Write a Java program that prompts for and reads in the temperature for 10 days
into an array, temperature. The program should:
2 Write a complete Java program that will store number of patients attended in a
clinic. The array, patient, will hold integer values for a week. The program
should:
SC 015 Page: 4