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

Write a RainFall class that has the following field: • an array of doubles that

ID: 3682374 • Letter: W

Question

Write a RainFall class that has the following field: • an array of doubles that stores the rainfall for each of the 12 months of the year (where the first index corresponds with January, the second with February, etc.) The class should also have the following methods : • a method that returns the total rainfall for the entire year • a method that returns the average monthly rainfall for the year • a method that returns the month with the most rain as a string • a method that returns the month with the least rain as a string Demonstrate the class in a program that takes 12 doubles from the user (take the doubles in the order of the months of the year, the first corresponding to the rainfall in January, etc.). Do input validation: if the user inputs a negative number, ignore it and continue asking them for input until you have 12 nonnegative doubles . Once the user has given you all 12 doubles , create an instance of the RainFall class and call its methods , printing out the total rainfall, the average monthly rainfall, the month with the most rain, and the month with the least rain, each on a separate line

Explanation / Answer


package rainfall;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class RainFall {
double monthRF[]=new double[12];
double value,total=0.0;
  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public RainFall() throws IOException
{
System.out.print("Enter the 12 non-negative double values ");
do{
for(int i=0;i<monthRF.length;i++)
{
value=Double.parseDouble(br.readLine());
if(value > 0)
monthRF[i]=value;
else
{
System.out.println("Re Enter the value");
break;
}
}
}while(value < 0);
}
public void totalRainFall()
{
//double total=0.0;
for(int i=0;i<monthRF.length;i++)
{
total=total+monthRF[i];
}
System.out.println("Total Rain fall is :"+total);
}
public void averageRainFall()
{
System.out.println("Average Rain fall is :"+total/monthRF.length);
}
public void leastMonth()
{
double least=monthRF[0];
for(int i=0;i<monthRF.length;i++)
{
if(least >= monthRF[i])
least=monthRF[i];
}
System.out.println("Least Rain Fall is :"+least);
}
public void largeMonth()
{
double max=monthRF[0];
for(int i=0;i<monthRF.length;i++)
{
if(max <= monthRF[i])
max=monthRF[i];
  
}
System.out.println("max Rain Fall is :"+max);
}
  
public static void main(String[] args) throws IOException {
  
RainFall rf=new RainFall();
rf.totalRainFall();
rf.averageRainFall();
rf.largeMonth();
rf.leastMonth();
}
  
}

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