Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise-#.The Person class contains, two string data fields, name and motherNam

ID: 3888778 • Letter: E

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 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. )

Explanation / Answer

Note : Could u please check the results..If u want me to do any modifications.I will do it.Thank You

Person.java

public class Person {


//Declaring instance variables
private String name;
private String mothername;

//Zero argumented constructor
public Person() {

}

//Parameterized constructor
public Person(String name, String mothername) {
this.name = name;
this.mothername = mothername;
}

//getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMothername() {
return mothername;
}
public void setMothername(String mothername) {
this.mothername = mothername;
}

//Equals method compare two objects
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
if (mothername == null) {
if (other.mothername != null)
return false;
} else if (!mothername.equals(other.mothername))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "Name=" + name + ", Mother name=" + mothername;
}

void displayAccess() {

}

}

__________________

Employee.java

public class Employee extends Person {


//Declaring instance variables
private int hours;
private double wage;

//Zero argumented constructor
public Employee() {
super();

}

//Parameterized constructor
public Employee(int hours, double wage) {
this.hours = hours;
this.wage = wage;
}

//This method compared two objects
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (hours != other.hours)
return false;
if (Double.doubleToLongBits(wage) != Double
.doubleToLongBits(other.wage))
return false;
return true && super.equals(obj);
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return super.toString() + ", Hours=" + hours + ", wage=" + wage;
}

//This method calculates the earnings
public double earnings() {
return hours * wage;
}

@Override
public void displayAccess() {
System.out.println(" Employee:" + getName());
System.out.println(toString());

}


}

______________________

Test.java

public class Test {

public static void main(String[] args) {

//Creating three Person class objects
Person mama = new Person("Lona", "Nora");

Person papa = new Person("Leo", "Lia");
Person pope = new Person("leo", "Lia");

System.out.println(papa.toString());

//Checking papa and mama objects are equal or not
boolean bool = papa.equals(mama);
if (bool) {
System.out.println("** Papa and Mama are equal **");
} else {
System.out.println("** Papa and Mama are not equal **");
}


//Checking papa and pope objects are equal or not
bool = papa.equals(pope);

if (bool) {
System.out.println("** Papa and Pope are equal **");
} else {
System.out.println("** Papa and Pope are not equal **");
}

Person mailman = new Employee(244, 14.5);
mailman.setName("Mario");
mailman.setMothername("Sabrina");


System.out.println(mailman.toString());

System.out.print("Mailman instance of Person ??");
if (mailman instanceof Person) {
System.out.print(" true");
} else {
System.out.print(" false ");
}

System.out.print(" Mailman instance of Employee ??");
if (mailman instanceof Employee) {
System.out.print("true");
} else {
System.out.print("false");
}
System.out.println(" " + mailman.getClass());
System.out.println(mailman.getClass().getName());

System.out.println("Mailman cannot call earning() method");

Employee supervisor = new Employee();
supervisor.setName("Mario");
supervisor.setMothername("Subrina");


boolean boo1 = mailman.equals(supervisor);
if (boo1) {
System.out.println("** Mailman and Supervisor are equal **");
} else {
System.out.println("** Mailman and Supervisor are not equal **");
}

}


}

______________________

Output:

Name=Leo, Mother name=Lia
** Papa and Mama are not equal **
** Papa and Pope are not equal **
Name=Mario, Mother name=Sabrina, Hours=244, wage=14.5
Mailman instance of Person ?? true
Mailman instance of Employee ??true
class org.students.Employee
org.students.Employee
Mailman cannot call earning() method
** Mailman and Supervisor are not equal **


_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote