
parallel arrays
could somebody please tell me where im going wrong with my code to put grades beside student name i really need some help many thanks ive stuff commented out
code
public class arrays {
public static void main(String[] args) {
String[] students = new String [8];
int[][] grades = new int[8][2];
String tmpStr;
int tmpInt;
students[0] = "Smith";
students[1] = "Jones";
students[2] = "Thompson";
students[3] = "Paul";
students[4] = "Jodan";
students[5] = "Cole";
students[6] = "Dunn";
students[7] = "Nolan";
grades[0][0] = 88;
grades[1][0] = 78;
grades[2][0] = 81;
grades[3][0] = 65;
grades[4][0] = 92;
grades[5][0] = 87;
grades[6][0] = 80;
grades[7][0] = 84;
grades[0][1] = 88;
grades[1][1] = 78;
grades[2][1] = 81;
grades[3][1] = 65;
grades[4][1] = 92;
grades[5][1] = 87;
grades[6][1] = 80;
grades[7][1] = 84;
grades[0][2] = 88;
grades[1][2] = 78;
grades[2][2] = 81;
grades[3][2] = 65;
grades[4][2] = 92;
grades[5][2] = 87;
grades[6][2] = 80;
grades[7][2] = 84;
// Arrays.sort(students);
// Arrays.sort(grades);
// for(int t=0, t<students.length,1 t++)
// for(int i=0, i<students.length,1 i++)
// if(students[i].compareTo(students+1)>0){
// tmpStr = students[i];
// tmpInt = grades[i];
// students[i] = students[i+1];
// grades[i] = grades[i+1];
// students [i+1] = tmpStr;
// grades[i+1] =tmpInt;
// }
//
//// print students
int t;
int i;
for(i=0, i< students.length, i++){
System.out.printf(%s  15s %s* students[i]);
int intSum = 0;
double avgGrad;
for(t=0, t<grades[i].length,t++){
System.out.print(grades[i][t] + " ");
intSum += grades[i][t];
}
int avgGrade = double / intSum;
grades[i].length;
System.out.println( "%5s %s \n" ",grades[i);
}
// }
}
}

Read my blog on this forum about sorting parallel arrays (using a Heapsort implementation). b.t.w. trying to sort parallel arrays is bad design from the old Fortran world ...
kind regards,
Jos


As Jos says, parallel arrays is bad design. You really should create a Student class that contains names and grades, and create just one array of Students.

Quote:
Originally Posted by
belfast09 thanks how di find it
In the right corner, just above my reply you see a link 'Blog entries 3'; click on the number ...
kind regards,
Jos


Quote:
Originally Posted by
belfast09 sorr jos i cant find it
Reread my previous reply; alternatively you can get to the blogs page by pressing 'Blogs' near the top of this page.
kind regards,
Jos