0% found this document useful (0 votes)
55 views2 pages

CSBP221

This document outlines the instructions for Lab 4 of the Programming Lab II course. It includes two sets of exercises. The first set is to be completed in the lab with the instructor and involves defining a method to calculate factorials and writing a program to manipulate a one-dimensional array. The second set includes writing programs to read temperature data from a file into an array, compare and analyze two arrays, and calculate averages. Students are expected to work in pairs and submit their solutions by the end of the lab period.

Uploaded by

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

CSBP221

This document outlines the instructions for Lab 4 of the Programming Lab II course. It includes two sets of exercises. The first set is to be completed in the lab with the instructor and involves defining a method to calculate factorials and writing a program to manipulate a one-dimensional array. The second set includes writing programs to read temperature data from a file into an array, compare and analyze two arrays, and calculate averages. Students are expected to work in pairs and submit their solutions by the end of the lab period.

Uploaded by

maryam mukhtar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Programming Lab II (CSBP221)

Spring 23

Lab 4

Objective and Overview:


 To manipulate One-Dimension arrays.
 To use predefined and user defined methods.
CLO: This lab maps to CLOs #1,2
Instructions:
 The first set of exercises is to be solved together in the lab with the instructor.
 The second set of exercises is to be solved by students. Students may work in groups of 2.
 All lab exercises must be submitted by the end of each lab (one submission per group).

SET: 1

Exercise#1: Define a method called calacFactorial that acepts one argument as an integer to
calculate and return the factorial of a given number N by user input.

Exercise #2: Write a Java program that declares an array numbers of 50 integer elements.

a. Initialize the array so that the first 25 elements are equal to the square of the
index variable and the last 25 elements are equal to three times the index variable.

b. Print out the array values, so that each 10 elements per line are printed.

c. Redo part a, but the first 25 elements are randomly generated between
and 10 and 50 and the last 25 elements are randomly generated between -25
and 25.

d. Count and display how many elements are positive and how many are negative.

e. Find and print the maximum value and the minimum value in the array.

SET: 2

Exercise #1:

a. Write a Java program initializing an array called “tempReadings”, of type double,


size 28, and with global visibility.
b. The program reads 28 values from a given file and save them to the array.
1/2
c. The program must be able to answer the following questions based on the user
selection:
a. The average temperature value during the month.
b. The average temperature value for a specific week.
c. The maximum temperature value during the month.
d. The maximum temperature value for a specific week.
e. The minimum temperature value during the month.
f. The minimum temperature value for a specific week.
g. Exit the program (the program must run continuously till the option ‘g’
selected)
Exercise #2: Write a program that performs the following:

a. Declare two arrays called arrayA and arrayB that holds integers, and the size
of the two arrays N is given by the user.

b. The main method calls a method called fillArray(…) of type void to fill an array
with a set of random generated integers between 7 and 33. This method
should be called twice to fill arrayA and then arrayB.

c. The main method calls another method called printArray (…) of type void to
display the elements of the array 5 elements per lines. This method should be
called twice to print arrayA and then arrayB.

d. The main method calls another method called count (…) of type integer to count
and return the total number of integers greater than a value enter by the user
(passed to the function).
e. Then the main methods calls another method called isSame( … ) of type boolean
to check if the two arrays arrayA and arrayB have the same elements or not.

f. The main method calls a method called findAverage(…) of type double that
calculates and returns average of all the values in arrayA or arrayB.

Then, main method calls a method called aboveAverage(…) of type integer that
finds and returns how many numbers in arrayA are above the average

2/2

You might also like