- The total rainfall for the year
- The average monthly rainfall
- The month with the most rain
- The month with the least rain
Input validation: Do not accept negative numbers for monthly rainfall figures. My mind right now is blank as far as how to make the program calculate and show the month with the most rain. Any help is greatly appreciated! Here's what I have so far:
import java.text.*;
import javax.swing.*;
class Rainfall
{
public static void main (String[] args)
{
DecimalFormat df = new DecimalFormat("0.00");
String[] monthName = { "January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December" };
double[] rainfall = new double[12];
double[] quarterAverage = new double[4];
double annualAverage,
sum,
difference;
sum = 0.0;
for (int i = 0; i < rainfall.length; i++)
{
rainfall[i] = Double.parseDouble(
JOptionPane.showInputDialog(null,
"Rainfall for" + monthName[i]));
sum += rainfall[i];
}
annualAverage = sum / 12.0;
System.out.println( "Total rainfall: " + sum);
System.out.println( "Average Monthly Rainfall: " + df.format(annualAverage ));
}
}

New Topic/Question
Reply




MultiQuote




|