Java Project Name IC18Rainfall In January 2015 Governor Brow
Java Project Name: IC18_Rainfall
In January 2015, Governor Brown declared a drought State of Emergency in California. Since then, the state has been desperately searching for ways to cope with this unprecedented drought.
One of the mechanisms necessary for drought research is accurate data and statistical reporting. Your job, as a concerned student is to write software that can accurately record rainfall statistics for each month.
Rainfall Statistics Write a program that lets the user enter the total rainfall for each of 12 months (stored in an array of strings e.g. monthNames) into an array of doubles (e.g. monthlyRainfall). The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Input Validation: Do not accept negative numbers for monthly rainfall figures. The goal is to keep an accurate record of rainfall data for scientists to use in prediction models.
An example transaction with the user (e.g. meteorologist) looks like:
Enter rainfall amount (in inches) for January >> 1.5
Enter rainfall amount (in inches) for February >> 3.0
Enter rainfall amount (in inches) for March >> 4.7
Enter rainfall amount (in inches) for April >> 0.91
Enter rainfall amount (in inches) for May >> 0.26
Enter rainfall amount (in inches) for June >> 0.07
Enter rainfall amount (in inches) for July >> 0.64
Enter rainfall amount (in inches) for August >> 0.0
Enter rainfall amount (in inches) for September >> 4.89
Enter rainfall amount (in inches) for October >> 0.0
Enter rainfall amount (in inches) for November >> 4.7
Enter rainfall amount (in inches) for December >> 7.93
Total Rainfall for the Year (in inches): 28.6
Average Rainfall for the Year (in inches): 2.38
Minimum Monthly Rainfall (in inches): 0.0
Maximum Monthly Rainfall (in inches): 7.93
i just cant figure out the max and minimum
Solution
RainfallTest.java
import java.util.Arrays;
import java.util.Scanner;
public class RainfallTest {
static String month[] = {\"January\", \"Fabruary\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\",\"October\",\"November\",\"December\"};
public static void main(String[] args) {
double monthlyRainfall[] = new double[12];
Scanner scan = new Scanner(System.in);
for(int i=0; i<monthlyRainfall.length; i++){
System.out.print(\"Enter rainfall amount (in inches) for \"+month[i]+\":\");
monthlyRainfall[i] = scan.nextDouble();
}
System.out.println(\"Entered rainfall details \"+Arrays.toString(monthlyRainfall));
displayTotalRainFall(monthlyRainfall);
displayAverageRainFall(monthlyRainfall);
displayMaximumRainFall(monthlyRainfall);
displayMinimumRainFall(monthlyRainfall);
}
public static void displayEachMonthRainFall(double months[]){
for(int i=0; i<months.length; i++){
System.out.println(month[i]+\": \"+months[i]);
}
}
public static void displayTotalRainFall(double months[]){
double total = 0;
for(int i=0; i<months.length; i++){
total = total + months[i];
}
System.out.printf(\"Total Rainfall for the Year (in inches): %.2f\ \",total);
}
public static void displayAverageRainFall(double months[]){
double total = 0;
double avg = 0;
for(int i=0; i<months.length; i++){
total = total + months[i];
}
avg = total/(double)months.length;
System.out.printf(\"Average Rainfall for the Year (in inches): %.2f\ \",avg);
}
public static void displayMaximumRainFall(double months[]){
double max = 0;
for(int i=0; i<months.length; i++){
if(max < months[i]){
max = months[i];
}
}
System.out.println(\"Maximum Monthly Rainfall (in inches): \"+max);
}
public static void displayMinimumRainFall(double months[]){
double min = months[0];
for(int i=0; i<months.length; i++){
if(min > months[i]){
min = months[i];
}
}
System.out.println(\"Minimum Monthly Rainfall (in inches): \"+min);
}
}
Output:
Enter rainfall amount (in inches) for January:1.5
Enter rainfall amount (in inches) for Fabruary:3.0
Enter rainfall amount (in inches) for March:4.7
Enter rainfall amount (in inches) for April:0.91
Enter rainfall amount (in inches) for May:0.26
Enter rainfall amount (in inches) for June:0.07
Enter rainfall amount (in inches) for July:0.64
Enter rainfall amount (in inches) for August:0.0
Enter rainfall amount (in inches) for September:4.89
Enter rainfall amount (in inches) for October:0.0
Enter rainfall amount (in inches) for November:4.7
Enter rainfall amount (in inches) for December:7.93
Entered rainfall details [1.5, 3.0, 4.7, 0.91, 0.26, 0.07, 0.64, 0.0, 4.89, 0.0, 4.7, 7.93]
Total Rainfall for the Year (in inches): 28.60
Average Rainfall for the Year (in inches): 2.38
Maximum Monthly Rainfall (in inches): 7.93
Minimum Monthly Rainfall (in inches): 0.0


