Question: All this together please solve it quickly 1. Design a super class Person and subclasses Student and Instructor using your idea obtained in previous lab



All this together please solve it quickly
1. Design a super class Person and subclasses Student and Instructor using your idea obtained in previous lab sessions. Add suitable state and behavior. 2. Override the method equals in Person, Student and Instructor classes. Hints: - The equals() method is inherited from the Object class. The equals() method compares the contents of two objects and if they have the same values for all instant data fields, the method will retune true, otherwise it will return false. You need to use instanceof operator in your implementation. - For example, the equals method is overridden in the Circle class as shown below: public boolean equals(Object o) { if (o instanceof Circle) { return radius == ((Circle)o).radius; } else return false; } 3. Create a test class to perform the following tasks: a. In the main method create an ArrayList of type Person. b. Add the objects (person1, person2, instructori, student1) you have created to the ArrayList (use an ArrayList method). Check point: Here a Person (super-type) reference both Instructor and Student (subtype), this is an example of polymorphism. Otherwise we need to have one ArrayList for each type of objects. C. Print out the ArrayList objects (use for-each loop and the objects' toString() method). Check point: Here is another example of polymorphism, where one statement is used to print the object details and with each object the appropriate implementation of toString() will be bind despite it is a Person, Instructor or Student object d. Print out the number of objects in the ArrayList (use an ArrayList method). e. Remove the Student object student1 from the ArrayList (use an ArrayList method). f. Print out the number of objects in the ArrayList again (use an ArrayList method). g. Check whether the ArrayList still has an object equals to the Student object studenti (1. use an ArrayList method. 2. Use the equals method and for- each loop.) 4. Fix any compiling errors in all the classes. 5. Run the Test class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
