Homework Assignment #6 Solution

$35.00 $30.80


Grading: Each programming problem is graded as follows


  • A submission which does not compile gets 0.


  • A submission which compiles but does something completely irrelevant gets 0.


  • A submission which works (partially) correctly, gets (up to) %80 of the total credit.


  • %20 is reserved for the coding style. Follow the coding style described in the book.





Problem 1 [65pts]. Define a class named Person that contains two instance variables of type String that stores the first name and last name of a person plus appropriate accessor and mutator methods. You must provide a constructor which takes as input the first name and the last name. Additionally, a copy constructor must be provided. Lastly, equip the class with toString and equals methods.


Next, define a class named Student that is derived from Person. The constructor should receive first name, last name, and also assigns values to student id, course, and teacher name. This class should redefine the toString (include student info as well) and equals methods. Include appropriate constructors (including a copy constructor).


Define a class named Teacher that is derived from Person. This class should contain instance variables for the subject name and salary. Include appropriate constructors (including a copy constructor). Finally, redefine thetoString (include all teacher information) and equals methods.


Create a main method (in a class called Test) that creates a 4-element array of Persons.


Populate the array with two student objects and two teacher objects with different values.


Next, in a for loop, print each one to the console.


Submission format: You must submit one file Test.java which contains the public class Test containing the tests in its main() method. The other classes are in this file as well.





Problem 2 [5pts]. Explain the difference between overriding a method and overloading a method in Java.


Submission format: You must submit one file Problem2.txt which contains your answer.


Please be brief.