Have first part of program written. It will use enum array for month and average rainfall amount.
It starts at January and runs through December.
Second part is to ask user at what month they want to start (example, April).
The printout would then start at April of year -1 (prior year) and run through March of current year.
Lots of time searching internet with no luck. I am looking for method to ask for start month, then read enum data to find that month and then start the program from that new point.
Hints, suggestions welcome.
Code snippets greatly appreciated.
Thanks.
import java.util.Scanner;
import java.util.Arrays;
public class Rainfall
{
public enum Average
{
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;
private Average(double average)
{
this.average = average;
}
public double getAverage()
{
return this.average;
}
}
public static void main(String[] args)
{
Average[] CurrentMonth = Average.values();
Scanner keyboard = new Scanner(System.in);
Scanner scannerObject = new Scanner(System.in);
double [] actual = new double[13];
double [] difference = new double[13];
int i;
//*******************************************************************************
//Now start input for what month at which to start.
//*******************************************************
System.out.println("From which month do you want to start?");
System.out.println("Please use January, February, March, April, May.......");
String month = scannerObject.next();
System.out.println("You entered : "+month);
for ( i=0; i<CurrentMonth.length; i++)
{
System.out.println("Enter rainfall average for "+ CurrentMonth[i]);
actual[i] = keyboard.nextDouble();
//
//book problem requires output to show "...how much above or below average".
//this will lead into negative numbers if below average. this is why "Math.abs" is commented out.
//difference[i] = Math.abs(actual[i]-CurrentMonth[i].getAverage( ));
//
difference[i] = (actual[i]-CurrentMonth[i].getAverage( ));
}
System.out.println("Test for rainfall.");
System.out.println("Monthly average: Month Average Current Difference");
for ( i=0; i<CurrentMonth.length; i++)
{
System.out.println("Month average: " + CurrentMonth[i] + " " + CurrentMonth[i].getAverage( ) + " " + actual[i] +" "+ difference[i]);
}
}
}