Compile and input 1,2,3,4,5,6,7,8,9,10,11,12 and repeat.
This turns out like this:
Highest Index Temps: 2
Highest Average Temps: 2.0
Lowest Index Temps: 3
Lowest Average Temps: 2.0
Right now I am having problems with my arrays between the methods and parameters trying:
public class Temp
{
private int column, row, IndexHigh,IndexLow,highTemps, lowTemps, lowest, largest,AvgHigh, AvgLow;
private int[][] yearTemp;
public Temp()
{
AvgHigh = 0;
AvgLow = 0;
IndexHigh = 0;
IndexLow = 0;
row = 0;
column = 0;
largest = 0;
}
public void sethighTemps(int [][]arrhigh1)
{
for(column = 0; column <= arrhigh1.length; column++)
{
highTemps = arrhigh1[0][column];
}
}
public int gethighTemps()
{
return highTemps;
}
public void setlowTemps(int [][]arrlow1)
{
for(column = 0; column <= arrlow1.length; column++)
{
lowTemps = arrlow1[1][column];
}
}
public int getlowTemps()
{
return lowTemps;
}
public void setIndexHigh(int[][] arrhigh2)
{
for(column = 0; arrhigh2.length > column; column++)
{
if(largest < arrhigh2[0][column])
{
largest = arrhigh2[0][column];
}
}
}
public int getIndexHigh()
{
return largest;
}
public void setIndexLow(int[][] arrlow2)
{
for(column = 0; arrlow2.length >= column; column++)
{
int low = arrlow2[1][column];
lowest = Math.min(low ,arrlow2[1][column]);
//f(lowest < arrlow[1][column])
// {
//int low = arrlow[1][column];
// }
}
}
public int getIndexLow()
{
return lowest;
}
public void setAvgHigh(int[][] arrhigh3)
{
for(column = 0; arrhigh3.length >= column; column++)
{
AvgHigh = (AvgHigh + arrhigh3[0][column]) /arrhigh3.length;
}
}
public double getAvgHigh()
{
return AvgHigh;
}
public void setAvgLow(int[][] arrlow3)
{
for(column = 0; arrlow3.length >= column; column++)
{
AvgLow = (AvgLow + arrlow3[1][column]) /arrlow3.length;
}
}
public double getAvgLow()
{
return AvgLow;
}
}
import java.util.*;
public class TempStats
{
public static void main(String [] args)
{
int[][] arrhigh;
int[][] arrlow;
int largest = 0;
int lowest = 0;
double AvgHigh = 0;
double AvgLow = 0;
Scanner reader = new Scanner(System.in);
Temp temperature = new Temp();
int Rowhighlow = 2;
int ColumnTemps = 12;
int[][] MyTemps = new int[Rowhighlow][ColumnTemps];
int month = 1;
for(int i = 0; i < ColumnTemps; i++)
{
System.out.print("Enter Highest Temperature for Month "+month +" :");
MyTemps[0][i] = reader.nextInt();
temperature.sethighTemps(MyTemps);
temperature.setIndexHigh(MyTemps);
largest = temperature.getIndexHigh();
temperature.setAvgHigh(MyTemps);
AvgHigh = temperature.getAvgHigh();
month += 1;
}
month = 1;
for(int i = 0; i < ColumnTemps; i++)
{
System.out.print("Enter Lowest Temperature for Month "+month +" :");
MyTemps[1][i] = reader.nextInt();
temperature.setlowTemps(MyTemps);
temperature.setIndexLow(MyTemps);
lowest = temperature.getIndexLow();
temperature.setAvgLow(MyTemps);
AvgLow = temperature.getAvgLow();
month += 1;
}
System.out.println();
System.out.println("Highest Index Temps: "+largest);
System.out.println("Highest Average Temps: "+AvgHigh);
System.out.println("Lowest Index Temps: "+lowest);
System.out.println("Lowest Average Temps: "+AvgLow);
}
}
It should run like this:
Highest Index Temps: 12
Highest Average Temps: 6.5
Lowest Index Temps: 1
Lowest Average Temps: 6.5
i just noticed it just runs at index of 2 and stops there

New Topic/Question
Reply




MultiQuote





|