Programming C#

Employee Hierarchy

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, interfaces or generic types 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:

I. 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 $50,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. bool 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 order.
  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 GetSupervisor: 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 employee.

II. HourlyEmployee: an hourly employee is an employee that earns an amount based on an hourly rate. The necessary methods for HourlyEmployee are:

  1. Constructor: (string firstName, string lastName, string number, double hourlyRate)
  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 GetHourlyRate(): returns the hourly rate of the employee
  7. void SetHourlyRate(double rate): sets the hourly rate of the employee
  8. double GetHoursWorked(): returns the number of hours worked by the employee in this pay period
  9. void SetHoursWorked(double hoursWorked): sets the hours worked by the employee in this pay period
  10. double GetBonus(): returns the bonus of the employee
  11. void SetBonus(double bonus): sets the bonus of the employee
  12. double GetAmountEarned(): returns the total amount earned by the employee (equals the hourly rate times the hours worked plus the bonus)
  13. void AdjustPay(double percentage): increases (or decreases) the hourly rate of the employee by the given percentage
  14. string ToString(): Overrides the method of Object. Returns a String representation which is in the format "number: last name, first name, Hourly Employee"
  15. bool Equals: Overrides the method of Object. Two employees are equal if both names and the number are equal.
  16. 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's 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 order.
  17. 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 earns the same amount as the parameter, and returns a positive value if this employee earns more than the parameter.
  18. void SetSupervisor: sets the supervisor for the employee. The supervisor must be one of the three supervisor types listed below.
  19. GetSupervisor(): returns the supervisor for the employee.

III. SalesEmployee: an sales employee is an employee that earns a small salary plus a commission on every sale made. The necessary methods for SalesEmployee are:

  1. Constructor: (String firstName, String lastName, String number, double salary, double commission)
  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 GetCommission(): returns the commission of the employee
  9. void GetCommission(double commission): sets the commission of the employee
  10. int GetNumSales(): returns the number of sales made by the employee in this pay period
  11. void SetNumSales(int numSales): sets the number of sales by the employee in this pay period
  12. double GetBonus(): returns the bonus of the employee
  13. void SetBonus(double bonus): sets the bonus of the employee
  14. double GetAmountEarned(): returns the total amount earned by the employee (equals the salary plus the commission times the number of sales plus the bonus)
  15. void AdjustPay(double percentage): increases (or decreases) the commission of the employee by the given percentage
  16. string ToString(): Overrides the method of Object. Returns a String representation which is in the format "number: last name, first name, Sales Employee"
  17. bool Equals: Overrides the method of Object. Two employees are equal if both names and the number are equal.
  18. 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 order.
  19. 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 employee earns the same amount as the parameter, and returns a positive value if this employee earns more than the parameter.
  20. void SetSupervisor: sets the supervisor for the employee. The supervisor must be one of the three supervisor types listed below.
  21. GetSupervisor(): returns the supervisor for the employee.

IV. SalariedSupervisor: a salaried supervisor is a supervisor that earns a fixed salary. The necessary methods for SalariedSupervisor are:

  1. Constructor: (String firstName, String lastName, String number, double salary)
  2. string GetFirstName(): returns the first name of the supervisor
  3. string GetLastName(): returns the last name of the supervisor
  4. void SetName(string firstName, string lastName): sets the first and last names for the supervisor
  5. string GetNumber(): returns the supervisor number of the supervisor
  6. double GetSalary(): returns the salary of the supervisor
  7. void SetSalary(double salary): sets the salary of the supervisor
  8. double GetBonus(): returns the bonus of the supervisor
  9. void SetBonus(double bonus): sets the bonus of the supervisor
  10. double GetAmountEarned(): returns the total amount earned by the supervisor (equals the salary plus the bonus)
  11. void AdjustPay(double percentage): increases (or decreases) the salary of the supervisor by the given percentage (for example, an supervisor earning $50,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 Supervisor"
  13. bool Equals: Overrides the method of Object. Two supervisors (or a supervisor and an employee) are equal if both names and the number are equal.
  14. int CompareToByName: compares the name of this supervisor to the name of the parameter. Returns a negative value if this supervisor's name precedes the parameter's in alphabetical order (last name, then first name), returns 0 if the supervisor and the parameter have the same name, and returns a positive value if this supervisor's name comes after the paramter's name in alphabetical order.
  15. int CompareToByEarnings: compares the total amount earned by this supervisor to that of the parameter. Returns a negative value if this supervisor earns less, returns 0 if the supervisor earn the same amount as the parameter, and returns a positive value if this supervisor earns more than the parameter.
  16. void SetSupervisor: sets the supervisor for the supervisor. The supervisor must be one of the three supervisor types listed here.
  17. GetSupervisor(): returns the supervisor for the supervisor.

V. HourlySupervisor: an salaried supervisor is a an supervisor that earns an amount based on an hourly rate. The necessary methods for HourlySupervisor are:

  1. Constructor: (string firstName, string lastName, string number, double hourlyRate)
  2. string GetFirstName(): returns the first name of the supervisor
  3. string GetLastName(): returns the last name of the supervisor
  4. void SetName(string firstName, string lastName): sets the first and last names for the supervisor
  5. string GetNumber(): returns the supervisor number of the supervisor
  6. double GetHourlyRate(): returns the hourly rate of the supervisor
  7. void SetHourlyRate(double rate): sets the hourly rate of the supervisor
  8. double GetHoursWorked(): returns the number of hours worked by the supervisor in this pay period
  9. void SetHoursWorked(double hoursWorked): sets the hours worked by the supervisor in this pay period
  10. double GetBonus(): returns the bonus of the supervisor
  11. void SetBonus(double bonus): sets the bonus of the supervisor
  12. double GetAmountEarned(): returns the total amount earned by the supervisor (equals the hourly rate times the hours worked plus the bonus)
  13. void AdjustPay(double percentage): increases (or decreases) the hourly rate of the supervisor by the given percentage
  14. string ToString(): Overrides the method of Object. Returns a String representation which is in the format "number: last name, first name, Hourly Supervisor"
  15. bool Equals: Overrides the method of Object. Two supervisors (or a supervisor and an employee) are equal if both names and the number are equal.
  16. int CompareToByName: compares the name of this supervisor to the name of the parameter. Returns a negative value if this supervisor's name precedes the parameter's in alphabetical order (last name, then first name), returns 0 if the supervisor and the parameter have the same name, and returns a positive value if this supervisor's name comes after the paramter's name in alphabetical order.
  17. int CompareToByEarnings: compares the total amount earned by this supervisor to that of the parameter. Returns a negative value if this supervisor earns less, returns 0 if the supervisor earn the same amount as the parameter, and returns a positive value if this supervisor earns more than the parameter.
  18. void SetSupervisor: sets the supervisor for the supervisor. The supervisor must be one of the three supervisor types listed here.
  19. GetSupervisor(): returns the supervisor for the supervisor.

VI. SalesSupervisor: an sales supervisor is a an supervisor that earns a small salary plus a commission on every sale made. The necessary methods for SalesSupervisor are:

  1. Constructor: (string firstName, string lastName, string number, double salary, double commission)
  2. string GetFirstName(): returns the first name of the supervisor
  3. string GetLastName(): returns the last name of the supervisor
  4. void SetName(string firstName, string lastName): sets the first and last names for the supervisor
  5. string GetNumber(): returns the supervisor number of the supervisor
  6. double GetSalary(): returns the salary of the supervisor
  7. void SetSalary(double salary): sets the salary of the supervisor
  8. double GetCommission(): returns the commission of the supervisor
  9. void SetCommission(double commission): sets the commission of the supervisor
  10. int GetNumSales(): returns the number of sales made by the supervisor in this pay period
  11. void SetNumSales(int numSales): sets the number of sales by the supervisor in this pay period
  12. double GetBonus(): returns the bonus of the supervisor
  13. void SetBonus(double bonus): sets the bonus of the supervisor
  14. double GetAmountEarned(): returns the total amount earned by the supervisor (equals the salary plus the commission times the number of sales plus the bonus)
  15. void AdjustPay(double percentage): increases (or decreases) the commission of the supervisor by the given percentage
  16. string ToString(): Overrides the method of Object. Returns a String representation which is in the format "number: last name, first name, Sales Supervisor"
  17. boolean Equals: Overrides the method of Object. Two supervisors (or a supervisor and an employee) are equal if both names and the number are equal.
  18. int CompareToByName: compares the name of this supervisor to the name of the parameter. Returns a negative value if this supervisor's name precedes the parameter's in alphabetical order (last name, then first name), returns 0 if the supervisor and the parameter have the same name, and returns a positive value if this supervisor's name comes after the paramter's name in alphabetical order.
  19. int CompareToByEarnings: compares the total amount earned by this supervisor to that of the parameter. Returns a negative value if this supervisor earns less, returns 0 if the supervisor earn the same amount as the parameter, and returns a positive value if this supervisor earns more than the parameter.
  20. void SetSupervisor: sets the supervisor for the supervisor. The supervisor must be one of the three supervisor types listed here.
  21. GetSupervisor(): returns the supervisor for the supervisor.

VII. EmployeeDatabase: a list of all the employees and supervisors of the company as well as helpful methods. The type should have only one constructor that takes no input. The database will start with an empty list to store the employees and supervisors. The type should have the following features that you will need to turn into one or more methods of the same, or slightly modified, names, as appropriate:

  1. Add: the add method(s) lets you add an employee or a supervisor object to the database. The object added should be the parameter to the method.
  2. Remove(first name, last name, number) lets you remove an employee or a supervisor that matches the parameters first name, last name, and number. The object removed from the database should be returned by the method. A NoSuchEmployee exception should be thrown if no employee or supervisor matching the given name and number is in the database.
  3. Find(first name, last name, number) returns an employee or a supervisor object that matches the parameters first name, last name, and number. Throws a NoSuchEmployee exception if no employee or supervisor matching the parameter values exists in the database.
  4. GetPayrollAmount: returns the total amount that all employees and supervisors earned.
  5. GetMaximumEarned: returns the employee or the supervisor who has the largest earnings in the database (break ties arbitrarily). Returns null if there are no employees or supervisors in the database.
  6. GetMinimumEarned: returns the employee or the supervisor who has the least earnings in the database (break ties arbitrarily). Returns null if there are no employees or supervisors in the database.
  7. GetMaxSales: returns the employee or the supervisor who has the largest number of sales (break ties arbitrarily). Throws a NoSuchEmployee exception if there are no sales employees or sales supervisors in the database.
  8. GetMinSales: returns the employee or the supervisor who has the least number of sales (break ties arbitrarily). Throws a NoSuchEmployee exception if there are no sales employees or sales supervisors in the database.
  9. GetMaxHoursWorked: returns the employee or the supervisor who worked the most hours (break ties arbitrarily). Throws a NoSuchEmployee exception if there are no hourly employees or hourly supervisors in the database.
  10. GetMinHoursWorked: returns the employee or the supervisor who worked the fewest hours (break ties arbitrarily). Throws a NoSuchEmployee exception if there are no hourly employees or hourly supervisors in the database.
  11. GetSupervisees(supervisor): takes a supervisor object as input and returns an array that contains all the employee and supervisor objects that the parameter supervisor supervises. (The order of the objects in the array does not matter, but the length of the array should equal the total number of supervisees.)

Extra Credit:

Write a main method for the EmployeeDatabase class. The main method should create an empty database, and then the method should allow user input (using the Scanner class) to manipulate the database, and the results should be output using Console.WriteLine(). Here are some examples:

> add salary John Lee 5 40000
Added 5: Lee, John, Salary Employee, with salary $40000.0 to the database
> add salarysupervisor Mary Cohen 4S 60000
Added 4S: Cohen, Mary, Salary Supervisor with salary $60000.0 to the database
> find John Lee 5
Retrieved 5: Lee, John, Salary Employee.
> set bonus 400.0
Set bonus for 5: Lee, John, Salary Employee to $400.0
> get bonus
Bonus for 5: Lee, John, Salary Employee is $400.0
> set supervisor Mary Cohen 4S
Set supervisor for 5: Lee, John, Salary Employee to 4S: Cohen, Mary, Salary Supervisor 
> find Mary Cohen 4S
Retrieved 4S: Cohen, Mary, Salary Supervisor.
> get supervisees
The list of supervisees for 4S: Cohen, Mary, Salary Supervisor is:
  5: Lee, John, Salary Employee
> find Thomas Smith 34
> No such employee