This is the class that will contain the program's main method and use an array of Month objects. In the main method: • Create an empty array of Month objects; The length must be 12. Prompt the user to enter a rainfall amount for each month. o If the user enters an amount less than 0, print an error message and prompt for a new value until the user enters a non-negative number. o Once you have validated the entered amount, create an instance of a new Month object and use the month's name and the entered amount as the constructor's two arguments o Add the newly created Month object to the array of Month objects. After storing all twleve Month objects into the array, your program will use the data contained in the array's objects to determine and print: 1. The total rainfall for the year 2. The average monthly rainfall for the year 3. The month with the most rain 4. The month with the least rain

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter5: Making Decisions
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question
Create a Java program that prompts the user to enter rainfall amounts (in inches) for 12 months of one
year. Your program must utilize an array of Month objects, which each hold the month's name and the
amount of rain in that month.
Month Class (Month.java)
1. The following private fields:
monthName (String) – Name of the month.
amount (int) – Amount of rainfall, in inches.
2. A public constructor that accepts two arguments.
The first parameter is a String and is used to set the monthName field
The second parameter is an int and is used to set the amount field
3. Two public accessor methods for retrieving the monthName and amount fields.
RainFallAmounts Class (RainFallAmounts.java)
This is the class that will contain the program's main method and use an array of Month objects.
In the main method:
• Create an empty array of Month objects; The length must be 12.
• Prompt the user to enter a rainfall amount for each month.
o If the user enters an amount less than 0, print an error message and prompt for a new
value until the user enters a non-negative number.
o Once you have validated the entered amount, create an instance of a new Month object
and use the month's name and the entered amount as the constructor's two arguments.
o Add the newly created Month object to the array of Month objects.
• After storing all twleve Month objects into the array, your program will use the data contained
in the array's objects to determine and print:
1. The total rainfall for the year
2. The average monthly rainfall for the year
3. The month with the most rain
4. The month with the least rain
When determining the months with the most and least rain, you do not need to account for ties.
Use comments to adequately document your source code.
See next page for sample input/output
Transcribed Image Text:Create a Java program that prompts the user to enter rainfall amounts (in inches) for 12 months of one year. Your program must utilize an array of Month objects, which each hold the month's name and the amount of rain in that month. Month Class (Month.java) 1. The following private fields: monthName (String) – Name of the month. amount (int) – Amount of rainfall, in inches. 2. A public constructor that accepts two arguments. The first parameter is a String and is used to set the monthName field The second parameter is an int and is used to set the amount field 3. Two public accessor methods for retrieving the monthName and amount fields. RainFallAmounts Class (RainFallAmounts.java) This is the class that will contain the program's main method and use an array of Month objects. In the main method: • Create an empty array of Month objects; The length must be 12. • Prompt the user to enter a rainfall amount for each month. o If the user enters an amount less than 0, print an error message and prompt for a new value until the user enters a non-negative number. o Once you have validated the entered amount, create an instance of a new Month object and use the month's name and the entered amount as the constructor's two arguments. o Add the newly created Month object to the array of Month objects. • After storing all twleve Month objects into the array, your program will use the data contained in the array's objects to determine and print: 1. The total rainfall for the year 2. The average monthly rainfall for the year 3. The month with the most rain 4. The month with the least rain When determining the months with the most and least rain, you do not need to account for ties. Use comments to adequately document your source code. See next page for sample input/output
Sample Input/Output
Please enter the rainfall amount for January: 5
Please enter the rainfall amount for February: 4
Please enter the rainfall amount for March: 3
Please enter the rainfall amount for April: 2
Please enter the rainfall amount for May: 1
Please enter the rainfall amount for June: 0
Please enter the rainfall amount for July: -6
Invalid amount. Try again.
Please enter the rainfall amount for July: -2
Invalid amount. Try again.
Please enter the rainfall amount for July: 2
Please enter the rainfall amount for August: 3
Please enter the rainfall amount for September: 4
Please enter the rainfall amount for October: 5
Please enter the rainfall amount for November: 6
Please enter the rainfall amount for December: 7
The total rainfall is 42 inches.
The average monthly rainfall is 3.50 inches.
The month with the
ost rain was December.
The month with the least rain was June.
Transcribed Image Text:Sample Input/Output Please enter the rainfall amount for January: 5 Please enter the rainfall amount for February: 4 Please enter the rainfall amount for March: 3 Please enter the rainfall amount for April: 2 Please enter the rainfall amount for May: 1 Please enter the rainfall amount for June: 0 Please enter the rainfall amount for July: -6 Invalid amount. Try again. Please enter the rainfall amount for July: -2 Invalid amount. Try again. Please enter the rainfall amount for July: 2 Please enter the rainfall amount for August: 3 Please enter the rainfall amount for September: 4 Please enter the rainfall amount for October: 5 Please enter the rainfall amount for November: 6 Please enter the rainfall amount for December: 7 The total rainfall is 42 inches. The average monthly rainfall is 3.50 inches. The month with the ost rain was December. The month with the least rain was June.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT