Question: Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should have methods that
Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should have methods that return the following: the total rainfall for the year the average monthly rainfall the month with the most rain the month with the least rain Demonstrate the class in a complete program. Input Validation: Do not accept negative numbers for monthly rainfall figures
Notes: use the following data as rainfalls for the months from Jan. to Dec.
1.6 2.1 1.7 3.5 2.6 3.7 3.9 2.6 2.9 4.3 2.4 3.7
and the RainfallDemo class should contains the code like the following:
public static void main(String[] args) { // Create an array of rainfall figures. double[] thisYear = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3, 2.4, 3.7 }; // Create a RainFall object initialized with the figures // stored in the thisYear array. Rainfall r = new Rainfall(thisYear);
.
.
.
}
and the outputs could look like:
The total rainfall for this year is .... The average rainfall for this year is .... The month with the highest amount of rain is .... The month with the lowest amount of rain is 1....
Press any key to continue . . .
Programming language: Java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
