Having issues with array.
Seems to pull in the enum files (month and average rainfall) and print accordingly.
Also seems to read in the updated rainfall per month.
However, problem is I can not make updated print with the enum.
Also, last line in program has ..."actual[i]". If use a value for the i, will get that value printed. If leave with variable, get error message which points to this issue....."at Rainfall.main(Rainfall.java:52)"
Any help appreciated.
import java.util.Scanner;
public class Rainfall
{
public enum Average
{
// Rainfall averages are from the internet and for Cleveland, Ohio
January (2.72), February (2.34), March (2.93), April (3.49), May (3.66), June (3.43),
July (3.46), August (3.51), September (3.81), October (3.07), November (3.62), December (3.10);
private double average, actual;
private Average(double average)
{
this.average = average;
}
public double getAverage()
{
return average;
}
}
public static void main(String[] args)
{
Average[] CurrentMonth = Average.values();
Scanner keyboard = new Scanner(System.in);
double [] actual = new double[12];
int i;
for ( i=0; i<CurrentMonth.length; i++)
{
System.out.println("Enter rainfall average for "+ CurrentMonth[i]);
actual[i] = keyboard.nextDouble();
}
System.out.println("Test for rainfall.");
for(Average p1 : Average.values())
{
System.out.println("Month average: " + p1.name() +" : " + p1.average + " " + actual[i]);
}
}
}