Question: In java: Create the Student class derived from the Person class. A student has a studentNumber (an int). Write constructors, the accessor and modifier, a

In java:

Create the Student class derived from the Person class. A student has a studentNumber (an int). Write constructors, the accessor and modifier, a writeOutput method and an equals method. (You can call two Students equal if they have the same ID number). write a compareTo so that students are compared according to their ID number.

Create the Undergraduate class derived from the Student class. An undergraduate has one attribute called Level, an int. all other attributes are derived from Student. Write all constructors, modifier and accessor, a writeOutput. In this instance do NOT add a compareTo. You will see that by doing this you are allowing undergrads to be compared the way that Students are compared. This is because the compiler will look for a compareTo in the undergrad class, and finding none will then go to its super class and find the one in Student.

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner;

public class InheritanceDemo {

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 myL = new ArrayList(); while(fileInput.hasNext()) { int id=fileInput.nextInt(); int level = fileInput.nextInt(); String name=fileInput.nextLine(); Undergraduate u=new Undergraduate(name, id, level); myL.add(u); } System.out.println(); System.out.println("Undergrads not sorted"); for(int i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!