QuestionQuestion

Polymorphism/Abstraction
Objectives: The focus of this assignment is modifying and utilizing the inheritance hierarchy from the previous assignment. You will need to understand and implement the ideas of basic inheritance, polymorphism, and abstraction.

Program Description:
Building upon the examples shown in class, this project will be a basic record of employees for a company. Many options for changing the list as a whole and updating the individual elements will be provided by the project.
A total of six classes are required. The first four are the same from the previous assignment with potential minor changes.
Employee – An abstract class which the other employee types inherit from
HourlyEmployee – An employee whose pay is based upon an hourly wage and hours worked
SalaryEmployee – An employee whose pay is based upon a yearly salary
CommissionEmployee – An employee whose pay is based upon a commission rate and sales amount
EmployeeManager – A class that contains an array of Employees and provides utilities to manage the array and the Employees stored within
EmployeeDriver – Contains main method. Creates a single EmployeeManager as well as the menu system in order to give the user the ability to use it.

UML DIAGRAM FOR AND DISCUSSION FOR Employee
Employee {abstract}
- String firstName
- String lastName
- char middleInitial
- boolean fulltime
- char gender
- int employeeNum
<<constructor>> Employee (fn : String, ln : String, m : char, g : char, empNum : int, ft : boolean )
+ getEmployeeNumber() : int
+ setEmployeeNumber(empNum : int)
+ getFirstName() : String
+ getLastName() : String
+ setFirstName(fn: String)
+ setLastName(ln : String)
+ setMiddleI(m : char)
+ setGender(g : char)
+ equals(e2 : Object) : Boolean
+ toString() : String
+ calculateWeeklyPay() : double {abstract}
+ annualRaise() {abstract}
+ holidayBonus() : double {abstract}
+ resetWeek() {abstract}

Notes on Data Members
The employeeNum member must be between 10000 and 99999, inclusive. If an invalid value is passed, the Employee class should immediately ask for another number until an acceptable one is given. This should be handled in setEmployeeNumber.
If an invalid value for gender is given (not ‘M’ or ‘F’) it should default to ‘F’. This should be handled in setGender.
Notes on Methods equals() – Overrides Object equals(). Returns true if the employeeNum of the two instances are equal, false otherwise. toString() – Overrides Object toString(). Returns as String of the Employee in the following format:
12345
Doe, John M.
Gender: M
Status: Full Time
(Note that Status doesn’t say true or false, rather Full Time or Part Time) calculateWeeklyPay() – Abstract method to be implemented by subclass. Calculates pay for the week.
annualRaise() – Abstract method to be implemented by subclass. Gives Employee a raise. holidayBonus() – Abstract method to be implemented by subclass. Calculates bonus for Employee. resetWeek() – Abstract method to be implemented by subclass. Resets the weekly values for Employee. DISSCUSSION ON Employee SUBCLASSES
HourlyEmployee
HourlyEmployee extends Employee
- double wage
- double hoursWorked
<<constructor>> HourlyEmployee (fn : String, ln : String, m : char, g : char, empNum : int, ft : boolean, wage : double ) + increaseHours(hours : double)
+ toString() : String
+ calculateWeeklyPay() : double
+ annualRaise()
+ holidayBonus() : double
+ resetWeek()
Additional Data Members:
- double wage
- double hoursWorked

Methods
Constructor accepts all that an Employee requires as well as a double for wage, hoursWorked set at 0.0.
Override toString(), returns a String of the HourlyEmployee in the following format:
12345
Doe, John M.
Gender: M
Status: Full Time
Wage: 3.40
Hours Worked: 0.00
Abstract method implementation:
calculateWeeklyPay() – Return amount earned in the week using wage and hoursWorked, any hours worked over 40 give double pay annualRaise() – Wage is increased by 5% holidayBonus() – Return amount of 40 hours worked (40*wage) resetWeek() – Resets hours worked to 0
increaseHours() - This class also needs the ability to increase the hours worked. Requesting to increase by a negative value should give no change, and report an error to the user.

SalaryEmployee
SalaryEmployee extends Employee
- salary : double
<<constructor>> SalaryEmployee (fn : String, ln : String, m : char, g : char, empNum : int, ft : boolean, salary : double )
+ toString() : String
+ calculateWeeklyPay() : double
+ annualRaise()
+ holidayBonus() : double
+ resetWeek()
Additional Data Members - double salary

Methods
Constructor accepts all that an Employee requires as well as a double for salary.
Override toString(), returns a String of the SalaryEmployee in the following format:
12345
Doe, John M. Gender: M
Status: Full Time
Salary: 50000.00
Abstract method implementation: calculateWeeklyPay() – Return amount earned in the week by dividing salary by 52 annualRaise() – Salary is increased by 6% holidayBonus() – Return 3% of salary resetWeek() – No change
CommissionEmployee
CommissionEmployee extends Employee
- sales : double
- rate : double
<<constructor>> CommissionEmployee (fn : String, ln : String, m : char, g : char, empNum : int, ft : boolean, rate : double ) + increaseSales(sales : double)
+ toString() : String
+ calculateWeeklyPay() : double
+ annualRaise()
+ holidayBonus() : double
+ resetWeek()

Additional Data Members
- double sales
- double rate (stored as a percent, eg. 3.5% would be stored as 3.5)

Methods
Constructor accepts all that an Employee requires as well as a double for rate, sales set to 0.0.
Override toString(), returns a String of the CommissionEmployee in the following format:
12345
Doe, John M.
Gender: M
Status: Full Time
Rate: 3.50
Sales: 0.00
Abstract method implementation: calculateWeeklyPay() – Return rate percentage of sales annualRaise() – Rate percentage increased .2% example, if rate was 2.5, it becomes 2.7 holidayBonus() – No bonus resetWeek() – Reset sales to 0.0
Additional functionality:
increaseSales() - This class also needs the ability to increase the sales. Requesting to increase by a negative value should give no change and report the error.

EmployeeManager
EmployeeManager
- employees : Employee[]
- employeeMax : final int = 100
-currentEmployees : int
<<constructor>> EmployeeManager
+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) + removeEmployee( index : int)
+ listAll()
+ listHourly()
+ listSalary()
+ listCommision()
+ resetWeek()
+ calculatePayout() : double
+ removeRedundancies()
+ getIndex( empNum : int ) : int
+ sortNumber()
+ sortName()
+ annualRaises()
+ holidayBonuses() : double
+ increaseHours( index : int, amount : double)
+ increaseSales( index : int, amount : double)

Data Members
- Employee[] employees – Collection of Employee objects
- final int employeeMax = 100 – Maximum number of Employees allowed - int currentEmployees – Current number of Employees in collection Methods
public EmployeeManager()
Constructor, creates the Employee array, sets currentEmployees to 0.
public void addEmployee(int, String, String, char, char, int, Boolean, double)
Takes an int representing the type of Employee to be added (1 – Hourly, 2 – Salary, 3 – Commision) as well as the required data to create that Employee.
public void removeEmployee(int)
Removes an Employee located at the given index from the Employee array.
public void listAll()
Lists all the current Employees. Outputs there are none if there are none.
public void listHourly()
Lists all the current HourlyEmployees. Outputs there are none if there are none.
public void listSalary()
Lists all the current SalaryEmployees. Outputs there are none if there are none.
public void listCommission()
Lists all the current CommissionEmployees. Outputs there are none if there are none.
public void resetWeek()
Resets the week for all Employees.
public double calculatePayout()
Returns the total weekly payout for all Employees.
public void removeRedundancies()
Removes any duplicate Employees, keeping the Employee that appeared earlier in the array.
public int getIndex(int)
Given an Employee Number, returns the index of that Employee in the array, if the Employee doesn’t exist retuns -1.
public void sortNumber()
Sorts the Employees by Employee Number.
public void sortName()
Sorts the Employees by Name. Primarily by last name, secondary by first name. Don’t worry about middle initial.
public void annualRaises()
Applies annual raise to all current Eexmployees.
public double holidayBonuses()
Outputs and returns the total holiday bonus of all Employees.
public void increaseHours(int, double)
Increase the hours worked of the Employee at the given index by the given double amount.
public void increaseSales(int, double)
Increase the sales of the Employee at the given index by the given double amount.

Some notes:
• To begin with the EmployeeManager has no Employees
• There should never be two Employees with the same number, the newer Employee would be removed
• Sorting will be required, though we haven’t discussed sorting in this class, recall the bubble sort from CIST
1400. Also, investigate String’s compareTo() method for alphabetical sorting
• Think about creating methods that perform in common behaviors for all Employees in the array
EmployeeDriver
The EmployeeDriver will create a single object of EmployeeManager as well as any other variables you deem necessary. This is the interface to using the EmployeeManager through a Menu system. The Main Menu should look like this: Main Menu
No Employees.
1. Employee Submenu
2. Add Employee
3. Remove Employee
4. Sort Employees
5. Calculate Weekly Payout
6. Calculate Bonus
7. Annual Raises
8. Reset Week
9. Quit

Enter Choice:
Where “No Employees” is listed, ALL of the current Employees must be listed if there are any, “No Employees” if there are none. Some of the options lead to a submenu which will allow the user to return back to the previous menu. Whenever the main menu is displayed the employees will be listed as they were added or if they were sorted, in the sorted order. This is provided for you. You must use the version provided and cannot make any changes. Menu Option Details
1. Employee Submenu
This leads the user to a submenu where they can choose a specific type of Employee. Once one is selected ONLY THE EMPLOYEES OF THAT TYPE are listed. Employees of type HourlyEmployee and CommissionEmployee are offered the option to add hours/sales as well as return to the previous menu. SalaryEmployees can only return to the previous menu. Main Menu
12345
Parker, Peter B.
Gender: M
Status: Full Time
Wage: 8.50
Hours Worked: 0.00
54321
Spector, Marc J. Gender: M
Status: Full Time
Wage: 9.80
Hours Worked: 0.00
98765
Pryde, Kitty T.
Gender: F
Status: Part Time
Salary: 25000.00
45678
Curry, Arthur J.
Gender: M
Status: Full Time Salary: 65000.00
87654
Kent, Clark J.
Gender: M
Status: Part Time
Rate: 3.40
Sales: 0.00
1. Employee Submenu
2. Add Employee
3. Remove Employee
4. Sort Employees
5. Calculate Weekly Payout
6. Calculate Bonus
7. Annual Raises
8. Reset Week9. Quit
Enter Choice: 1
1. Hourly Employees
2. Salary Employees
3. Commission Employees
4. Back
Enter Choice: 1
12345
Parker, Peter B.
Gender: M
Status: Full Time
Wage: 8.50
Hours Worked: 0.00
54321
Spector, Marc J.
Gender: M
Status: Full Time
Wage: 9.80
Hours Worked: 0.00
1. Add Hours
2. Back
Enter Choice: 2
1. Hourly Employees
2. Salary Employees
3. Commission Employees
4. Back
Enter Choice:
2. Add Employee
Gives a similar submenu, asking which type of Employee to add, prompting for the appropriate information. Returns to main menu after added.
3. Remove Employee
Asks for an employee number and removes the Employee from the array if it exists. If not states that no such Employee exists and none have been removed. Returns to main menu after.
4. Sort Employee
Offers the option to sort all the Employees by employee number or name (alphabetical Last / First). Listing Employees after this will cause them to be output in the proper order. Adding Employees after a sort does not require the Employee to be placed in the sorted order, will still be added to the end.
5. Calculate Payout
Reports how much the company will have to pay out given the Employee’s current sales, hours worked, and salaries
6. Calculate Bonus
Lists all Employees as well as their specific holiday bonus amount after their information. Also reports the total holiday bonus payout.
Enter Choice: 6
12345
Parker, Peter B. Gender: M
Status: Full Time
Wage: 7.80
Hours Worked: 0.00
Bonus Amount: 312.00
54321
Wayne, Bruce J. Gender: M
Status: Full Time
Wage: 9.50
Hours Worked: 0.00
Bonus Amount: 380.00
98765
Richards, Reed L. Gender: M
Status: Part Time
Salary: 20000.00
Bonus Amount: 600.00
65432
Prince, Diana R.
Gender: F
Status: Full Time
Rate: 55000.00
Sales: 0.00
Bonus Amount: 0.00
Total holiday bonus payout is 1292.00
7. Annual Raises
Applies the annual raises for all Employees and notifies that annual raises have been applied.
8. Reset Week
Resets the weekly values for all Employees.
9. Quit
Exits the program giving an exiting message.  

Other Notes:
• Make sure monetary values are formatted correctly
• Monetary amounts are forced to be 2 decimal places o Keep this in mind when applying raises, for example if a wage is 9.50, increasing by 5% gives 9.975, this should be rounded DOWN to 9.97
• Make proper use of super
• When down casting to program in the specific, do not forget to make sure the type you are casting to is the type of the object being referenced

Summary of Files
You will need to six (6) files for this assignment.
• Employee.java
• HourlyEmployee.java
• SalaryEmployee.java
• CommissionEmployee.java
• EmployeeManager.java
• EmployeeDriver.java (provided)


Required Elements:
• All outputs to the user must include identifying text.
• The user should be prompted for all inputs.
• Your program file must meet the programming standards defined for this course and contain the appropriate header defined for this course.
• Document your methods

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;
import employeeType.subTypes.HourlyEmployee;
import employeeType.subTypes.SalaryEmployee;
import employeeType.subTypes.CommissionEmployee;

public class EmployeeDriver
{

/* public static int menu(String... options)
{
int choice;
do
{
for(int line = 0; line < options.length; line++)
System.out.printf("%d. %s\n", line+1,options[line]);

System.out.println("\nEnter Choice: ");
choice = in.nextInt();
}while(choice > 0 && choice <= options.length);

return choice;
}*/

public static void main(String args[])
{
int mainInput;//Input for main menu
int subInput1;//Input for submenu
int subInput2;//Input for sub-submenu
int en; //Inputting an employee number
int index;
double amount;
EmployeeManager em = new EmployeeManager(); //The EmployeManager object
Scanner in = new Scanner(System.in);

//Main control loop, keep coming back to the
//Main menu after each selection is finished
do
{...
$20.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats