How to calculate & return highestmonth and lowestmonth as string in interactions tab?
Trying to create a getHightestMonth out of the Arrays made and return the string of the month for the highest number listed in the array.
Code java:
< public class RainFall
{
// Instance variable
private String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
private double[] values;
// Constructor method
public RainFall()
{
// Nothing to do yet, but good practice to always include a
// no-argument constructor method
}
// Overloaded Constructor method - accepts an array of doubles
public RainFall(double [] newArray)
{
values = new double [newArray.length];
for(int i = 0; i < values.length; i++) {
values[i] = newArray[i];
}
}
// Adds up and return the total of the values in the array numbers
public double getTotal()
{
double total = 0.0;
for (double val : values)
{
total += val;
}
return total;
}
// Return the mean (average) of the values in array numbers
public double getAverage()
{
double average = 0.0;
average = getTotal() / values.length;
return average;
}
// Return the Highest Month
public String getHighestMonth()
{
String hiMonth = "";
return hiMonth;
}
// Return the Lowest Month
public String getLowestMonth()
{
String loMonth = "";
return loMonth;
}
}>
Re: How to calculate & return highestmonth and lowestmonth as string in interactions
If the array values has the same length as monthNames (obviously being 12) then it is just a matter of getting the index of the highest number in values and return the String in monthNames based on that index.