Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.*; public class SortStudents { private static int amount; priva

ID: 3529307 • Letter: I

Question

import java.util.*; public class SortStudents { private static int amount; private static String[] studentNames; public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of students: "); int numofstudents = input.nextInt(); String[] names = new String[numofstudents]; int[] array = new int[numofstudents]; for(int i = 0; i < numofstudents; i++) { System.out.print("Enter the student's name: "); names[i] = input.next(); System.out.print("Enter the student's score: "); array[i] = input.nextInt(); } selectionSort(names, array); System.out.println(Arrays.toString(names)); } public static void selectionSort(String[] names, int[] array) { for(int i = array.length - 1; i >= 1; i--) { String temp; int currentMax = array[0]; int currentMaxIndex = 0; for(int j = 1; j <= i; j++) { if (currentMax > array[j]) { currentMax = array[j]; currentMaxIndex = j; } } if (currentMaxIndex != i) { temp = names[currentMaxIndex]; names[currentMaxIndex] = names[i]; names[i] = temp; array[currentMaxIndex] = array[i]; array[i] = currentMax; //everything works until here then it need to show names and scores from the code below. } for (int j = 0; j < amount; j++) { // this part isn't correct to show name and scores in deceasing order System.out.println(studentNames [j] + " studentScores " + [j]); } } } }

Explanation / Answer

I could be wrong, and tell me if I am, but you never set what "amount" is. I think the for loop doesn't go.