Suggested Solution

Task 1 Task 2 Task 3 Task 4 Task 5 Task 6

 

Scenario

A scientist is running a simulation on rainfall data.

He has written a computer program which:

Here is the code.

Task1

Start a new project in your ide and copy in the Main.java code.

There are 1 or 2 errors. Can you find them and fix them?

Observation questions

  1. How many global variables are there.
  2. What length is the array initialised to?
  3. What task does the function populateArray() perform?
  4. What data does the function getMaxVal return to the calling program?
  5. What does num--; mean?
  6. How do you feel about the algorithm determining the maximum value in the array?

Task 2

Another function, getMinValue(), needs to be written. Code this function which returns the smallest value in the array.

Test that your function works as expected.

Task 3

Another function, getTotalValue(), needs to be written. Code this function which returns the sum of all values in the array.

Test that your function works as expected.

Task 4

Another function, getAverageValue(), needs to be written. Code this function which returns the average of all values in the array.

getAverageValue should call getTotalValue in order to determine and return the average value.

Test that your function works as expected.

Task 5

Another function, evaluateData(), needs to be written.

This function takes 2 values as parameters. The first represents a minimum rainfall value.

The second represents the maximum rainfall value.

The function outputs Irregular data set if the difference between the two values is greater than 50; Otherwise it outputs Regular data set

Test that your function works as expected.

Task 6

Design a function that will display the min, max, average and total values in the data array - do not use any additional global variables.

Write a program to test all of the functions available.