Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Students: This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns about this content to your instructor. If you
Students: This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns about this content to your instructor. If you have any technical issues with the zyLab submission system, use the "Trouble with lab?" button at the bottom of the lab. Objectives To practice nested loops To earn extra credit Assignment Extra Credit B Write a Java program that uses nested loops to collect data and calculate the average rainfall over a period of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period. Requirements: Do not accept a number less than 1 for the number of years. Print "Must enter a number 1 or greater" and stop the program. Do not accept negative numbers for the monthly rainfall. Print "Rainfall must be 0 or greater" and stop program. The prompt for years should read: "Enter the number of years:" The prompt for months should read: "Enter the inches of rainfall for month n:" Samples of program execution (as if run on UNIX): > java ExtraCreditB Enter the number of years: 2 Enter the inches of rainfall for month 1: 2.4 Enter the inches of rainfall for month 2: 3.1 Enter the inches of rainfall for month 3: 4.7 Enter the inches of rainfall for month 4: 1.3 ... Total number of months: 24 Total inches of rainfall: Average rainfall per month
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started