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

Rainfall Statistics Create an application that lets the user enter the rainfall

ID: 3905764 • Letter: R

Question

Rainfall Statistics Create an application that lets the user enter the rainfall for each of 12 months into an array. The application should calculate and display the following statistics: total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts of rainfall. Figure shows an example of the application's form after each month's rainfall amount has been entered and the statistics have been displayed. Check for nonnumeric input. Figure Rainfall Statistics form Rainfall Statistics Monthly Rainfall Input Rainfall for January3 Rainfall for February 8 Rainfall for March6 Rainfall for April-4 Rainfall for May-7 Rainfall for June 5 Rainfall for July -6 Rainfall for August 3 Rainfall for September-8 Rainfall for October 2 Rainfall for November 4 Rainfall for December 3 The total annual rainfall was 59 The average monthly rainfall was 4.92 The minimum monthly rainfall was 2 (October) The maximum monthly rainfall was 8(February nput Monthly Rainfall Display Stats Clear Ext

Explanation / Answer

Let's Start, to get the Rainfall data and display the required output we can use the following code.

The code for the following is given below:

import java.util.Scanner;

class Rainfall

{

public static void main(String[] args)

{

int c=0;

String Month1=" ",Month2= " "; //Initialize the Variables

String [] a=new String [12]; //Declare the Array for Months

a[0]="January";

a[1]="February";

a[2]="March";

a[3]="April";

a[4]="May";

a[5]="June";

a[6]="July";

a[7]="August";

a[8]="September";

a[9]="October";

a[10]="November";

a[11]="December";

int [] num = new int[12]; // Declare the array to store Rainfall Values

Scanner sc=new Scanner(System.in); // Taking input using Scanner

System.out.println("Enter Rainfall Data");

System.out.println(" ");

System.out.println("Enter Rainfall for Each Month");

System.out.println(" ");

System.out.println("Rainfall in January:");

num [0]=sc.nextInt();

System.out.println("Rainfall in February:");

num [1]=sc.nextInt();

System.out.println("Rainfall in March:");

num [2]=sc.nextInt();

System.out.println("Rainfall in April:");

num [3]=sc.nextInt();

System.out.println("Rainfall in May:");

num [4]=sc.nextInt();

System.out.println("Rainfall in June:");

num [5]=sc.nextInt();

System.out.println("Rainfall in July:");

num [6]=sc.nextInt();

System.out.println("Rainfall in August:");

num [7]=sc.nextInt();

System.out.println("Rainfall in September:");

num [8]=sc.nextInt();

System.out.println("Rainfall in October:");

num [9]=sc.nextInt();

System.out.println("Rainfall in November:");

num [10]=sc.nextInt();

System.out.println("Rainfall in December:");

num [11]=sc.nextInt();

System.out.println(" ");

for(int i=0;i<12;i++) //Total Rainfall

{

c = c + num[i];

}

int maxValue = num[0]; // Maximum Rainfall

for(int i=1;i < num.length;i++)

{

if(num[i] > maxValue)

{

maxValue = num[i];

Month1 = a[i];

}

}

int minValue = num[0]; // Minimum Rainfall

for(int i=1;i<num.length;i++)

{

if(num[i] < minValue)

{

minValue = num[i];

Month2 = a[i];

}

}

System.out.println("Total Annual Rainfall: "+c);

System.out.println(" ");

System.out.println("Average Monthly Rainfall: "+c/12);

System.out.println(" ");

System.out.println("Maximum Monthly Rainfall: "+maxValue+"("+Month1+")");

System.out.println(" ");

System.out.println("Minimum Monthly Rainfall: "+minValue+"("+Month2+")");

}

}

Save the file as Rainfall.java, and to compile use javac Rainfall.java, and to execute use java Rainfall.

So, the given code will generate the required output and the GUI can be designed accordingly, the code uses basic for and if loops to calculate the Average and total amount of Rainfall.

Comments have been added at necessary places, please refer to the comments for better explanation.

This is all for the question.

Thank You for using Chegg.!