Write Rainfall Class Stores Total Rainfall 12 Months Array Doubles Program Methods Return Q43900122
Write a RainFall class that stores the total rainfall for eachof 12 months into an array of
doubles. The program should have methods that return thefollowing:
• 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 monthlyrainfall figures
Notes: use the following data as rainfallsfor the months from Jan. to Dec.
1.6 2.1 1.7 3.52.6 3.7 3.9 2.6 2.9 4.3 2.4 3.7
and the RainfallDemo class should contains the code like thefollowing:
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 objectinitialized with the figures
// stored in the thisYeararray.
Rainfall r = newRainfall(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
Expert Answer
Answer to Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should…
OR