【发布时间】:2021-02-06 10:29:59
【问题描述】:
我需要帮助来完成我们班上的给定作业。我们被分配了一项任务,我们应该用学生的身份证、名字、姓氏、课程、年级、我们的预科成绩、期中成绩、期末成绩、暂定和期末成绩来制作学生记录。问题围绕着我应该用来以并行顺序对以下数组中的元素进行排序的算法。这是我的代码的一部分。
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;
}
这是我需要帮助的部分。我不知道应该使用什么算法对数组元素进行排序。如果是这样,我应该如何将所有 8 个数组放在一个排序算法中?方法如下。
public static void sortDataBasedOnNames(String[] id, String[] n, String[] c, int[] yLevel, byte[] p, byte[] m, byte[] t,
byte[] f) {
} // end of sortBasedOnNames method
任何帮助或建议将不胜感激。正如你所知道的,我对此完全陌生,并且真的尽我最大的努力来解决如何解决这个算法。
【问题讨论】:
-
“并行顺序”是什么意思?您需要按哪个字段对数组进行排序?
标签: java arrays algorithm sorting