Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In java please, Rainfall Analysis For this project, you will write a program tha

ID: 3737847 • Letter: I

Question

In java please,

Rainfall Analysis For this project, you will write a program that analyzes the amount of rain observed over the course of several days. Your program should prompt the user to specify the number of days for which observation data will be entered (between 1 and 10 inclusive). If the user enters an invalid number of days, the program should display an error message and keep asking the user for a valid number of days until the user enters an appropriate number. The program should then prompt the user for the observed amount of rain that fell on each of the specified number of days menu of Once rainfall data has been entered, the program should then present the user with a options that will display information about the observation period. The menu will provide the following options to display (1) the total rainfall, (2) the average rainfall, (3) the day and the amount of the greatest rainfall, (4) the day and the amount of the least rainfall, (5) the number of days a flood warning was issued due to six or more inches of rain in a single day, or eight or more inches of rain over two consecutive days, and (6) quit. The menu should continue to be displayed until the user selects the quit option. If the user enters an invalid option, the program should display an "Invalid response, please try again!" message and redisplay the menu. Note: If two days have the same greatest (or least) rainfall, report the first/earliest day that had that value You should develop your project using Eclipse. Create a new project in Eclipse called RainfallAnalysis

Explanation / Answer

import java.util.ArrayList;

import java.util.Scanner;

public class RainfallAnalysis {

public static void main(String args[]) {

int days;

ArrayList<Double> rainfall = new ArrayList<Double>();

Scanner sc = new Scanner(System.in);

int choice;

System.out.println("Enter number of days (1 to 10): ");

days = sc.nextInt();

while(days < 0 || days > 10) {

System.out.println("You have entered wrong value.Enter value again!!");

System.out.println("Enter number of days (1 to 10): ");

days = sc.nextInt();

}

System.out.println("Enter rainfall in inches for "+days+" days");

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

rainfall.add(sc.nextDouble());

}

do {

System.out.println("Select choice: 1/2/3/4/5/6");

System.out.println("1. Total Rainfall ");

System.out.println("2. Average rainfall");

System.out.println("3. Day and amount of greatest rainfall");

System.out.println("4. Day and amount of least rainfall");

System.out.println("5. Number of days flood warning was issued");

System.out.println("6. Quit");

choice = sc.nextInt();

switch(choice) {

case 1 :

double totalRainfall = totalRainfall(rainfall);

System.out.println("Total rainfall is "+ totalRainfall +" for last "+days+" days.");

break;

case 2:

double avg = averageRainfall(rainfall);

System.out.println("Average rainfall is "+ avg +" for last "+days+" days.");

break;

case 3:

greatestRainfall(rainfall);

break;

case 4:

leastRainfall(rainfall);

break;

case 5:

daysOfFlood(rainfall);

break;

case 6:

System.out.println("Exiting from the system!!");

System.exit(0);

break;

default:

System.out.println("Invalid response. Please try again!!");

break;

}

}

while(true);

}

public static double totalRainfall(ArrayList<Double> rainfall) {

double sum = 0;

for(int i=0; i<rainfall.size(); i++) {

sum = sum + rainfall.get(i);

}

return sum;

}

public static double averageRainfall(ArrayList<Double> rainfall) {

double avg;

avg = totalRainfall(rainfall);

return avg/rainfall.size();

}

public static void greatestRainfall(ArrayList<Double> rainfall) {

double max = rainfall.get(0);

int day = 0;

if(rainfall != null) {

for(int i=1;i<rainfall.size();i++) {

if(max < rainfall.get(i)) {

max = rainfall.get(i);

day = i;

}

}

System.out.println("Max rainfall occured on "+ (day+1)+" with "+ max+" in.");

}

System.out.println("No rainfall occured");

}

public static void leastRainfall(ArrayList<Double> rainfall) {

double min = rainfall.get(0);

int day = 0;

if(rainfall != null) {

for(int i=1;i<rainfall.size();i++) {

if(min > rainfall.get(i)) {

min = rainfall.get(i);

day = i;

}

}

System.out.println("Min rainfall occured on "+ (day+1)+" with "+ min +" in.");

}

System.out.println("No rainfall occured");

}

public static void daysOfFlood(ArrayList<Double> rainfall) {

int day = 0;

boolean rain = false;

boolean rain6In = false;

if(rainfall != null) {

for(int i= 0; i<rainfall.size(); i++) {

if(rainfall.get(i) > 7.9 ) {

if((i != 0 && i != rainfall.size()-1 ) && ( rainfall.get(i-1) > 7.9 || rainfall.get(i+1)> 7.9)) {

rain = true;

day = i;

break;

}

else if(rainfall.get(i) > 5.99) {

rain6In = true;

day = i+1;

break;

}

}

}

System.out.println("Flood occured on "+ day+" day");

}

System.out.println("No rain occured");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote