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
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
Chapter5: Making Decisions
Section: Chapter Questions
Problem 7PE
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1b3d56f9-5448-464a-93a6-79d37f3c5924%2F2c80278b-d33e-48fa-be69-fb5c8471aba5%2F5vnsbhi_processed.jpeg&w=3840&q=75)
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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1b3d56f9-5448-464a-93a6-79d37f3c5924%2F2c80278b-d33e-48fa-be69-fb5c8471aba5%2Fsg0sxnr_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT