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

In java please, without the use of switch statements For this project, you will

ID: 3737849 • Letter: I

Question

In java please,

without the use of switch statements

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 f days until the user enters an appropriate number. The program should then valid number o prompt the user for the observed amount of rain that fell on each of the specified number of days Once rainfall data has been entered, the program should then present the user with a menu of 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, days a flood warning was issued due to six or more inches of rain in a single day more inches of rain over two consecutive days, and (6) quit. The menu should cont 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. (5) the number of or eight or inue to be 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 lastname> where

Explanation / Answer

import java.util.*;
public class RainfallAnalysis {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter number of days for which observation is present (between 1 and 10): ");
n=sc.nextInt();
while(n<1 || n>10){
System.out.println("Invalid value. Please enter a number between 1 and 10(both inclusive):");
n=sc.nextInt();
}
int obs[]=new int[n];
for(int i=0;i<n;i++){
System.out.println("Enter observation for day "+(i+1)+" :");
obs[i]=sc.nextInt();
}
int sum=0;
double avg;
int greatestRainfallDay=-1,greatestRainfall=-1,leastRainfallDay=-1,leastRainfall=obs[0];
int floodWarning=0;
for(int i=0;i<n;i++){
sum+=obs[i];
if(obs[i]>greatestRainfall){
greatestRainfall=obs[i];
greatestRainfallDay=i+1;
}
if(obs[i]<leastRainfall){
leastRainfall=obs[i];
leastRainfallDay=i+1;
}
if(obs[i]>=6 || (i>0 && (obs[i]+obs[i-1])>=8)){
floodWarning++;
}
}
avg=sum/n;
int ch=-1;
while(ch !=6){
System.out.println("Enter choice:");
System.out.println("1.Total Rainfall 2.Average rainfall 3.the day and tha amount of greatest rainfall "+
"4.The day and the amount of least rainfall 5.The number of days flood warning was issued "+
"6.Quit");
ch=sc.nextInt();
if(ch==1){
System.out.println("Total Rainfall:" + sum);
}
else if(ch==2){
System.out.println("Average Rainfall: "+avg);
}
else if(ch==3){
System.out.println("Greatest rainfall day: "+greatestRainfallDay);
System.out.println("Amount: "+greatestRainfall);
}
else if(ch==4){
System.out.println("Least rainfall day: "+leastRainfallDay);
System.out.println("Amount: "+leastRainfall);
}
else if(ch==5){
System.out.println("Number of days with flood warning: "+floodWarning);
}
else if(ch==6){
System.out.println("Quitting");
}
else{
System.out.println("Invalid choice.Try Again!");
}
}
}
}

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