Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create the Student class with methods and attributes given in the PowerPoint. (You can call two Students equal if they have the same ID number).

Create the Student class with methods and attributes given in the PowerPoint. (You can call two Students equal if they have the same ID number).

Create a Graduate class (this is different from the PowerPoint which has a Masters and a Doctorate class, but let us just have one, derived from Student, and add another attribute (a String) called degree, which is either "Masters" or "Doctorate", and a boolean called thesis (meaning whether they have completed their thesis and initially set to false).

Submit your L11a project.

Student Class:

-studentNumber: int

+reset(String newName, int newStudentNumber):void

+getStudentNumber(): int

+setStudentNumber(int newStudentNumber): void

+writeOutput(): void

+equals(Student otherStudent): boolean

Graduate class:

+make your self

Below is the correct code for the main method

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public static void main(String[] args) {

File inFile = new File("student.in");

Scanner fileInput = null;

try {

fileInput = new Scanner(inFile);

} catch (FileNotFoundException ex) {

//Logger.getLogger(Lab10.class.getName()).log(Level.SEVERE, null, ex);

}

//input student into an ArrayList

ArrayList myList = new ArrayList();

while(fileInput.hasNext())

{ int id=fileInput.nextInt();

String name=fileInput.nextLine();

Student s=new Student(name, id);

myList.add(s);

}

System.out.println();

System.out.println("Students not sorted");

for(int i=0; i

{

myList.get(i).writeOutput();

}

Collections.sort(myList);

System.out.println();

System.out.println("Students sorted");

for(int i=0; i

{

myList.get(i).writeOutput();

}

fileInput.close();

inFile = new File("graduate.in");

try {

fileInput = new Scanner(inFile);

} catch (FileNotFoundException ex) {

//Logger.getLogger(Lab10.class.getName()).log(Level.SEVERE, null, ex);

}

//input student into an ArrayList

ArrayList myG = new ArrayList();

while(fileInput.hasNext())

{ int id=fileInput.nextInt();

String MD = fileInput.next();

String thesis = fileInput.next();

String name=fileInput.nextLine();

Graduate g=new Graduate(name, id, MD, thesis);

myG.add(g);

}

System.out.println();

System.out.println("Graduates not sorted");

for(int i=0; i

{

myG.get(i).writeOutput();

}

Collections.sort(myG);

System.out.println();

System.out.println("Graduates sorted");

for(int i=0; i

{

myG.get(i).writeOutput();

}

fileInput.close();

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions