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

Lab 7

This document provides instructions and examples for using arrays in Java programs. It includes two tasks: 1) Creating an array to calculate the total of elements and allowing a user to input sales data to calculate total bottle sales. 2) Creating an array to calculate the average (mean) of elements and examples calculating the average height of students and average of integers in an array. It concludes with two exercises to write programs calculating totals and averages of temperature and number of clinic patients over a given period using arrays.

Uploaded by

CheeYan Tiew
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)
75 views4 pages

Lab 7

This document provides instructions and examples for using arrays in Java programs. It includes two tasks: 1) Creating an array to calculate the total of elements and allowing a user to input sales data to calculate total bottle sales. 2) Creating an array to calculate the average (mean) of elements and examples calculating the average height of students and average of integers in an array. It concludes with two exercises to write programs calculating totals and averages of temperature and number of clinic patients over a given period using arrays.

Uploaded by

CheeYan Tiew
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
You are on page 1/ 4

LAB MODULE

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:

a. Calculate and print total temperature recorded in the array.

b. Calculate and print average of temperature in the array.

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:

a. Calculate and print total patients recorded in a week.

b. Calculate and print average of patients recorded in a week.

SC 015 Page: 4

You might also like