Hourly Temperature /* * Main.java * * Created on September 27, 2007, 4:43 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package hourlytemperature; /** * * @author instructor */ public class Main { /** Creates a new instance of Main */ public Main() { } /** * @param args the command line arguments */ public static void main(String[] args) { // define variables double currentTemp = 0; double totalTemp = 0; double maxTemp = 0; double minTemp = 0; int maxHour = 0; int minHour = 0; //start the loop for(int hours = 0; hours<24; hours++) { System.out.println("Please enter the current temperature at this hour: "); currentTemp = MyInput.readDouble(); totalTemp = totalTemp + currentTemp; if(hours == 0) { maxTemp = currentTemp; minTemp = currentTemp;
} else { if(currentTemp > maxTemp) { maxTemp = currentTemp; maxHour = hours; }//end if statement if(currentTemp < minTemp) { minTemp = currentTemp; minHour = hours; }//end if statement }//end if else stetement }//end for loop //calculate average temp double averageTemp = totalTemp / 24; //display results System.out.println("The max temp is "+ maxTemp +" degrees happened at the hour of "+maxHour); System.out.println("The min temp is "+ minTemp +" degrees happened at the hour of "+minHour); System.out.println("The average temp during the 24 hour period is: " + averageTemp); }//end of main() method }//end of Main class