can you help me figure out why my program doesn't run? the fatal error I get is "Student must be defined in its own file", but that doesn't seem helpful? here's my code: package student;   public class Sort { public static void sort(Student[] studentArr) { int minIndex = 0; for(int i = 0; i < studentArr.length; i++) { minIndex = i; for(int j = i+1; j< studentArr.length; j++) { if(studentArr[j].compareTo(studentArr[minIndex]) < 0) { minIndex = j; } } Student temp = studentArr[i]; studentArr[i] = studentArr[minIndex]; studentArr[minIndex] = temp; } }   public static void main (String[] args) { Student[] studentArr = { new Student("Lat", 4.0), new Student("Ampere", 2.4), new Student("Jing", 3.0), new Student("Memphis", 3.1) };   System.out.println("The students are: "); for(Student s: studentArr) System.out.println(s);   sort(studentArr);   System.out.println("Students after sorting are:"); for(Student s: studentArr) System.out.println(s); } }   public class Student implements Comparable { private int studentID; private String name; private double gpa;   private static int maxStudentID;   public Student() { maxStudentID++; this.studentID = maxStudentID; }   public Student(String name, double gpa) { this(); this.name = name; this.gpa = gpa; }   public int getStudentID() { return studentID; }   public String getName() { return name; }   public void setName(String name) { this.name = name; } public double getGpa() { return gpa; } public void setGpa(double dpa) { this.gpa = gpa; } @Override public String toString() { return "Student [ID=" + studentID + ", name:" + name + ", GPA=" + gpa+ "]"; } @Override public int compareTo(Student otherStudent) { if(this.studentID < otherStudent.studentID) return -1; if(this.studentID > otherStudent.studentID) return 1; return 0; }   }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

can you help me figure out why my program doesn't run? the fatal error I get is "Student must be defined in its own file", but that doesn't seem helpful?

here's my code:

package student;

 

public class Sort {

public static void sort(Student[] studentArr) {

int minIndex = 0;

for(int i = 0; i < studentArr.length; i++) {

minIndex = i;

for(int j = i+1; j< studentArr.length; j++) {

if(studentArr[j].compareTo(studentArr[minIndex]) < 0) {

minIndex = j;

}

}

Student temp = studentArr[i];

studentArr[i] = studentArr[minIndex];

studentArr[minIndex] = temp;

}

}

 

public static void main (String[] args) {

Student[] studentArr = {

new Student("Lat", 4.0),

new Student("Ampere", 2.4),

new Student("Jing", 3.0),

new Student("Memphis", 3.1)

};

 

System.out.println("The students are: ");

for(Student s: studentArr)

System.out.println(s);

 

sort(studentArr);

 

System.out.println("Students after sorting are:");

for(Student s: studentArr)

System.out.println(s);

}

}

 

public class Student implements Comparable <Student> {

private int studentID;

private String name;

private double gpa;

 

private static int maxStudentID;

 

public Student() {

maxStudentID++;

this.studentID = maxStudentID;

}

 

public Student(String name, double gpa) {

this();

this.name = name;

this.gpa = gpa;

}

 

public int getStudentID() {

return studentID;

}

 

public String getName() {

return name;

}

 

public void setName(String name) {

this.name = name;

}

public double getGpa() {

return gpa;

}

public void setGpa(double dpa) {

this.gpa = gpa;

}

@Override

public String toString() {

return "Student [ID=" + studentID + ", name:" + name + ", GPA=" + gpa+ "]";

}

@Override

public int compareTo(Student otherStudent) {

if(this.studentID < otherStudent.studentID)

return -1;

if(this.studentID > otherStudent.studentID)

return 1;

return 0;

}

 

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education