Write a program that stores the total rainfall for each of 12 months into an array of doubles. The program should have methods that return the following:
the total rainfall for the year.
the average monthly rainfall.
the month with the most rain.
the month with the least rain.
Here's my code so far.
import java.util.Scanner; //Needed for Scanner class. public class Rainfall { public static void main(String[] args) { double[] months = new double[12]; double[] rainfall = new double[12]; Scanner scn = new Scanner(System.in); for (int index = 0; index < rainfall.length; index++) { System.out.print("rainfall for month #" + (index + 1) + ": "); rainfall[index] = scn.nextDouble(); } for (int index = 0; index < rainfall.length; index++) { TotalRainfall(rainfall[index]); Average(rainfall[index]); Most(rainfall[index]); Least(rainfall[index]); } } public static void TotalRain(double rainfall) { double total = 0; for (int index = 0; index < rainfall.length; index++) { total += rainfall[index]; } System.out.print("Total rainfall is: " + total); } public static double Avrge(double rainfall) { double total = 0; double average; for (int index = 0; index < rainfall.length; index++) { total += rainfall; } average = total / rainfall.length; System.out.println("average monthly rainfall is: " + average); } public static double Most(double rainfall) { int highest = rainfall[0]; int month; for (int index = 1; index < rainfall.length; index++) { if (rainfall[index] > highest) { highest = rainfall[index]; month = index; } } System.out.println("Highest rain happened during month #" + month); } public static double Least(double rainfall) { int lowest = rainfall[0]; int month; for (int index = 1; index < rainfall.length; index++) { if (rainfall[index] < lowest) { lowest = rainfall[index]; month = index; } } System.out.println("Least rain happened during month #" + month); } }