I am having a problem with my code it seems to endlessly loop with user input of two temps never ending. As I am a newbie at this could someone take a look at what I've got so far and fix what's wrong here are my two classes This is my third week of class, I'd like to know how am I doing? [/TEX]
import java.util.*;
import java.text.*;
import java.math.*;
public class Ch9_PrExercise10 {
/**
* This program will store the highest and lowest temeratures for each month for a year
* Output average high, average low, and highest and lowest temperatures of the year.
* @Written by: ellas
*/
public static void main(String[] args)
{
Statistics unc = new Statistics();
double[][] calendarTemps = new double[2][12];
int i, j, temp = 0;
Scanner keyboard = new Scanner(System.in);
for (i = 0; i < calendarTemps.length; i++)
{
for (j = 0; j < calendarTemps[i].length; j++)
{
Exception exp = null; // temp Exception object, pointing to null for now
do{
try{
exp = null;
System.out.println("Please input high temperature " + (i + 1) + " ");
temp = keyboard.nextInt();
System.out.println("Please input low temperature " + (j + 1) + " ");
temp = keyboard.nextInt();
calendarTemps[i][j] = temp;
}catch(Exception e){exp = e;}
} while(calendarTemps[i][j] == null || exp != null);
}
double avgHTemp = unc.averageHigh(calendarTemps);
double avgLTemp = unc.averageLow(calendarTemps);
System.out.println("Average high temperatures of the year is: " + avgHTemp);
System.out.println("Average low temperatures of the year is: " + avgLTemp);
}
}
public class Statistics
{
int avgLTemp = 0;
int higHTemp;
int loWTemp;
public int getData()
{
return 0;
}
public double averageHigh(double[][] avgHigh)
{
int i = 0;
double sumHTemp = 0;
double avgHTemp = 0;
for (i=0; i < avgHigh.length; i++)
{
sumHTemp = sumHTemp + avgHigh[0][i];
}
avgHTemp = (sumHTemp/avgHigh.length);
return avgHTemp;
}
public double averageLow(double[][] avgLow)
{
int i = 0;
double sumLTemp = 0;
double avgLTemp = 0;
for (i=0; i < avgLow.length; i++)
{
sumLTemp += avgLow[1][i];
}
avgLTemp = (sumLTemp/avgLow.length);
return avgLTemp;
}
}