Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rainfall Statistics.java Write a program that stores the name of each month in an array of Strings, and the rainfall for each month of the

Rainfall Statistics.java

Write a program that stores the name of each month in an array of Strings, and the rainfall for each month of the year into an array of doubles. The program should determine the total rainfall for the year, the average monthly rainfall, and the months with the most and least amount of rain.

You will need:

1.) Two one-dimensional arrays one to store the names of each month and another to store the rainfall for each month. (What would be the size of these arrays?)

-Use an initialization list to store the names of each month into the String array.

2.) A for loop to receive the values of rainfall.

-You should refer to your string array to get the names for the appropriate month.

-The rainfall values should be stored in the doubles array.

-Input validation: Make sure the user does not enter a negative value for rainfall. (Use a while loop for this part)

3.) A for loop to compute the running sum

4.) A variable to store the average

5.) A for loop (with a nested if statement) to determine the largest amount of rainfall in the doubles array

-You need to refer to the String array to indicate the month with the largest rainfall

6.) A for loop (with a nested if statement) to determine the smallest amount of rainfall

-You need to refer to the String array to indicate the month with the smallest rainfall

7.) Comments as needed.

Output:

Enter the rainfall (in inches) for January: -2

Values must be 0 or more.

Re-enter the rainfall for January: 12

Enter the rainfall (in inches) for February: 23

Enter the rainfall (in inches) for March: 17

Enter the rainfall (in inches) for April: 19

Enter the rainfall (in inches) for May: 10

Enter the rainfall (in inches) for June: 6

Enter the rainfall (in inches) for July: 7.5

Enter the rainfall (in inches) for August: 8.6

Enter the rainfall (in inches) for September: 9

Enter the rainfall (in inches) for October: 11.2

Enter the rainfall (in inches) for November: 8.9

Enter the rainfall (in inches) for December: 12

The total rainfall for the year is 144.2 inches.

The average rainfall for the year is 12.02 inches.

The largest amount of rainfall for the year is 23 inches in February.

The smallest amount of rainfall for the year is 6 inches in June.

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