cs4l
12-15-2011, 09:06 AM
been working on some java on day and cant think straight anymore..maybe someone can look at this and help me out
import java.util.*;
public class lab3{
public static void main(String[] args) throws Exception {
java.io.File file = new java.io.File("CPS2231Lab3.data");
Scanner input = new Scanner(file);
//Declare Variables
int ArraySize = input.nextInt(); // READ ARRAY SIZE
int[][] TestScore = new int[ArraySize][3]; // DEFINE ARRAY
System.out.print("Student\t\t Exam1\t Exam2\t Exam3\t Avg \n");
System.out.println("---------\t---------\t---------\t---------\t--------\n");
// PRINT ARRAY
for (int i = 0; i<TestScore.length; i++) {
for (int j = 0; j<TestScore[i].length; j++) {
TestScore[i][j]=input.nextInt();
}
}
double HighAvg=0.0;
// HIGH
int highest[]= new int [3];
for (int i=0;i<TestScore.length;i++){
for (int j=0;j<3;j++) {
if (highest[j]< TestScore[i][j]) {
highest[j] = TestScore[i][j];
// int temp = highest[j];
//System.out.print(highest[j] + " ");
} // end if
} // end [i]
}
//System.out.print(HighAvg/4);
// LOW
int lowest[]=new int[3];
lowest[0]=100;
lowest[1]=100;
lowest[2]=100;
for (int i=0;i<TestScore.length;i++) {
for (int j=0;j<3;j++) {
if (lowest[j]>TestScore[i][j]){
lowest[j]=TestScore[i][j];
}
}
}
// DECLARE STUDENT
int Student=0;
// AVERAGE
System.out.println("");
for (int i=0; i<TestScore.length;i++) {
double TotalAvg=0.0; //finds average
System.out.print(i+1);
System.out.print("\t\t");
for (int j=0;j<TestScore[i].length;j++) {
System.out.print(TestScore[i][j]);
System.out.print("\t\t");
TotalAvg=(TestScore[i][0] + TestScore[i][1] +
TestScore[i][3]) / 3;
}
System.out.print(TotalAvg+"\n");
}
System.out.println(""); //finds and prints lowest
System.out.print("Lowest : ");
for (int i=0;i<lowest.length;i++){
System.out.print(lowest[i]);
System.out.print("\t\t");
}
System.out.println("");
System.out.print("Highest : "); //finds and prints highest
for (int i=0;i< highest.length;i++) {
System.out.print(highest[i]);
System.out.print("\t\t");
HighAvg=HighAvg+highest[i];
}
System.out.println();
}// end class
}// end
import java.util.*;
public class lab3{
public static void main(String[] args) throws Exception {
java.io.File file = new java.io.File("CPS2231Lab3.data");
Scanner input = new Scanner(file);
//Declare Variables
int ArraySize = input.nextInt(); // READ ARRAY SIZE
int[][] TestScore = new int[ArraySize][3]; // DEFINE ARRAY
System.out.print("Student\t\t Exam1\t Exam2\t Exam3\t Avg \n");
System.out.println("---------\t---------\t---------\t---------\t--------\n");
// PRINT ARRAY
for (int i = 0; i<TestScore.length; i++) {
for (int j = 0; j<TestScore[i].length; j++) {
TestScore[i][j]=input.nextInt();
}
}
double HighAvg=0.0;
// HIGH
int highest[]= new int [3];
for (int i=0;i<TestScore.length;i++){
for (int j=0;j<3;j++) {
if (highest[j]< TestScore[i][j]) {
highest[j] = TestScore[i][j];
// int temp = highest[j];
//System.out.print(highest[j] + " ");
} // end if
} // end [i]
}
//System.out.print(HighAvg/4);
// LOW
int lowest[]=new int[3];
lowest[0]=100;
lowest[1]=100;
lowest[2]=100;
for (int i=0;i<TestScore.length;i++) {
for (int j=0;j<3;j++) {
if (lowest[j]>TestScore[i][j]){
lowest[j]=TestScore[i][j];
}
}
}
// DECLARE STUDENT
int Student=0;
// AVERAGE
System.out.println("");
for (int i=0; i<TestScore.length;i++) {
double TotalAvg=0.0; //finds average
System.out.print(i+1);
System.out.print("\t\t");
for (int j=0;j<TestScore[i].length;j++) {
System.out.print(TestScore[i][j]);
System.out.print("\t\t");
TotalAvg=(TestScore[i][0] + TestScore[i][1] +
TestScore[i][3]) / 3;
}
System.out.print(TotalAvg+"\n");
}
System.out.println(""); //finds and prints lowest
System.out.print("Lowest : ");
for (int i=0;i<lowest.length;i++){
System.out.print(lowest[i]);
System.out.print("\t\t");
}
System.out.println("");
System.out.print("Highest : "); //finds and prints highest
for (int i=0;i< highest.length;i++) {
System.out.print(highest[i]);
System.out.print("\t\t");
HighAvg=HighAvg+highest[i];
}
System.out.println();
}// end class
}// end