How to design the hierarchy and how to write the EmployeeDatabase Class?(My thou
ID: 3741238 • Letter: H
Question
How to design the hierarchy and how to write the EmployeeDatabase Class?(My thought is to create abstract class Employee and Supervisor. Is this correct? If it is correct, should both class Employee and class Supervisor extend class EmployeeDatabase?)
IV. Java Programming (60% of your grade) For this project you will implement a simple employee database. Note that we did a small employee hierarchy as a lecture example. You can use that as a guide, but the specifications below are different and so you should not use exactly the lecture example Design Rules: Your project must contain the following seven types and each type must contain the listed methods. The project may use any combination of classes, abstract classes, or interfaces that you feel is appropriate. The project may add additional types to the ones listed. The classes/types may contain additional methods to the ones listed if you feel they are needed. You may use any combination of inheritance, method overriding, and method overloading to achieve the needed behavior. Part of the coding grade will be the quality of the hierarchy you create Hint (repeated from above): Spend a lot of time designing your hierarchy before you code. A well designed hierarchy will reduce the amount of code you have to write The seven types your project must contain represent different kinds of employees and supervisors as well as the database of employees and supervisors. The types are 1. SalariedEmployee: a salaried employee is an employee that earns a fixed salary. The necessary methods for SalariedEmployee are 1. constructor: (String firstName, String lastName, String number, double salary) 2. string getFirstName(): returns the first name of the employee 3. string getlastName (): returns the last name of the employee 4. void setName (String firstName, String lastName): sets the first and last names for the employee 5. String getNumber(: returns the employee number of the employee 6. double getsalary(): returns the salary of the employee 7. void setsalary (double salary): sets the salary of the employee 8. double getBonus (): returns the bonus of the employee 9. void setBonus (double bonus): sets the bonus of the employee 10. double getAmountEarned (): returns the total amount earned by the employee (equals the salary plus the bonus) 11. void adjustPay (double percentage): increases (or decreases) the salary of the employee by the given percentage (for example, an employee earning S50,000 with a 10% adjustment would now have a salary of $55,000) 12. string toString(: Overrides the method of object. Returns a String representation which is in the format "number: last name, first name, Salaried Employee" 13. boolean equals: Overrides the method of object. Two employees are equal if both names and the number are equal. 14. int compareToByName: compares the name of this employee to the name of the parameter. Returns a negative value if this employee's name precedes the parameter's in alphabetical order (last name, then first name), returns 0 if this employee has the same name as the parameter, and returns a positive value if this employee's name comes after the paramter's name in alphabetical ordeir 15. int compareToByEarnings: compares the total amount earned by this employee to that of the parameter. Returns a negative value if this employee earns less, returns 0 if this employees earn the same amount as the parameter, and returns a positive value if this employee earns more than the parameter. 16. void setSupervisor: sets the supervisor for the employee. The supervisor must be one of the three supervisor types listed below 17. getsupervisor(): returns the supervisor for the employeeExplanation / Answer
My thought is to create abstract class Employee and Supervisor. Is this correct??
I beg to differ as supervisor is also a kind of employee, define abstract class Employee which will be extended by Supervisor. After that classes salaried, hourly & sales can extend these classes to provide complete definition.
Should both class Employee and class Supervisor extend class EmployeeDatabase???
No it should not extend EmployeeDatabase as employees are not kind of database, rather as mentioned in the EmployeeDatabase description, you will have to create required arrays of these two classes with appropriate capacity to accommodate as many employee as required.
So they do not extend EmployeeDatabase but they are part of database class itself which in real world would resemble similar to a company's employee database, in which a database contains all the details of the employees.
The reason why we are including array of supervisors rather than just including for Employee is that in general databases maintain separate tables, one for all the employees and another table of supervisors(generally contains supervisor & repartees mapping).
So the hierarchy would be:
1. Define abstract class Employee
2. Define class Supervisor which implements Employee
3. Define class EmployeeDatabase which will also contain array of ojbects of Employee & Supervisor
4. Define salariedEmployee/hourlyEmployee/salesEmployee which extend Employee
5. Define salariedSupervisor which will extend Supervisor & salariedEmployee. Similarly hourlySupervisor extends Supervisor & hourlyEmployee and salesSupervisor extends Supervisor & salesEmployee
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.