Question: Exercise-#.The Person class contains, two string data fields, name and motherName to store the person's name and the person's mother's name. Setter method for the

Exercise-#.The Person class contains, two string data fields, name and motherName to store the person's name and the person's mother's name. Setter method for the field, initializer constr, default constr, an equals() method that overrides the Object class equals; the method takes and Object, type parameter other; (i) if other is instance of Person type cast other to Person type (storing the cast result in a local variable is an option but not necessary) and apply the String equals method to compare the fields as usual return the boolean result of the comparison (ii) otherwise return false. A toString() method, A displayAccess() method; void, no parameter, empty body The Employee class extends Person and it contains. two data fields, hours and wage of type int and double, to store the number of hours the employee worked and the hourly wage, respectively. A default constructor, a constructor that takes two parameters to initialize the Employee fields; the constructor calls the default constructor of the superclass. A toString() method that overrides toString of the superclass, the method calls toString of Person then concatenates to the return value its own fields with explanations. An equals() method that overrides equals()of the Person class, the method takes an Object type parameter other (i) if other is instance of Employee. "in order to generate the boolean return value of equals, type cast other to Employee type (storing the cast result in a local variable is an option but not necessary) then apply the = operator on the fields hours and wage; also, the equals method of the superclass is called and its value added to the above boolean using &&; return the boolean expression you built (ii) otherwise return false. A method named earnings() such that it calculates and returns the employee's earnings (hours multiplied by wage) a method named displayAccess() such that the output as shown in Fig2. is printed to the console; note that this method overrides the 'do nothing' method of the Person class and the comments in the output hint about the implementation of the method #The Test class contains the main method. Test the Person class. Instantiate three Person objects : object reference(mama, papa, pope), the name field(Lona, Leo, leo), the motheName field(Nora, Lia, Lia). Test the toString() method w.r.t. papa. Test the equals() method w.r.t. papa and mama. Test the equals) method w.r.t. papa and pope Test the Employee class. Declare and instantiate a polymorphicrepresentation of an Employee object mailman (Person is the ref type Employee is the initializer constr); choose actual parametervalues for the fields. Call the setter methods of the Person fields and supply a name and a motherName value. Testthe toStrig() methodw.r.t. mailman, print the output with comment. Test the class of mailman using the instanceof operator w.r.t. both Person and Employee; print the output with comment. Test the class of mailman using getClass() and getClass.getName) print the output with comment Test if mailman can call the earnings) method (no typecast) register the error in a comment if not, print the output to console with comment if yes, Instantiate a second Employee supervisor of type Employee with the same field input as mailman. Check the equals() method to see if mailman and supervisor are equal; comment the output. A template for the output fig1. (fig1. Employee mailman data; name: mario, mother name: Sabrina, hours worked: 244, wage: 14.5. mailman instance of Employee??? true. mailman instance of Person?? true. mailman equal supervisor?? true). (fig2. mailman call displayAcces() " access the person name field from employee: Mario. calling toString() name: mario; mother name: sabrina. )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
