Question

5. Create a java application that uses nested loops to collect data and calculate the average rainfall over a peniod of years First the program should ask for the number 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, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period Input validation: Do not accept a number less than 1 for the number ofyears. Do not accept negative numbers for the monthly rainfall

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package HomeworkLibSolution1;

import java.util.Scanner;

public class RainFall {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.println("Enetr number of years: ");

int N=sc.nextInt();

while(N<1) {

System.out.println("Enetr number of years: ");

N=sc.nextInt();

}

double totalRainfall=0;

for(int i=0; i<N; i++) {

double monthRainfall=0;

for(int j=0; j<12; j++) {

System.out.println("Enter raifall for month: "+(j+1)+" of year: "+(i+1));

monthRainfall+=sc.nextDouble();

while(monthRainfall<0) {

System.out.println("Enter raifall for month: "+(j+1)+" of year: "+(i+1));

monthRainfall+=sc.nextDouble();

}

}

totalRainfall+=monthRainfall;

}

System.out.println("Average Rainfall is: "+(totalRainfall/N));

}

}

HomeworkLib - Chegglava/src/HomeworkLibSolution1/RainFalljava Eclipse Eile Edit Source Refactor Navigate Search Projec Bun Window Help Quick Accesse s Package ExplorerERain Fall java3 System.out.println(Enetr number of years: ); int N-sc.nextInt); while(Ik1) t 18 HousePointersjava > Dİ Insurance..ava System.out.println(Enetr number of years: ); 12 13 14 15 N-sc.nextInt); Life.java double totalRainfall-e; for(int i:0; i<N; i++) { 17 18 19 20 21 double monthRainfall-8; for(int j-0; j<12; j+t) Main.javo Main.java mainDriver java System.out.println(Enter raifall for month: +j+1)+ of year (+1)) monthRainfall+-sc.nextDouble ModLoan.javo ProblemsJavadoc Declaration ConsoleDebug termineted RainFall ava Application] C:Program FilesJevalre1.8.0 651binljavaw.exe (Oct 28, 2018, 12:09:51 A Enter raifall for month: 4 of year: 1 Enter raifall for nonth: 5 of ycar: 1 Enter raifall for month: 6 of year: 1 Enter raifall for nonth: 7 of ycar: 1 Enter raifall for month: 8 of year: Enter raifall for nonth: 9 of ycar: 1 NotEnoughBalance,java Palindromjovo Player.java PlayerDatabase javia Enter raifall for month: 10 of year:1 123 Enter raifall for month: 11 of year: 1 234 Enter raifall for month: 12 of year:1 456 Average Rainfall is: 1308.0 Program.java Purchase,java PurchaseDemo java Question java RainFalljva U: 0.00 KiB/s D: 12:10 AM 10/28/2018 0.00 KiB/s

Add a comment
Know the answer?
Add Answer to:
5. Create a java application that uses nested loops to collect data and calculate the average...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Average Rainfall Design a program that uses nested loops to collect data and calculate the average...

    Average Rainfall Design a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve 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...

  • Write a program that uses nested loops to collect data and calculate the average rainfall over...

    Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should prompt the user for the number of years. Be sure to ask for each months average rainfall for each year. The outer loop will iterate once for each year while the inner loop will iterate 12 times(one time per month) prompting for the months average rainfall on each iteration. Display the number of months, the total inches...

  • Design a program that uses nested loops to collect data and calculate the average rainfall over...

    Design a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterte twelve times, onece for each month. Each itertion of the inner loop will ask the user for the inches of rainfall for tht month. After all iterations, the program should display the number of months, the...

  • Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops...

    Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve 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,...

  • Small Basic Programming Question: Average score Write a program that uses loops to collect data and...

    Small Basic Programming Question: Average score Write a program that uses loops to collect data and calculate the average score over a number of tests for a number of students. The program should : 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the...

  • Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and...

    Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and calculate the average score over a number of tests for a number of students. The program should: 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the scores...

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED home / study...

    PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED home / study / engineering / computer science / questions and answers / python programming - code the program based on ... Your question has been answered! Rate it below. Let us know if you got a helpful answer. Question: PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE... Bookmark PYTHON PROGRAMMING - CODE THE PROGRAM BASED ON THE INSTRUCTIONS AND ALGORITHM PROVIDED Rainfall Algorithm Declare and...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Poly-Poly + a[i] * power 6. (15%) Consider the nested loops shown below, where N is...

    Poly-Poly + a[i] * power 6. (15%) Consider the nested loops shown below, where N is assumed to be a power of 2. i.e., N-2 for some positive integer k. i=N; while (i>-1){ while (j =N){ j-2 *j; i=i/2. a) Determine the number of outer iterations (associated with the outer while loop) to be executed? Show your work. b) For each outer iteration (for each value of i), determine the number of iterations of the inner while loop to be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT