Question: JAVA- Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles, and contains methods to return

JAVA- Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles, and contains methods to return the total rainfall for the year, the average monthly rainfall, the month with the most and the least rain, the rainfall in any month. And then write an application to demonstrate the service class.

The data stored on an array may be inputted by user or initialized in the client class using the initializer list, or read from an external file. For file input, please download the file, rainfallDat.txt in the drop box with the lab description. The file contains the amount of rainfall in 12 month of a year. The first line in the file contains the amount for January, the second line contains the amount for February, and so forth.

Please follow the following steps to complete the assignment:

Design the program in a UML class diagram. The diagram should contain both service and application class. The service class should contain:

An array as a private data member in the data type, double

A constructor with an array object as a parameter, which is used instantiate the data member

Methods (each returns a value):

Return the total rainfall for the year

Return the average monthly rainfall

Return the month which has the most rain (returns a month number, NOT amount of rain)

Return the month which has the least rain (returns a month number, NOT amount of rain)

Return the rainfall in any month (need an int parameter)

Return the month name (need an int parameter)

A void method which searches for months whose amount of rainfall are higher than average, and display number of months, and month name and amount of rainfall associate with the month.

Implement the design in Java program.

Your program structure should reflect the class diagram structure.

If you change data member/field name or data type, or add/remove a variable in Java code, make change in the diagram.

If you change method header (return type, name, and parameter) in Java code, or add/remove a method in Java code, make change in the diagram.

In the service class, RainFall,

Please notice that all methods are operated on the array. Since the array is the data member in the class, no method needs (except the constructor) an array as a parameter because all methods can access the array directly. (The class structure and some methods are similar to code on P436 (Grader.java) and P431 (SalesData.java).

Hints for the void method to find months whose amount of rainfall are higher than average:

Compare the amount of each month with the average amount. If it is higher than the average, display.

Remember you can call other methods inside a method.

In the application class,

Create two arrays: one is used to test an array which stores data from user input or uses the initializer list to initialize the array elements directly. The other is used to test an array which stores data read from the external file, rainfallData.txt.

Create two objects of the RainFall class, and pass each of the array objects as the argument to the constructor.

Use the object to invoke methods in the service class.

Format output for values of rainfall with one or two decimal points.

Please use the following data to test your program:

Assume the following values are stored in the first array:

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 2nd array stores data read from the file.

Here is the running result:

JAVA- Write a RainFall class that stores the total rainfall for each

Test data from the intializer list... The total rainfall for this year is 35.0 The average rainfall for this year is 2.9 The month with the highest amount of rain is October with 4.3 inches. The month with the lowest amount of rain is January with 1.6 inches There are 5 months whose rainfall are higher than average: April June July October Decemeber 3.7 3.7 Test data read from the file... The total rainfall for this year is 34.1 The average rainfall for this year is 2.8 The month with the highest amount of rain is August with 4 inches The month with the lowest amount of rain is February with 1.5 inches. There are 5 months whose rainfall are higher than average: April July August September October

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!