I need help with a given assignment to me in our class. We are given an assignment where we are supposed to make a student record with the student's id, first name, last name, course, year level, our prelim grade, midterm grade, final grade, tentative and final grade. The problem revolves around the algorithm I should use to sort the elements in the following arrays in parallel order. Here is a part of my code.
System.out.print("Number of students to record? ");
count = Integer.parseInt(keyboard.nextLine());
id = new String[count];
names = new String[count];
course = new String[count];
yearLevel = new int[count];
pGrade = new byte[count];
mGrade = new byte[count];
tFGrade = new byte[count];
fGrade = new byte[count];`
showData(id, names, course, yearLevel, pGrade, mGrade, tFGrade, fGrade); // Invoke the method for displaying the array elements
// Show the students in sorted order
System.out.println("Sorted Data");
showData(id, names, course, yearLevel, pGrade, mGrade, tFGrade, fGrade);
}
public static void populateArrays(String[] id, String[] n, String[] c, int[] y, byte[] p, byte[] m, byte[] t, byte[] f) {
for (int index = 0; index < n.length; index++) {
System.out.print("Enter the id number of student " + (index + 1) + ":");
id[index] = keyboard.nextLine();
System.out.print("Enter the name of student " + (index + 1) + ":");
n[index] = keyboard.nextLine();
System.out.print("Enter the course of student " + (index + 1) + ":");
c[index] = keyboard.nextLine();
System.out.print("Enter the year level of student " + (index + 1) + ":");
y[index] = Integer.parseInt(keyboard.nextLine());
System.out.print("Enter the prelim grade of student " + (index + 1) + ":");
p[index] = Byte.parseByte(keyboard.nextLine());
System.out.print("Enter the midterm grade of student " + (index + 1) + ":");
m[index] = Byte.parseByte(keyboard.nextLine());
System.out.print("Enter the tentative final grade of student " + (index + 1) + ":");
t[index] = Byte.parseByte(keyboard.nextLine());
// compute the final grade of student as the average of prelim, midterm and tentative final grade
f[index] = (byte) ((1.0 * p[index] + 1.0 * m[index] + 1.0 * t[index]) / 3.0 + 0.5);
}
return;
}
This is the part I need help. I don't know what algorithm I should use to sort the element of the arrays. And if so, how should I put all 8 arrays in one sort algorithm? Here is the method.
public static void sortDataBasedOnNames(String[] id, String[] n, String[] c, int[] yLevel, byte[] p, byte[] m, byte[] t,
byte[] f) {
} // end of sortBasedOnNames method
Any help or advice will be greatly appreciated. As you can tell, I am all new to this and really trying my best to wrapped my head on how to solve this algorithm.