This method needs improvement ivate static void sortList(Student[] s) { Student temp; int minIndex = 0; for (int x = 0; x < s.length - 1; x++) { minIndex = x; for (int y = x + 1; y < s.length; y++) { if (s[minIndex].getLastName().compareToIgnoreCase(s[y].getLastName()) > 0) minIndex = y; } (minTndor

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please fix the private static void sortList(Student[] s) method 

// Warning! using the last name as the sort key is not sufficient for a realistic set of records
// This method needs improvement
private static void sortList(Student[] s) {
Student temp;
int minIndex = 0;
for (int x = 0; x < s.length - 1; x++) {
minIndex = X;
for (int y = x + 1; y < s.length; y++) {
if (s[minIndex].getLastName().compareToIgnoreCase(s[y].getLastName()) > 0)
minIndex = y;
}
if (minIndex != x) {
temp = s[x];
s[x] = s[minIndex];
s[minIndex] = temp;
} // end of sortList method
|} // end of class
Transcribed Image Text:// Warning! using the last name as the sort key is not sufficient for a realistic set of records // This method needs improvement private static void sortList(Student[] s) { Student temp; int minIndex = 0; for (int x = 0; x < s.length - 1; x++) { minIndex = X; for (int y = x + 1; y < s.length; y++) { if (s[minIndex].getLastName().compareToIgnoreCase(s[y].getLastName()) > 0) minIndex = y; } if (minIndex != x) { temp = s[x]; s[x] = s[minIndex]; s[minIndex] = temp; } // end of sortList method |} // end of class
public class StudentList {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {...}
private static void showList(Student[] studs) {
for (int x = 0; x < studs.length; x++) {
System.out.println(studs[x].tostring());
}
private static Student readStudent() {
System.out.print("first name: ");
String f = keyboard.nextLine();
System.out.print("middle name: ");
String m = keyboard.nextLine ();
System.out.print("last name: ");
String l = keyboard.nextLine();
System.out.print("age: ");
int a = Integer.parseInt(keyboard.nextLine(O);
System.out.print("grade point average: ");
double g = Double.parseDouble (keyboard.nextLine());
Student
= new Student(f, m, l, a, g);
return s;
}
Transcribed Image Text:public class StudentList { static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) {...} private static void showList(Student[] studs) { for (int x = 0; x < studs.length; x++) { System.out.println(studs[x].tostring()); } private static Student readStudent() { System.out.print("first name: "); String f = keyboard.nextLine(); System.out.print("middle name: "); String m = keyboard.nextLine (); System.out.print("last name: "); String l = keyboard.nextLine(); System.out.print("age: "); int a = Integer.parseInt(keyboard.nextLine(O); System.out.print("grade point average: "); double g = Double.parseDouble (keyboard.nextLine()); Student = new Student(f, m, l, a, g); return s; }
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY