THIS IS WHAT THE PROGRAM SAYS "Write a program that uses a two-dimensional arra to store the highest and lowest temperatures for each month of the year.The program should output the average high , average low and highest and lowest temperatures of the year. Your program will include the following methods:
a. Method getData: this method read and stores the data in the two-dimensional array
b. Method averageHigh: this method calculates and returns the average high temp of the year
c. Method averageLow: this method calculates and returns the average low temp of the year
d. Method indexHighTemp: this method returns the index of the highest temperature in the
array
e. Method indexLowTemp: this method returns the index of the lowest temperature in the array
this is what i have
import java.text.*;
import java.math.*;
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);
<strong class="highlight">for</strong> (i = 0; i < calendarTemps.length; i++)
{
<strong class="highlight">for</strong> (j = 0; j < calendarTemps[i].length; j++)
{
Exception exp = null; 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 <strong class="highlight">of</strong> <strong class="highlight"><vb_highlight>the</strong></vb_highlight> <strong class="highlight">year</strong> is: " + avgHTemp);
System.out.println("Average low temperatures <strong class="highlight">of</strong> <strong class="highlight"><vb_highlight>the</strong></vb_highlight> <strong class="highlight">year</strong> 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;
<strong class="highlight">for</strong> (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;
<strong class="highlight">for</strong> (i=0; i < avgLow.length; i++)
{
sumLTemp += avgLow[1][i];
}
avgLTemp = (sumLTemp/avgLow.length);
return avgLTemp;
}
}

New Topic/Question
Reply




MultiQuote




|