Primitive Type Arrays Exercises
Primitive Type Arrays Exercises
Question 1:
Create the following application class called ArrayStuff by following the UML class diagram
and class description table.
ArrayStuff
+ main(String[]): void
+ displayNumbers(int[]): String
+ countEven(int[]): int
+ sortArray(int[]): void
+ determineSameDigits(int): boolean
Take note that a student can have more than one name, but it is still one element in the
array. The names are separated by a space. You will have to look at the split() method of the
String class.
Make use of one for loop to print the information of each student to look like this:
Student number:
Surname:
Initials:
Question 3:
Create an application called CoronaStats as shown in the UML class diagram and explained
in the description table. The application will be used to look at the Corona Virus statistics in
the provinces in South Africa.
CoronaStats
+ main(String[]): void
+ recoveryRate(String, String[], int[], int[]): double
+ infectionsLessThan(int, int[]): int
+ lowestInfections(String[], int[]): String
Method Description
main(String[]) Complete these steps in the main method:
Declare and populate the provinces array that stores the names
of the 9 provinces of South Africa ("Limpopo", "Mpumalanga",
"Gauteng", "North West", "Northern Cape", "Free State",
"Kwazulu Natal", "Western Cape", "Eastern Cape").
Declare and populate the infections array that is a parallel array
to the provinces array that stores the number of infections for
each province (8562, 6687, 16589, 3874, 1005, 8333, 15578,
16368, 13698).
Declare and populate the recoveries array that is a parallel array
to the provinces and infections arrays that stores the number of
recoveries for each province (8000, 6300, 14500, 3200, 850,
7956, 14975, 15974, 12879).
Let the user enter the name of the province for which to
determine the recovery rate.
Invoke the recoveryRate() method with the required arguments
and display the recovery rate of the specified province as a
percentage.
Generate a random number in the range of 5000 to 15000 to be
used as the value to determine the number of provinces with
infections less than this value.
Invoke the infectionsLessThan() method with the required
arguments and display the number of provinces with infections
less than the specified value.
Invoke the lowestInfections() method with the correct
arguments and display the province with the least number of
infections.
recoveryRate(String, String[], int[], int[]) The method is used to determine and return the recovery rate of a
specified province.
The method will receive as parameters the specified province name as
well three parallel arrays.
Determine as a percentage the recovery rate of the specified province
and return this value.
infectionsLessThan(int, int[]) This method will count and return the number of provinces that have
infections less than the specified value.