Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java Introduction: In this lab, we will explore inheritance in detail and practice its implementation. You will implement multiple classes in two separate problems to
java
Introduction: In this lab, we will explore inheritance in detail and practice its implementation. You will implement multiple classes in two separate problems to create two unique inheritance hierarchies. You will also write JavaDoc comments for the classes and methods. You must use the instanceof operator in the equals methods to ensure there will not be any ClassCastExceptions when you cast objects. Create a project in Eclipse name Lab6 and complete the following two problems. Problem 1: In the first inheritance hierarchy, we will be exploring a work environment that consists of multiple classes. These classes include a Person, Employee, Manager, and Executive. The Employee is a child of Person, Manager is a child of Employee, and Executive is a child of Manager. This problem will help us practice pure inheritance principles. The following are the requirements for each class. 1. Class Person: Create a class named Person which has the following instance properties and public interface. a. Instance Properties: i. String name - the name of the person. ii. int yearOfBirth - the year of birth of the person. b. Public Interface: i. Constructors: Two constructors need to be provided. Namely a default constructor and a workhorse constructor. The default constructor will initialize the instance properties to their default values (numbers to 0 and Strings to s). ii. Getters and Setters for each instance property. iii. public boolean equals(Object o) The method returns true if the two Persons have the same name and year of birth and false, otherwise. iv. public String toString() The method returns a String representing the Person object that includes the name and year of birth. The formatted string should follow this example: I am a person whose name is James Bond and was born in 1997.. 2. Class Employee: Create a class named Employee which is a child of Person and has the following instance properties and public interface. a. Instance Properties: i. double salary the salary of the person (for example, $85,000.00). b. Public Interface: i. Constructors: Two constructors need to be provided. Namely a default constructor and a workhorse constructor. The default constructor will initialize the instance properties to their default values (numbers to 0 and Strings to ). Note, you must utilize the super() constructor call appropriately to set the parent's instance properties. ii. Getters and Setters for each instance property. iii. public boolean equals(Object o) The method returns true if the two Employees have the same name, year of birth, and salary and false, otherwise. Do not forget to use the parent's equals() method when applicable. iv. public String toString - The method returns a String representing the Employee object that includes the name, year of birth, and salary. The formatted string should follow this example: I am an employee and have a salary of $50,000.00. I am a person whose name is James Bond and was born in 1997.. Note that you should utilize the parent's toString() method where applicable. 3. Class Manager: Create a class named Manager which is a child of Employee and has the following instance properties and public interface. a. Instance Properties: i. String department - the department of the manager. b. Public Interface: i. Constructors: Two constructors need to be provided. Namely a default constructor and a workhorse constructor. The default constructor will initialize the instance properties to their default values (numbers to 0 and Strings to "*). Note, you must utilize the super() constructor call appropriately to set the parent's instance properties. ii. Getters and Setters for each instance property. iii. public boolean equals(Object o) - The method returns true if the two Managers have the same name, year of birth, salary, and department and false, otherwise. Do not forget to use the parent's equals() method when applicable. iv. public String toString() The method returns a String representing the Manager object that includes the name, year of birth, and salary. The formatted string should follow this example: I am a manager of the Human Resource department. I am an employee and have a salary of $50,000.00. I am a person whose name is James Bond and was born in 1997.. Note that you should utilize the parent's toString() method where applicable. 4. Class Executive: Create a class named Executive which is a child of Manager and has the following instance properties and public interface. Instance Properties: i. String office Location the office location of the executive (i.e., "suite 300, room 419"). b. Public Interface: i. Constructors: Two constructors need to be provided. Namely a default constructor and a workhorse constructor. The default constructor will initialize the instance properties to their default values (numbers to 0 and Strings to ""). Note, you must utilize the super() constructor call appropriately to set the parent's instance properties. ii. Getters and Setters for each instance property. iii. public boolean equals(Object o) - The method returns true if the two Executives have the same name, year of birth, salary, department, and officeLocation and false, otherwise. Do not forget to use the parent's equals() method when applicable. iv. public String toString() - The method returns a String representing the Executive object that includes the name, year of birth, and salary. The formatted string should follow this example: I am an executive and my office location is room 419. I am a manager of the Human Resource department. I am an employee and have a salary of $50,000.00. I am a person whose name is James Bond and was born in 1997.". Note that you should utilize the parent's to String method where applicable. a. Tester Class: In the main method of your Tester class, you must test the classes from both problems listed above. Because there are no validation checks necessary in this Lab, make sure to simply test your equals(), toString(), constructors, and speak() methods. Additional Notes: . Make sure you include JavaDoc comments for all methods and classes including parameter and return descriptions. Make sure that all classes are named correctly. There is no explicit validation checking needed for this Lab assignmentStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started