Question: JAVA I need help with the following: 1. Create a Person class with name and phone number as attributes. 2. Create an Employee class which

JAVA

I need help with the following:

1. Create a Person class with name and phone number as attributes.

2. Create an Employee class which inherits from class Person and which also has an OIB number.

3. Override the toString() method for both classes. This should print out the details of the object.

4. Override the equals() method for both classes.

a. Two person objects are considered equal if they have the same name and phone number.

b. Two employees are considered equal if they have the same OIB number.

c. Ensure that the equals method checks for an object being compared to itself and also being compared to null.

The part with Person is done, I need for Employee:

public class Person { String name; int phoneNumber;

public String toString() { return "Person{" + "name='" + name + '\'' + ", phoneNumber=" + phoneNumber + '}'; }

public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Person)) return false;

Person person = (Person) o;

if (phoneNumber != person.phoneNumber) return false; return name != null ? name.equals(person.name) : person.name == null; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!