Question: Create a class Person that implements the Comparable interface. A person has a name and a year of birth. You should provide a constructor that
Create a class Person that implements the Comparable interface. A person has a name and a year of birth. You should provide a constructor that takes in the name as a string and the year of birth as an int. You should provide accessor methods for both fields and a toString method. Your compareTo method should compare by birth year.
Once that is complete make two additional classes: Student and Instructor. Both of these classes should extend Person. Students have a major (store it as a string) and Instructors have a salary (store it as an int). Create the appropriate constructors for Student and Instructor (such that they take in and populate all the inherited fields from Person as well as their additional field). Make sure to update your toString method as needed and provide an extra accessor method for the added property.
Supply a PersonTester class that creates and ArrayList typed as Person. Populate that array list with at least one object of type Person, one object of type Instructor, and one object of type Student.
Print out the contents of the ArrayList. Then, using the Collections sort method, sort the ArrayList by birth year and print out the resulting sorted array.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
