Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Create bonds with present or future customers.

Answered: 1 week ago