import java.util.Scanner;
/**Write a program that will input 10 students names
* in random order and their corresponding 3 project scores.
* Data will be read into 2 separate arrays: an array of strings
* for the names and a 2D array for the scores.
* Output input data in table form
*For each of the 3 projects, output the name of the student(s) who scored
the highest mark.
**/
class NameAndGrades {
public static void main
(String[] args
) { //Scanner object to allow user input
Scanner scnr
= new Scanner
(System.
in);
//This array will store the names of the students
//This 2D array will store the 3 project scores
int[][] scores = new int[10][3];
//Ask user to input the student names
System.
out.
println("Enter the 10 student names: ");
for (int index = 0; index < 10; index++) {
System.
out.
print("Student " + (index
+ 1) + ": "); names[index] = scnr.nextLine();
}
selectionSort(names);
//Will print the names alphabetically
//THIS WILL BE DELETED LATER, IT WAS JUST TO CHECK IF IT DID ITS JOB
System.
out.
println("The students' names in alphabetical order: ");
for (int i = 0; i < names.length; i++) {
}
//Ask user to enter the corresponding project scores
System.
out.
println("Enter the 3 project scores for each student: "); for(int i = 0; i < names.length; ++i) {
System.
out.
print("Enter three project marks for " + names
[i
] + " : "); scores[i][0] = scnr.nextInt();
scores[i][1] = scnr.nextInt();
scores[i][2] = scnr.nextInt();
}
//PRINT NAMES AND SCORES SIDE BY SIDE
//MAKE TABLE HEADING HERE
System.
out.
println("\n\n\t\tMarks Table: \n========================================="); for(int i = 0; i < names.length; ++i) {
System.
out.
print(names
[i
] + " marks: " + scores
[i
][0] + ", " + scores
[i
][1] + ", " + scores
[i
][2] + "\n"); }
}
/**Selection sort method made to sort the student names in
* alphabetical order.
@param names names of students
@return the names organized alphabetically
**/
for (int index = 0; index < names.length - 1; ++index) {
int minIndex = index;
for (int j = index + 1; j < names.length; ++j) {
if (names[j].compareTo(names[minIndex]) < 0) {
minIndex = j;
}
}
names[index] = names[minIndex];
names[minIndex] = temp;
}
return (names);
}
}