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

Write a program that calculates the average rainfall for three months. The progr

ID: 643659 • Letter: W

Question

Write a program that calculates the average rainfall for three months.

The program should ask the user to enter the name of each month, such as June or July, and the amount of rain (in inches) that fell each month.

The program should display a message similar to the following:

       The average rainfall for June, July, and August is 6.72 inches.

Prompts And Output Labels: Each month read should be prompted for by the string "Enter month: "

and each rainfall amount should be prompted for by a string of the form "Enter rainfall for MONTH: " where MONTH is the name of the month that was just entered.

The output should be of the form: "The average rainfall for MONTH1, MONTH2, and MONTH3 is: AVERAGE"

where MONTH1, MONTH2, and MONTH3 are the month names that were entered by the user and

where AVERAGE is the calculated average rainfall shown with exactly two digits past the decimal point.

Explanation / Answer

mport java.io.*;
class rainavg
{
public static void main(String args[])
{
try
{
String month[]= new String[12];
String rainfall[]= new String[12];

int avg=0,rainf=0;
for(int i=0;i<12;i++)
{
month[i]="jjjjj";
rainfall[i]="jjjjjj";
System.out.println("enter month name");
BufferedReader br = new BufferedReader(new InputStreamReader(null));
month[i]=br.readLine();
System.out.println("enter rain fall");
rainfall[i]=br.readLine();
rainf=Integer.parseInt(rainfall[i]);
avg=avg+rainf;
}
for(int i=0;i<12;i++)
{

System.out.println("month "+ month[i]);
System.out.println(" rain fall average"+avg);
}


}catch(Exception e){}
}
}

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