I am writing a program that allows the user to create an array of 12 numbers and my program has the ability to find the highest month's rainfall, the average rain fall, and the total rainfall. The total and average rainfall work fine but in the getHighestMonth() method i continually have the issues of my variable month being found as a java.lang.String but it requires a double. The highest month method is supposed to display the actual month's name and not the amount of rainfall.
Thanks for the help.
public class RainFall { public double[] values; // Constructor method public RainFall(double[] d) { values = new double[d.length]; for (int index = 0; index < d.length; index++) values[index] = d[index]; } // Return the sum total of values in the array public double getTotalRainFall() { double total = 0.0; for(double val : values) total = total + val; return total; } // Return the average (mean) of the values in array public double getAverageRainFall() { double mean = 0.0; int count = 0; mean = getTotalRainFall()/values.length; return mean; } public double getHighestMonth() { double highest = values[0]; String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novemeber", "December"}; String month = ""; for (int index = 0; index < values.length; index++) { if (values[index] > highest) month = months[index]; highest = values[index]; } return month; } }