SlideShare a Scribd company logo
package employeeType.employee;
public abstract class Employee {
private String firstName;
private String lastName;
private char middleInitial;
private boolean fulltime;
private char gender;
private int employeeNum;
public Employee(String firstName, String lastName, char middleInitial,
char gender, int employeeNum, boolean fulltime) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.middleInitial = middleInitial;
this.fulltime = fulltime;
this.gender = gender;
this.employeeNum = employeeNum;
}
public int getEmployeeNumber() {
return this.employeeNum;
}
public void setEmployeeNumber(int empNum) {
this.employeeNum = empNum;
}
public String getFirstName() {
return firstName;
}
String getLastName() {
return lastName;
}
char getMiddleInitial() {
return middleInitial;
}
public char getGender() {
return gender;
}
public void setFirstName(String fn) {
this.firstName = fn;
}
public void setLastName(String ln) {
this.lastName = ln;
}
public void setMiddleI(char m) {
this.middleInitial = m;
}
public void setGender(char g) {
this.gender = g;
}
public boolean equals(Object obj) {
// TODO Auto-generated method stub
if (obj instanceof Employee) {
Employee employee = (Employee) obj;
if (employee.getEmployeeNumber() == this.getEmployeeNumber())
return true;
else
return false;
} else
return false;
}
public String toString() {
// TODO Auto-generated method stub
return getEmployeeNumber() + " " + getFirstName() + " "
+ getLastName() + " Gender:" + getGender() + " Status:"
+ ((fulltime) ? "Full Time" : "Part Time");
}
public abstract double calculateWeeklyPay();
public abstract void annualRaise();
public abstract double holidayBonus();
public abstract void resetWeek();
}
package employeeType.subTypes;
import java.text.DecimalFormat;
import employeeType.employee.Employee;
public class HourlyEmployee extends Employee {
private double wage;
private double hoursWorked;
public HourlyEmployee(String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double wage) {
super(firstName, lastName, middleInitial, gender, employeeNum, fulltime);
// TODO Auto-generated constructor stub
this.wage = wage;
this.hoursWorked = 0.0d;
}
public void increaseHours(double hours) {
if (hours > 0)
this.hoursWorked += hours;
else
System.out.println("Error! Invalid hours");
}
public String toString() {
// TODO Auto-generated method stub
return super.toString() + " Wage: " + wage + " Hours Worked: "
+ hoursWorked;
}
public double calculateWeeklyPay() {
double pay;
if (hoursWorked > 40) {
pay = (40 * wage) + (2 * (hoursWorked - 40) * wage);
} else {
pay = wage * hoursWorked;
}
return pay;
}
public void annualRaise() {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
wage = Double.valueOf(decimalFormat.format(wage * 0.05));
}
public double holidayBonus() {
return 40 * wage;
}
public void resetWeek() {
this.hoursWorked = 0;
}
}
package employeeType.subTypes;
import java.text.DecimalFormat;
import employeeType.employee.Employee;
public class SalaryEmployee extends Employee {
double salary;
public SalaryEmployee(String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double s) {
super(firstName, lastName, middleInitial, gender, employeeNum, fulltime);
// TODO Auto-generated constructor stub
this.salary = s;
}
public String toString() {
// TODO Auto-generated method stub
return super.toString() + " Salary:" + salary;
}
public double calculateWeeklyPay() {
return salary / 52.00d;
}
public void annualRaise() {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
salary = Double.valueOf(decimalFormat.format(salary * 0.06));
}
public double holidayBonus() {
return salary * 0.03;
}
public void resetWeek() {
}
}
package employeeType.subTypes;
import employeeType.employee.Employee;
public class CommissionEmployee extends Employee {
double sales;
double rate;
public CommissionEmployee(String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double r) {
super(firstName, lastName, middleInitial, gender, employeeNum, fulltime);
// TODO Auto-generated constructor stub
this.rate = r;
this.sales = 0.0d;
}
public String toString() {
// TODO Auto-generated method stub
return super.toString() + " Rate: " + rate + " Sales: " + sales;
}
public void increaseSales(double sales) {
if (sales > 0)
this.sales += sales;
else
System.out.println("Error! Not valid sales");
}
public double calculateWeeklyPay() {
return sales * rate / 100;
}
public void annualRaise() {
this.rate += 0.02;
}
public double holidayBonus() {
return 0.00d;
}
public void resetWeek() {
this.sales = 0.0d;
}
}
import employeeType.employee.Employee;
import employeeType.subTypes.CommissionEmployee;
import employeeType.subTypes.HourlyEmployee;
import employeeType.subTypes.SalaryEmployee;
public class EmployeeManager {
Employee[] employees;
final int employeeMax = 10;
int currentEmployees;
public EmployeeManager() {
// TODO Auto-generated constructor stub
employees = new Employee[employeeMax];
this.currentEmployees = 0;
}
/*
* Takes an int representing the type of Employee to be added (1 – Hourly, 2
* – Salary, 3 – Commission) as well as the required data to create that
* Employee. If one of these values is not passed output the line, “Invalid
* Employee Type, None Added”, and exit the method. If an Employee with the
* given Employee Number already exists do not add the Employee and output
* the line, “Duplicate Not Added”, and exit the method. If the array is at
* maximum capacity do not add the new Employee, and output the line,
* "Cannot add more Employees".
*/
public void addEmployee(int input, String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double wage) {
switch (input) {
case 1: {
HourlyEmployee employee = new HourlyEmployee(firstName, lastName,
middleInitial, gender, employeeNum, fulltime, wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println("Duplicate Not Added");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println("Cannot add more Employees");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
case 2: {
SalaryEmployee employee = new SalaryEmployee(firstName, lastName,
middleInitial, gender, employeeNum, fulltime, wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println("Duplicate Not Added");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println("Cannot add more Employees");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
case 3: {
CommissionEmployee employee = new CommissionEmployee(firstName,
lastName, middleInitial, gender, employeeNum, fulltime,
wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println("Duplicate Not Added");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println("Cannot add more Employees");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
default:
System.out.println("Invalid Employee Type, None Added");
break;
}
}
// Removes an Employee located at the given index from the Employee array.
public void removeEmployee(int index) {
employees[index] = null;
}
// Lists all the current Employees. Outputs there are none if there are
// none.
public void listAll() {
if (currentEmployees == 0)
System.out.println("none");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null)
System.out.println(employees[i].toString());
}
}
}
// Lists all the current HourlyEmployees. Outputs there are none if there
// are none.
public void listHourly() {
if (currentEmployees == 0)
System.out.println("none");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof HourlyEmployee)
System.out.println(employees[i].toString());
}
}
}
}
// Lists all the current SalaryEmployees. Outputs there are none if there
// are none.
public void listSalary() {
if (currentEmployees == 0)
System.out.println("none");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof SalaryEmployee)
System.out.println(employees[i].toString());
}
}
}
}
// Lists all the current CommissionEmployees. Outputs there are none if
// there are none.
public void listCommission() {
if (currentEmployees == 0)
System.out.println("none");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof CommissionEmployee)
System.out.println(employees[i].toString());
}
}
}
}
public void resetWeek() {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
employees[i].resetWeek();
}
}
}
public double calculatePayout() {
double payOut = 0;
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
payOut += employees[i].calculateWeeklyPay();
}
}
return payOut;
}
public int getIndex(int employeeNum) {
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
return i;
}
}
return -1;
}
public void annualRaises() {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
employees[i].annualRaise();
}
}
}
public double holidayBonuses() {
double holiBonus = 0;
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
holiBonus += employees[i].holidayBonus();
}
}
return holiBonus;
}
// Increase the hours worked of the Employee at the given index by the given
// double amount.
public void increaseHours(int index, double amount) {
if (employees[index] != null
&& employees[index] instanceof HourlyEmployee) {
HourlyEmployee employee = (HourlyEmployee) employees[index];
employee.increaseHours(amount);
}
}
// Increase the sales of the Employee at the given index by the given double
// amount.
public void increaseSales(int index, double amount) {
if (employees[index] != null
&& employees[index] instanceof CommissionEmployee) {
CommissionEmployee employee = (CommissionEmployee) employees[index];
employee.increaseSales(amount);
}
}
}
import java.util.Scanner;
public class EmployeeDriver {
static Scanner in = new Scanner(System.in);
public static int menu(String... options) {
int choice;
for (int line = 0; line < options.length; line++)
System.out.printf("%d. %s ", line + 1, options[line]);
do {
System.out.print("Enter 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
// Main control loop, keep coming back to the
// Main menu after each selection is finished
do {
// This is the main menu. Displays menu
// and asks for a choice, validaties that
// what is entered is a valid choice
System.out.println("  Main Menu ");
em.listAll();
mainInput = menu("Employee Submenu", "Add Employee",
"Remove Employee", "Calculate Weekly Payout",
"Calculate Bonus", "Annual Raises", "Reset Week", "Quit");
// Perform the correct action based upon Main menu input
switch (mainInput) {
// Employee Submenu
case 1:
do {
subInput1 = menu("Hourly Employees", "Salary Employee",
"Comission Employees", "Back");
switch (subInput1) {
case 1:
em.listHourly();
do {
subInput2 = menu("Add Hours", "Back");
if (subInput2 == 1) {
System.out.println("Employee Number: ");
en = in.nextInt();
index = em.getIndex(en);
if (index != -1) {
System.out.print("Enter Hours: ");
amount = in.nextDouble();
em.increaseHours(index, amount);
} else {
System.out.println("Employee not found!");
}
}
} while (subInput2 != 2);
break;
case 2:
em.listSalary();
subInput2 = menu("Back");
break;
case 3:
em.listCommission();
do {
subInput2 = menu("Add Sales", "Back");
if (subInput2 == 1) {
System.out.println("Employee Number: ");
en = in.nextInt();
index = em.getIndex(en);
if (index != -1) {
System.out.print("Enter Sales: ");
amount = in.nextDouble();
em.increaseSales(index, amount);
} else {
System.out.println("Employee not found!");
}
}
} while (subInput2 != 2);
break;
}
} while (subInput1 != 4);
break;
// Add Employee
case 2:
String fn,
ln;
char mi,
g,
f;
boolean ft = true;
subInput1 = menu("Hourly", "Salary", "Commission");
System.out.print("Enter Last Name: ");
ln = in.next();
System.out.print("Enter First Name: ");
fn = in.next();
System.out.print("Enter Middle Initial: ");
mi = in.next().charAt(0);
System.out.print("Enter Gender: ");
g = in.next().charAt(0);
System.out.print("Enter Employee Number: ");
en = in.nextInt();
System.out.print("Full Time? (y/n): ");
f = in.next().charAt(0);
if (f == 'n' || f == 'N') {
ft = false;
}
if (subInput1 == 1) {
System.out.print("Enter wage: ");
} else if (subInput1 == 2) {
System.out.print("Enter salary: ");
} else {
System.out.print("Enter rate: ");
}
amount = in.nextDouble();
em.addEmployee(subInput1, fn, ln, mi, g, en, ft, amount);
break;
// Remove Employee
case 3:
System.out.print("Enter Employee Number to Remove: ");
en = in.nextInt();
index = em.getIndex(en);
em.removeEmployee(index);
break;
// Calculate Weekly Payout
case 4:
System.out.printf("Total weekly payout is %.2f ",
em.calculatePayout());
break;
// Calculate Bonus
case 5:
amount = em.holidayBonuses();
System.out.printf("Total holiday bonus payout is %.2f ",
amount);
break;
// Apply Annual Raises
case 6:
em.annualRaises();
System.out.println("Annual Raises applied.");
break;
// Reset the weeks values
case 7:
em.resetWeek();
System.out.println("Weekly values reset.");
break;
// Exit
case 8:
System.out
.println(" Thank you for using the Employee Manager! ");
}
} while (mainInput != 8);
}
}
Solution
package employeeType.employee;
public abstract class Employee {
private String firstName;
private String lastName;
private char middleInitial;
private boolean fulltime;
private char gender;
private int employeeNum;
public Employee(String firstName, String lastName, char middleInitial,
char gender, int employeeNum, boolean fulltime) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.middleInitial = middleInitial;
this.fulltime = fulltime;
this.gender = gender;
this.employeeNum = employeeNum;
}
public int getEmployeeNumber() {
return this.employeeNum;
}
public void setEmployeeNumber(int empNum) {
this.employeeNum = empNum;
}
public String getFirstName() {
return firstName;
}
String getLastName() {
return lastName;
}
char getMiddleInitial() {
return middleInitial;
}
public char getGender() {
return gender;
}
public void setFirstName(String fn) {
this.firstName = fn;
}
public void setLastName(String ln) {
this.lastName = ln;
}
public void setMiddleI(char m) {
this.middleInitial = m;
}
public void setGender(char g) {
this.gender = g;
}
public boolean equals(Object obj) {
// TODO Auto-generated method stub
if (obj instanceof Employee) {
Employee employee = (Employee) obj;
if (employee.getEmployeeNumber() == this.getEmployeeNumber())
return true;
else
return false;
} else
return false;
}
public String toString() {
// TODO Auto-generated method stub
return getEmployeeNumber() + " " + getFirstName() + " "
+ getLastName() + " Gender:" + getGender() + " Status:"
+ ((fulltime) ? "Full Time" : "Part Time");
}
public abstract double calculateWeeklyPay();
public abstract void annualRaise();
public abstract double holidayBonus();
public abstract void resetWeek();
}
package employeeType.subTypes;
import java.text.DecimalFormat;
import employeeType.employee.Employee;
public class HourlyEmployee extends Employee {
private double wage;
private double hoursWorked;
public HourlyEmployee(String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double wage) {
super(firstName, lastName, middleInitial, gender, employeeNum, fulltime);
// TODO Auto-generated constructor stub
this.wage = wage;
this.hoursWorked = 0.0d;
}
public void increaseHours(double hours) {
if (hours > 0)
this.hoursWorked += hours;
else
System.out.println("Error! Invalid hours");
}
public String toString() {
// TODO Auto-generated method stub
return super.toString() + " Wage: " + wage + " Hours Worked: "
+ hoursWorked;
}
public double calculateWeeklyPay() {
double pay;
if (hoursWorked > 40) {
pay = (40 * wage) + (2 * (hoursWorked - 40) * wage);
} else {
pay = wage * hoursWorked;
}
return pay;
}
public void annualRaise() {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
wage = Double.valueOf(decimalFormat.format(wage * 0.05));
}
public double holidayBonus() {
return 40 * wage;
}
public void resetWeek() {
this.hoursWorked = 0;
}
}
package employeeType.subTypes;
import java.text.DecimalFormat;
import employeeType.employee.Employee;
public class SalaryEmployee extends Employee {
double salary;
public SalaryEmployee(String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double s) {
super(firstName, lastName, middleInitial, gender, employeeNum, fulltime);
// TODO Auto-generated constructor stub
this.salary = s;
}
public String toString() {
// TODO Auto-generated method stub
return super.toString() + " Salary:" + salary;
}
public double calculateWeeklyPay() {
return salary / 52.00d;
}
public void annualRaise() {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
salary = Double.valueOf(decimalFormat.format(salary * 0.06));
}
public double holidayBonus() {
return salary * 0.03;
}
public void resetWeek() {
}
}
package employeeType.subTypes;
import employeeType.employee.Employee;
public class CommissionEmployee extends Employee {
double sales;
double rate;
public CommissionEmployee(String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double r) {
super(firstName, lastName, middleInitial, gender, employeeNum, fulltime);
// TODO Auto-generated constructor stub
this.rate = r;
this.sales = 0.0d;
}
public String toString() {
// TODO Auto-generated method stub
return super.toString() + " Rate: " + rate + " Sales: " + sales;
}
public void increaseSales(double sales) {
if (sales > 0)
this.sales += sales;
else
System.out.println("Error! Not valid sales");
}
public double calculateWeeklyPay() {
return sales * rate / 100;
}
public void annualRaise() {
this.rate += 0.02;
}
public double holidayBonus() {
return 0.00d;
}
public void resetWeek() {
this.sales = 0.0d;
}
}
import employeeType.employee.Employee;
import employeeType.subTypes.CommissionEmployee;
import employeeType.subTypes.HourlyEmployee;
import employeeType.subTypes.SalaryEmployee;
public class EmployeeManager {
Employee[] employees;
final int employeeMax = 10;
int currentEmployees;
public EmployeeManager() {
// TODO Auto-generated constructor stub
employees = new Employee[employeeMax];
this.currentEmployees = 0;
}
/*
* Takes an int representing the type of Employee to be added (1 – Hourly, 2
* – Salary, 3 – Commission) as well as the required data to create that
* Employee. If one of these values is not passed output the line, “Invalid
* Employee Type, None Added”, and exit the method. If an Employee with the
* given Employee Number already exists do not add the Employee and output
* the line, “Duplicate Not Added”, and exit the method. If the array is at
* maximum capacity do not add the new Employee, and output the line,
* "Cannot add more Employees".
*/
public void addEmployee(int input, String firstName, String lastName,
char middleInitial, char gender, int employeeNum, boolean fulltime,
double wage) {
switch (input) {
case 1: {
HourlyEmployee employee = new HourlyEmployee(firstName, lastName,
middleInitial, gender, employeeNum, fulltime, wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println("Duplicate Not Added");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println("Cannot add more Employees");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
case 2: {
SalaryEmployee employee = new SalaryEmployee(firstName, lastName,
middleInitial, gender, employeeNum, fulltime, wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println("Duplicate Not Added");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println("Cannot add more Employees");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
case 3: {
CommissionEmployee employee = new CommissionEmployee(firstName,
lastName, middleInitial, gender, employeeNum, fulltime,
wage);
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
System.out.println("Duplicate Not Added");
return;
}
}
if (currentEmployees == employeeMax) {
System.out.println("Cannot add more Employees");
return;
}
employees[currentEmployees] = employee;
currentEmployees++;
break;
}
default:
System.out.println("Invalid Employee Type, None Added");
break;
}
}
// Removes an Employee located at the given index from the Employee array.
public void removeEmployee(int index) {
employees[index] = null;
}
// Lists all the current Employees. Outputs there are none if there are
// none.
public void listAll() {
if (currentEmployees == 0)
System.out.println("none");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null)
System.out.println(employees[i].toString());
}
}
}
// Lists all the current HourlyEmployees. Outputs there are none if there
// are none.
public void listHourly() {
if (currentEmployees == 0)
System.out.println("none");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof HourlyEmployee)
System.out.println(employees[i].toString());
}
}
}
}
// Lists all the current SalaryEmployees. Outputs there are none if there
// are none.
public void listSalary() {
if (currentEmployees == 0)
System.out.println("none");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof SalaryEmployee)
System.out.println(employees[i].toString());
}
}
}
}
// Lists all the current CommissionEmployees. Outputs there are none if
// there are none.
public void listCommission() {
if (currentEmployees == 0)
System.out.println("none");
else {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
if (employees[i] instanceof CommissionEmployee)
System.out.println(employees[i].toString());
}
}
}
}
public void resetWeek() {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
employees[i].resetWeek();
}
}
}
public double calculatePayout() {
double payOut = 0;
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
payOut += employees[i].calculateWeeklyPay();
}
}
return payOut;
}
public int getIndex(int employeeNum) {
for (int i = 0; i < employees.length; i++) {
if (employees[i].getEmployeeNumber() == employeeNum) {
return i;
}
}
return -1;
}
public void annualRaises() {
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
employees[i].annualRaise();
}
}
}
public double holidayBonuses() {
double holiBonus = 0;
for (int i = 0; i < currentEmployees; i++) {
if (employees[i] != null) {
holiBonus += employees[i].holidayBonus();
}
}
return holiBonus;
}
// Increase the hours worked of the Employee at the given index by the given
// double amount.
public void increaseHours(int index, double amount) {
if (employees[index] != null
&& employees[index] instanceof HourlyEmployee) {
HourlyEmployee employee = (HourlyEmployee) employees[index];
employee.increaseHours(amount);
}
}
// Increase the sales of the Employee at the given index by the given double
// amount.
public void increaseSales(int index, double amount) {
if (employees[index] != null
&& employees[index] instanceof CommissionEmployee) {
CommissionEmployee employee = (CommissionEmployee) employees[index];
employee.increaseSales(amount);
}
}
}
import java.util.Scanner;
public class EmployeeDriver {
static Scanner in = new Scanner(System.in);
public static int menu(String... options) {
int choice;
for (int line = 0; line < options.length; line++)
System.out.printf("%d. %s ", line + 1, options[line]);
do {
System.out.print("Enter 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
// Main control loop, keep coming back to the
// Main menu after each selection is finished
do {
// This is the main menu. Displays menu
// and asks for a choice, validaties that
// what is entered is a valid choice
System.out.println("  Main Menu ");
em.listAll();
mainInput = menu("Employee Submenu", "Add Employee",
"Remove Employee", "Calculate Weekly Payout",
"Calculate Bonus", "Annual Raises", "Reset Week", "Quit");
// Perform the correct action based upon Main menu input
switch (mainInput) {
// Employee Submenu
case 1:
do {
subInput1 = menu("Hourly Employees", "Salary Employee",
"Comission Employees", "Back");
switch (subInput1) {
case 1:
em.listHourly();
do {
subInput2 = menu("Add Hours", "Back");
if (subInput2 == 1) {
System.out.println("Employee Number: ");
en = in.nextInt();
index = em.getIndex(en);
if (index != -1) {
System.out.print("Enter Hours: ");
amount = in.nextDouble();
em.increaseHours(index, amount);
} else {
System.out.println("Employee not found!");
}
}
} while (subInput2 != 2);
break;
case 2:
em.listSalary();
subInput2 = menu("Back");
break;
case 3:
em.listCommission();
do {
subInput2 = menu("Add Sales", "Back");
if (subInput2 == 1) {
System.out.println("Employee Number: ");
en = in.nextInt();
index = em.getIndex(en);
if (index != -1) {
System.out.print("Enter Sales: ");
amount = in.nextDouble();
em.increaseSales(index, amount);
} else {
System.out.println("Employee not found!");
}
}
} while (subInput2 != 2);
break;
}
} while (subInput1 != 4);
break;
// Add Employee
case 2:
String fn,
ln;
char mi,
g,
f;
boolean ft = true;
subInput1 = menu("Hourly", "Salary", "Commission");
System.out.print("Enter Last Name: ");
ln = in.next();
System.out.print("Enter First Name: ");
fn = in.next();
System.out.print("Enter Middle Initial: ");
mi = in.next().charAt(0);
System.out.print("Enter Gender: ");
g = in.next().charAt(0);
System.out.print("Enter Employee Number: ");
en = in.nextInt();
System.out.print("Full Time? (y/n): ");
f = in.next().charAt(0);
if (f == 'n' || f == 'N') {
ft = false;
}
if (subInput1 == 1) {
System.out.print("Enter wage: ");
} else if (subInput1 == 2) {
System.out.print("Enter salary: ");
} else {
System.out.print("Enter rate: ");
}
amount = in.nextDouble();
em.addEmployee(subInput1, fn, ln, mi, g, en, ft, amount);
break;
// Remove Employee
case 3:
System.out.print("Enter Employee Number to Remove: ");
en = in.nextInt();
index = em.getIndex(en);
em.removeEmployee(index);
break;
// Calculate Weekly Payout
case 4:
System.out.printf("Total weekly payout is %.2f ",
em.calculatePayout());
break;
// Calculate Bonus
case 5:
amount = em.holidayBonuses();
System.out.printf("Total holiday bonus payout is %.2f ",
amount);
break;
// Apply Annual Raises
case 6:
em.annualRaises();
System.out.println("Annual Raises applied.");
break;
// Reset the weeks values
case 7:
em.resetWeek();
System.out.println("Weekly values reset.");
break;
// Exit
case 8:
System.out
.println(" Thank you for using the Employee Manager! ");
}
} while (mainInput != 8);
}
}

More Related Content

Similar to package employeeType.employee;public abstract class Employee {  .pdf

I need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfI need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdf
kourystephaniamari30
 
Code Include libraries. import javax.swing.JOptionPane;.pdf
Code Include libraries. import javax.swing.JOptionPane;.pdfCode Include libraries. import javax.swing.JOptionPane;.pdf
Code Include libraries. import javax.swing.JOptionPane;.pdf
ankitmobileshop235
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
aplolomedicalstoremr
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
fashioncollection2
 
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxmaJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
infantsuk
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
forwardcom41
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
NicholasflqStewartl
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfI am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
petercoiffeur18
 
import java.io.-WPS Office.docx
import java.io.-WPS Office.docximport java.io.-WPS Office.docx
import java.io.-WPS Office.docx
Katecate1
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
fashioncollection2
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
Ganesh Samarthyam
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
arjuncp10
 
Designing Immutability Data Flows in Ember
Designing Immutability Data Flows in EmberDesigning Immutability Data Flows in Ember
Designing Immutability Data Flows in Ember
Jorge Lainfiesta
 
C# programs
C# programsC# programs
C# programs
Gourav Pant
 
Keep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfKeep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdf
AroraRajinder1
 
for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...
hwbloom14
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
arpaqindia
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J ScriptRoman Agaev
 

Similar to package employeeType.employee;public abstract class Employee {  .pdf (20)

I need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfI need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdf
 
Code Include libraries. import javax.swing.JOptionPane;.pdf
Code Include libraries. import javax.swing.JOptionPane;.pdfCode Include libraries. import javax.swing.JOptionPane;.pdf
Code Include libraries. import javax.swing.JOptionPane;.pdf
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
define a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdfdefine a class name Employee whose objects are records for employee..pdf
define a class name Employee whose objects are records for employee..pdf
 
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxmaJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfI am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
 
import java.io.-WPS Office.docx
import java.io.-WPS Office.docximport java.io.-WPS Office.docx
import java.io.-WPS Office.docx
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
 
Designing Immutability Data Flows in Ember
Designing Immutability Data Flows in EmberDesigning Immutability Data Flows in Ember
Designing Immutability Data Flows in Ember
 
C# programs
C# programsC# programs
C# programs
 
Keep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdfKeep getting a null pointer exception for some odd reasonim creati.pdf
Keep getting a null pointer exception for some odd reasonim creati.pdf
 
for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J Script
 

More from nipuns1983

0.5164Solution0.5164.pdf
0.5164Solution0.5164.pdf0.5164Solution0.5164.pdf
0.5164Solution0.5164.pdf
nipuns1983
 
#include stdio.h #include stdlib.h #include unistd.h .pdf
 #include stdio.h #include stdlib.h #include unistd.h .pdf #include stdio.h #include stdlib.h #include unistd.h .pdf
#include stdio.h #include stdlib.h #include unistd.h .pdf
nipuns1983
 
Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
  Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf  Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
nipuns1983
 
ADH causes increased permeability of DCT and collecting tubule to wa.pdf
  ADH causes increased permeability of DCT and collecting tubule to wa.pdf  ADH causes increased permeability of DCT and collecting tubule to wa.pdf
ADH causes increased permeability of DCT and collecting tubule to wa.pdf
nipuns1983
 
There are several solutions for treating chronically mentally ill pa.pdf
There are several solutions for treating chronically mentally ill pa.pdfThere are several solutions for treating chronically mentally ill pa.pdf
There are several solutions for treating chronically mentally ill pa.pdf
nipuns1983
 
The water is split providing the electrons for PSII, which then exci.pdf
The water is split providing the electrons for PSII, which then exci.pdfThe water is split providing the electrons for PSII, which then exci.pdf
The water is split providing the electrons for PSII, which then exci.pdf
nipuns1983
 
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdfThe Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
nipuns1983
 
The integral has a pole at z=-1Integral region is around a circle .pdf
The integral has a pole at z=-1Integral region is around a circle .pdfThe integral has a pole at z=-1Integral region is around a circle .pdf
The integral has a pole at z=-1Integral region is around a circle .pdf
nipuns1983
 
SolutionThis encryption scheme is not considered to be a secure o.pdf
SolutionThis encryption scheme is not considered to be a secure o.pdfSolutionThis encryption scheme is not considered to be a secure o.pdf
SolutionThis encryption scheme is not considered to be a secure o.pdf
nipuns1983
 
Smart Beta ia a rather elusive term in modern finance sometimes know.pdf
Smart Beta ia a rather elusive term in modern finance sometimes know.pdfSmart Beta ia a rather elusive term in modern finance sometimes know.pdf
Smart Beta ia a rather elusive term in modern finance sometimes know.pdf
nipuns1983
 
Ques-1 What is the differential diagnosis of this patients infectin.pdf
Ques-1 What is the differential diagnosis of this patients infectin.pdfQues-1 What is the differential diagnosis of this patients infectin.pdf
Ques-1 What is the differential diagnosis of this patients infectin.pdf
nipuns1983
 
Option 1Project management software Project management software .pdf
Option 1Project management software Project management software .pdfOption 1Project management software Project management software .pdf
Option 1Project management software Project management software .pdf
nipuns1983
 
import java.util.Scanner;public class InputIntegers{public sta.pdf
import java.util.Scanner;public class InputIntegers{public sta.pdfimport java.util.Scanner;public class InputIntegers{public sta.pdf
import java.util.Scanner;public class InputIntegers{public sta.pdf
nipuns1983
 
The main drawback of Troutons rule is that it i.pdf
                     The main drawback of Troutons rule is that it i.pdf                     The main drawback of Troutons rule is that it i.pdf
The main drawback of Troutons rule is that it i.pdf
nipuns1983
 
Solid to liquid, or liquid to gas change absorbs .pdf
                     Solid to liquid, or liquid to gas change absorbs .pdf                     Solid to liquid, or liquid to gas change absorbs .pdf
Solid to liquid, or liquid to gas change absorbs .pdf
nipuns1983
 
RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
                     RNase P catalyzes the Mg2+-dependent 5-maturati.pdf                     RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
nipuns1983
 
pH of a solution is directly proportional to mola.pdf
                     pH of a solution is directly proportional to mola.pdf                     pH of a solution is directly proportional to mola.pdf
pH of a solution is directly proportional to mola.pdf
nipuns1983
 
Option - D is correct !! .pdf
                     Option - D is correct !!                         .pdf                     Option - D is correct !!                         .pdf
Option - D is correct !! .pdf
nipuns1983
 
n = number present before orbital =3 l= 0 for s, .pdf
                     n = number present before orbital =3 l= 0 for s, .pdf                     n = number present before orbital =3 l= 0 for s, .pdf
n = number present before orbital =3 l= 0 for s, .pdf
nipuns1983
 
nitro methane is a polar compound plus it has nit.pdf
                     nitro methane is a polar compound plus it has nit.pdf                     nitro methane is a polar compound plus it has nit.pdf
nitro methane is a polar compound plus it has nit.pdf
nipuns1983
 

More from nipuns1983 (20)

0.5164Solution0.5164.pdf
0.5164Solution0.5164.pdf0.5164Solution0.5164.pdf
0.5164Solution0.5164.pdf
 
#include stdio.h #include stdlib.h #include unistd.h .pdf
 #include stdio.h #include stdlib.h #include unistd.h .pdf #include stdio.h #include stdlib.h #include unistd.h .pdf
#include stdio.h #include stdlib.h #include unistd.h .pdf
 
Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
  Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf  Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
 
ADH causes increased permeability of DCT and collecting tubule to wa.pdf
  ADH causes increased permeability of DCT and collecting tubule to wa.pdf  ADH causes increased permeability of DCT and collecting tubule to wa.pdf
ADH causes increased permeability of DCT and collecting tubule to wa.pdf
 
There are several solutions for treating chronically mentally ill pa.pdf
There are several solutions for treating chronically mentally ill pa.pdfThere are several solutions for treating chronically mentally ill pa.pdf
There are several solutions for treating chronically mentally ill pa.pdf
 
The water is split providing the electrons for PSII, which then exci.pdf
The water is split providing the electrons for PSII, which then exci.pdfThe water is split providing the electrons for PSII, which then exci.pdf
The water is split providing the electrons for PSII, which then exci.pdf
 
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdfThe Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
 
The integral has a pole at z=-1Integral region is around a circle .pdf
The integral has a pole at z=-1Integral region is around a circle .pdfThe integral has a pole at z=-1Integral region is around a circle .pdf
The integral has a pole at z=-1Integral region is around a circle .pdf
 
SolutionThis encryption scheme is not considered to be a secure o.pdf
SolutionThis encryption scheme is not considered to be a secure o.pdfSolutionThis encryption scheme is not considered to be a secure o.pdf
SolutionThis encryption scheme is not considered to be a secure o.pdf
 
Smart Beta ia a rather elusive term in modern finance sometimes know.pdf
Smart Beta ia a rather elusive term in modern finance sometimes know.pdfSmart Beta ia a rather elusive term in modern finance sometimes know.pdf
Smart Beta ia a rather elusive term in modern finance sometimes know.pdf
 
Ques-1 What is the differential diagnosis of this patients infectin.pdf
Ques-1 What is the differential diagnosis of this patients infectin.pdfQues-1 What is the differential diagnosis of this patients infectin.pdf
Ques-1 What is the differential diagnosis of this patients infectin.pdf
 
Option 1Project management software Project management software .pdf
Option 1Project management software Project management software .pdfOption 1Project management software Project management software .pdf
Option 1Project management software Project management software .pdf
 
import java.util.Scanner;public class InputIntegers{public sta.pdf
import java.util.Scanner;public class InputIntegers{public sta.pdfimport java.util.Scanner;public class InputIntegers{public sta.pdf
import java.util.Scanner;public class InputIntegers{public sta.pdf
 
The main drawback of Troutons rule is that it i.pdf
                     The main drawback of Troutons rule is that it i.pdf                     The main drawback of Troutons rule is that it i.pdf
The main drawback of Troutons rule is that it i.pdf
 
Solid to liquid, or liquid to gas change absorbs .pdf
                     Solid to liquid, or liquid to gas change absorbs .pdf                     Solid to liquid, or liquid to gas change absorbs .pdf
Solid to liquid, or liquid to gas change absorbs .pdf
 
RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
                     RNase P catalyzes the Mg2+-dependent 5-maturati.pdf                     RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
 
pH of a solution is directly proportional to mola.pdf
                     pH of a solution is directly proportional to mola.pdf                     pH of a solution is directly proportional to mola.pdf
pH of a solution is directly proportional to mola.pdf
 
Option - D is correct !! .pdf
                     Option - D is correct !!                         .pdf                     Option - D is correct !!                         .pdf
Option - D is correct !! .pdf
 
n = number present before orbital =3 l= 0 for s, .pdf
                     n = number present before orbital =3 l= 0 for s, .pdf                     n = number present before orbital =3 l= 0 for s, .pdf
n = number present before orbital =3 l= 0 for s, .pdf
 
nitro methane is a polar compound plus it has nit.pdf
                     nitro methane is a polar compound plus it has nit.pdf                     nitro methane is a polar compound plus it has nit.pdf
nitro methane is a polar compound plus it has nit.pdf
 

Recently uploaded

CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 

Recently uploaded (20)

CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 

package employeeType.employee;public abstract class Employee {  .pdf

  • 1. package employeeType.employee; public abstract class Employee { private String firstName; private String lastName; private char middleInitial; private boolean fulltime; private char gender; private int employeeNum; public Employee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime) { super(); this.firstName = firstName; this.lastName = lastName; this.middleInitial = middleInitial; this.fulltime = fulltime; this.gender = gender; this.employeeNum = employeeNum; } public int getEmployeeNumber() { return this.employeeNum; } public void setEmployeeNumber(int empNum) { this.employeeNum = empNum; } public String getFirstName() { return firstName; } String getLastName() { return lastName; } char getMiddleInitial() { return middleInitial; } public char getGender() { return gender;
  • 2. } public void setFirstName(String fn) { this.firstName = fn; } public void setLastName(String ln) { this.lastName = ln; } public void setMiddleI(char m) { this.middleInitial = m; } public void setGender(char g) { this.gender = g; } public boolean equals(Object obj) { // TODO Auto-generated method stub if (obj instanceof Employee) { Employee employee = (Employee) obj; if (employee.getEmployeeNumber() == this.getEmployeeNumber()) return true; else return false; } else return false; } public String toString() { // TODO Auto-generated method stub return getEmployeeNumber() + " " + getFirstName() + " " + getLastName() + " Gender:" + getGender() + " Status:" + ((fulltime) ? "Full Time" : "Part Time"); } public abstract double calculateWeeklyPay(); public abstract void annualRaise(); public abstract double holidayBonus(); public abstract void resetWeek(); } package employeeType.subTypes;
  • 3. import java.text.DecimalFormat; import employeeType.employee.Employee; public class HourlyEmployee extends Employee { private double wage; private double hoursWorked; public HourlyEmployee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double wage) { super(firstName, lastName, middleInitial, gender, employeeNum, fulltime); // TODO Auto-generated constructor stub this.wage = wage; this.hoursWorked = 0.0d; } public void increaseHours(double hours) { if (hours > 0) this.hoursWorked += hours; else System.out.println("Error! Invalid hours"); } public String toString() { // TODO Auto-generated method stub return super.toString() + " Wage: " + wage + " Hours Worked: " + hoursWorked; } public double calculateWeeklyPay() { double pay; if (hoursWorked > 40) { pay = (40 * wage) + (2 * (hoursWorked - 40) * wage); } else { pay = wage * hoursWorked; } return pay; } public void annualRaise() { DecimalFormat decimalFormat = new DecimalFormat("#.##"); wage = Double.valueOf(decimalFormat.format(wage * 0.05));
  • 4. } public double holidayBonus() { return 40 * wage; } public void resetWeek() { this.hoursWorked = 0; } } package employeeType.subTypes; import java.text.DecimalFormat; import employeeType.employee.Employee; public class SalaryEmployee extends Employee { double salary; public SalaryEmployee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double s) { super(firstName, lastName, middleInitial, gender, employeeNum, fulltime); // TODO Auto-generated constructor stub this.salary = s; } public String toString() { // TODO Auto-generated method stub return super.toString() + " Salary:" + salary; } public double calculateWeeklyPay() { return salary / 52.00d; } public void annualRaise() { DecimalFormat decimalFormat = new DecimalFormat("#.##"); salary = Double.valueOf(decimalFormat.format(salary * 0.06)); } public double holidayBonus() { return salary * 0.03; } public void resetWeek() { }
  • 5. } package employeeType.subTypes; import employeeType.employee.Employee; public class CommissionEmployee extends Employee { double sales; double rate; public CommissionEmployee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double r) { super(firstName, lastName, middleInitial, gender, employeeNum, fulltime); // TODO Auto-generated constructor stub this.rate = r; this.sales = 0.0d; } public String toString() { // TODO Auto-generated method stub return super.toString() + " Rate: " + rate + " Sales: " + sales; } public void increaseSales(double sales) { if (sales > 0) this.sales += sales; else System.out.println("Error! Not valid sales"); } public double calculateWeeklyPay() { return sales * rate / 100; } public void annualRaise() { this.rate += 0.02; } public double holidayBonus() { return 0.00d; } public void resetWeek() { this.sales = 0.0d; }
  • 6. } import employeeType.employee.Employee; import employeeType.subTypes.CommissionEmployee; import employeeType.subTypes.HourlyEmployee; import employeeType.subTypes.SalaryEmployee; public class EmployeeManager { Employee[] employees; final int employeeMax = 10; int currentEmployees; public EmployeeManager() { // TODO Auto-generated constructor stub employees = new Employee[employeeMax]; this.currentEmployees = 0; } /* * Takes an int representing the type of Employee to be added (1 – Hourly, 2 * – Salary, 3 – Commission) as well as the required data to create that * Employee. If one of these values is not passed output the line, “Invalid * Employee Type, None Added”, and exit the method. If an Employee with the * given Employee Number already exists do not add the Employee and output * the line, “Duplicate Not Added”, and exit the method. If the array is at * maximum capacity do not add the new Employee, and output the line, * "Cannot add more Employees". */ public void addEmployee(int input, String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double wage) { switch (input) { case 1: { HourlyEmployee employee = new HourlyEmployee(firstName, lastName, middleInitial, gender, employeeNum, fulltime, wage); for (int i = 0; i < employees.length; i++) { if (employees[i].getEmployeeNumber() == employeeNum) { System.out.println("Duplicate Not Added"); return; }
  • 7. } if (currentEmployees == employeeMax) { System.out.println("Cannot add more Employees"); return; } employees[currentEmployees] = employee; currentEmployees++; break; } case 2: { SalaryEmployee employee = new SalaryEmployee(firstName, lastName, middleInitial, gender, employeeNum, fulltime, wage); for (int i = 0; i < employees.length; i++) { if (employees[i].getEmployeeNumber() == employeeNum) { System.out.println("Duplicate Not Added"); return; } } if (currentEmployees == employeeMax) { System.out.println("Cannot add more Employees"); return; } employees[currentEmployees] = employee; currentEmployees++; break; } case 3: { CommissionEmployee employee = new CommissionEmployee(firstName, lastName, middleInitial, gender, employeeNum, fulltime, wage); for (int i = 0; i < employees.length; i++) { if (employees[i].getEmployeeNumber() == employeeNum) { System.out.println("Duplicate Not Added"); return; } }
  • 8. if (currentEmployees == employeeMax) { System.out.println("Cannot add more Employees"); return; } employees[currentEmployees] = employee; currentEmployees++; break; } default: System.out.println("Invalid Employee Type, None Added"); break; } } // Removes an Employee located at the given index from the Employee array. public void removeEmployee(int index) { employees[index] = null; } // Lists all the current Employees. Outputs there are none if there are // none. public void listAll() { if (currentEmployees == 0) System.out.println("none"); else { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) System.out.println(employees[i].toString()); } } } // Lists all the current HourlyEmployees. Outputs there are none if there // are none. public void listHourly() { if (currentEmployees == 0) System.out.println("none"); else { for (int i = 0; i < currentEmployees; i++) {
  • 9. if (employees[i] != null) { if (employees[i] instanceof HourlyEmployee) System.out.println(employees[i].toString()); } } } } // Lists all the current SalaryEmployees. Outputs there are none if there // are none. public void listSalary() { if (currentEmployees == 0) System.out.println("none"); else { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { if (employees[i] instanceof SalaryEmployee) System.out.println(employees[i].toString()); } } } } // Lists all the current CommissionEmployees. Outputs there are none if // there are none. public void listCommission() { if (currentEmployees == 0) System.out.println("none"); else { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { if (employees[i] instanceof CommissionEmployee) System.out.println(employees[i].toString()); } } } } public void resetWeek() {
  • 10. for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { employees[i].resetWeek(); } } } public double calculatePayout() { double payOut = 0; for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { payOut += employees[i].calculateWeeklyPay(); } } return payOut; } public int getIndex(int employeeNum) { for (int i = 0; i < employees.length; i++) { if (employees[i].getEmployeeNumber() == employeeNum) { return i; } } return -1; } public void annualRaises() { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { employees[i].annualRaise(); } } } public double holidayBonuses() { double holiBonus = 0; for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { holiBonus += employees[i].holidayBonus(); }
  • 11. } return holiBonus; } // Increase the hours worked of the Employee at the given index by the given // double amount. public void increaseHours(int index, double amount) { if (employees[index] != null && employees[index] instanceof HourlyEmployee) { HourlyEmployee employee = (HourlyEmployee) employees[index]; employee.increaseHours(amount); } } // Increase the sales of the Employee at the given index by the given double // amount. public void increaseSales(int index, double amount) { if (employees[index] != null && employees[index] instanceof CommissionEmployee) { CommissionEmployee employee = (CommissionEmployee) employees[index]; employee.increaseSales(amount); } } } import java.util.Scanner; public class EmployeeDriver { static Scanner in = new Scanner(System.in); public static int menu(String... options) { int choice; for (int line = 0; line < options.length; line++) System.out.printf("%d. %s ", line + 1, options[line]); do { System.out.print("Enter Choice: "); choice = in.nextInt(); } while (!(choice > 0 && choice <= options.length)); return choice; } public static void main(String args[]) {
  • 12. 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 // Main control loop, keep coming back to the // Main menu after each selection is finished do { // This is the main menu. Displays menu // and asks for a choice, validaties that // what is entered is a valid choice System.out.println(" Main Menu "); em.listAll(); mainInput = menu("Employee Submenu", "Add Employee", "Remove Employee", "Calculate Weekly Payout", "Calculate Bonus", "Annual Raises", "Reset Week", "Quit"); // Perform the correct action based upon Main menu input switch (mainInput) { // Employee Submenu case 1: do { subInput1 = menu("Hourly Employees", "Salary Employee", "Comission Employees", "Back"); switch (subInput1) { case 1: em.listHourly(); do { subInput2 = menu("Add Hours", "Back"); if (subInput2 == 1) { System.out.println("Employee Number: "); en = in.nextInt(); index = em.getIndex(en); if (index != -1) { System.out.print("Enter Hours: ");
  • 13. amount = in.nextDouble(); em.increaseHours(index, amount); } else { System.out.println("Employee not found!"); } } } while (subInput2 != 2); break; case 2: em.listSalary(); subInput2 = menu("Back"); break; case 3: em.listCommission(); do { subInput2 = menu("Add Sales", "Back"); if (subInput2 == 1) { System.out.println("Employee Number: "); en = in.nextInt(); index = em.getIndex(en); if (index != -1) { System.out.print("Enter Sales: "); amount = in.nextDouble(); em.increaseSales(index, amount); } else { System.out.println("Employee not found!"); } } } while (subInput2 != 2); break; } } while (subInput1 != 4); break; // Add Employee case 2: String fn,
  • 14. ln; char mi, g, f; boolean ft = true; subInput1 = menu("Hourly", "Salary", "Commission"); System.out.print("Enter Last Name: "); ln = in.next(); System.out.print("Enter First Name: "); fn = in.next(); System.out.print("Enter Middle Initial: "); mi = in.next().charAt(0); System.out.print("Enter Gender: "); g = in.next().charAt(0); System.out.print("Enter Employee Number: "); en = in.nextInt(); System.out.print("Full Time? (y/n): "); f = in.next().charAt(0); if (f == 'n' || f == 'N') { ft = false; } if (subInput1 == 1) { System.out.print("Enter wage: "); } else if (subInput1 == 2) { System.out.print("Enter salary: "); } else { System.out.print("Enter rate: "); } amount = in.nextDouble(); em.addEmployee(subInput1, fn, ln, mi, g, en, ft, amount); break; // Remove Employee case 3: System.out.print("Enter Employee Number to Remove: "); en = in.nextInt(); index = em.getIndex(en);
  • 15. em.removeEmployee(index); break; // Calculate Weekly Payout case 4: System.out.printf("Total weekly payout is %.2f ", em.calculatePayout()); break; // Calculate Bonus case 5: amount = em.holidayBonuses(); System.out.printf("Total holiday bonus payout is %.2f ", amount); break; // Apply Annual Raises case 6: em.annualRaises(); System.out.println("Annual Raises applied."); break; // Reset the weeks values case 7: em.resetWeek(); System.out.println("Weekly values reset."); break; // Exit case 8: System.out .println(" Thank you for using the Employee Manager! "); } } while (mainInput != 8); } } Solution package employeeType.employee; public abstract class Employee {
  • 16. private String firstName; private String lastName; private char middleInitial; private boolean fulltime; private char gender; private int employeeNum; public Employee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime) { super(); this.firstName = firstName; this.lastName = lastName; this.middleInitial = middleInitial; this.fulltime = fulltime; this.gender = gender; this.employeeNum = employeeNum; } public int getEmployeeNumber() { return this.employeeNum; } public void setEmployeeNumber(int empNum) { this.employeeNum = empNum; } public String getFirstName() { return firstName; } String getLastName() { return lastName; } char getMiddleInitial() { return middleInitial; } public char getGender() { return gender; } public void setFirstName(String fn) { this.firstName = fn;
  • 17. } public void setLastName(String ln) { this.lastName = ln; } public void setMiddleI(char m) { this.middleInitial = m; } public void setGender(char g) { this.gender = g; } public boolean equals(Object obj) { // TODO Auto-generated method stub if (obj instanceof Employee) { Employee employee = (Employee) obj; if (employee.getEmployeeNumber() == this.getEmployeeNumber()) return true; else return false; } else return false; } public String toString() { // TODO Auto-generated method stub return getEmployeeNumber() + " " + getFirstName() + " " + getLastName() + " Gender:" + getGender() + " Status:" + ((fulltime) ? "Full Time" : "Part Time"); } public abstract double calculateWeeklyPay(); public abstract void annualRaise(); public abstract double holidayBonus(); public abstract void resetWeek(); } package employeeType.subTypes; import java.text.DecimalFormat; import employeeType.employee.Employee; public class HourlyEmployee extends Employee {
  • 18. private double wage; private double hoursWorked; public HourlyEmployee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double wage) { super(firstName, lastName, middleInitial, gender, employeeNum, fulltime); // TODO Auto-generated constructor stub this.wage = wage; this.hoursWorked = 0.0d; } public void increaseHours(double hours) { if (hours > 0) this.hoursWorked += hours; else System.out.println("Error! Invalid hours"); } public String toString() { // TODO Auto-generated method stub return super.toString() + " Wage: " + wage + " Hours Worked: " + hoursWorked; } public double calculateWeeklyPay() { double pay; if (hoursWorked > 40) { pay = (40 * wage) + (2 * (hoursWorked - 40) * wage); } else { pay = wage * hoursWorked; } return pay; } public void annualRaise() { DecimalFormat decimalFormat = new DecimalFormat("#.##"); wage = Double.valueOf(decimalFormat.format(wage * 0.05)); } public double holidayBonus() { return 40 * wage;
  • 19. } public void resetWeek() { this.hoursWorked = 0; } } package employeeType.subTypes; import java.text.DecimalFormat; import employeeType.employee.Employee; public class SalaryEmployee extends Employee { double salary; public SalaryEmployee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double s) { super(firstName, lastName, middleInitial, gender, employeeNum, fulltime); // TODO Auto-generated constructor stub this.salary = s; } public String toString() { // TODO Auto-generated method stub return super.toString() + " Salary:" + salary; } public double calculateWeeklyPay() { return salary / 52.00d; } public void annualRaise() { DecimalFormat decimalFormat = new DecimalFormat("#.##"); salary = Double.valueOf(decimalFormat.format(salary * 0.06)); } public double holidayBonus() { return salary * 0.03; } public void resetWeek() { } } package employeeType.subTypes; import employeeType.employee.Employee;
  • 20. public class CommissionEmployee extends Employee { double sales; double rate; public CommissionEmployee(String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double r) { super(firstName, lastName, middleInitial, gender, employeeNum, fulltime); // TODO Auto-generated constructor stub this.rate = r; this.sales = 0.0d; } public String toString() { // TODO Auto-generated method stub return super.toString() + " Rate: " + rate + " Sales: " + sales; } public void increaseSales(double sales) { if (sales > 0) this.sales += sales; else System.out.println("Error! Not valid sales"); } public double calculateWeeklyPay() { return sales * rate / 100; } public void annualRaise() { this.rate += 0.02; } public double holidayBonus() { return 0.00d; } public void resetWeek() { this.sales = 0.0d; } } import employeeType.employee.Employee; import employeeType.subTypes.CommissionEmployee;
  • 21. import employeeType.subTypes.HourlyEmployee; import employeeType.subTypes.SalaryEmployee; public class EmployeeManager { Employee[] employees; final int employeeMax = 10; int currentEmployees; public EmployeeManager() { // TODO Auto-generated constructor stub employees = new Employee[employeeMax]; this.currentEmployees = 0; } /* * Takes an int representing the type of Employee to be added (1 – Hourly, 2 * – Salary, 3 – Commission) as well as the required data to create that * Employee. If one of these values is not passed output the line, “Invalid * Employee Type, None Added”, and exit the method. If an Employee with the * given Employee Number already exists do not add the Employee and output * the line, “Duplicate Not Added”, and exit the method. If the array is at * maximum capacity do not add the new Employee, and output the line, * "Cannot add more Employees". */ public void addEmployee(int input, String firstName, String lastName, char middleInitial, char gender, int employeeNum, boolean fulltime, double wage) { switch (input) { case 1: { HourlyEmployee employee = new HourlyEmployee(firstName, lastName, middleInitial, gender, employeeNum, fulltime, wage); for (int i = 0; i < employees.length; i++) { if (employees[i].getEmployeeNumber() == employeeNum) { System.out.println("Duplicate Not Added"); return; } } if (currentEmployees == employeeMax) { System.out.println("Cannot add more Employees");
  • 22. return; } employees[currentEmployees] = employee; currentEmployees++; break; } case 2: { SalaryEmployee employee = new SalaryEmployee(firstName, lastName, middleInitial, gender, employeeNum, fulltime, wage); for (int i = 0; i < employees.length; i++) { if (employees[i].getEmployeeNumber() == employeeNum) { System.out.println("Duplicate Not Added"); return; } } if (currentEmployees == employeeMax) { System.out.println("Cannot add more Employees"); return; } employees[currentEmployees] = employee; currentEmployees++; break; } case 3: { CommissionEmployee employee = new CommissionEmployee(firstName, lastName, middleInitial, gender, employeeNum, fulltime, wage); for (int i = 0; i < employees.length; i++) { if (employees[i].getEmployeeNumber() == employeeNum) { System.out.println("Duplicate Not Added"); return; } } if (currentEmployees == employeeMax) { System.out.println("Cannot add more Employees"); return;
  • 23. } employees[currentEmployees] = employee; currentEmployees++; break; } default: System.out.println("Invalid Employee Type, None Added"); break; } } // Removes an Employee located at the given index from the Employee array. public void removeEmployee(int index) { employees[index] = null; } // Lists all the current Employees. Outputs there are none if there are // none. public void listAll() { if (currentEmployees == 0) System.out.println("none"); else { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) System.out.println(employees[i].toString()); } } } // Lists all the current HourlyEmployees. Outputs there are none if there // are none. public void listHourly() { if (currentEmployees == 0) System.out.println("none"); else { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { if (employees[i] instanceof HourlyEmployee) System.out.println(employees[i].toString());
  • 24. } } } } // Lists all the current SalaryEmployees. Outputs there are none if there // are none. public void listSalary() { if (currentEmployees == 0) System.out.println("none"); else { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { if (employees[i] instanceof SalaryEmployee) System.out.println(employees[i].toString()); } } } } // Lists all the current CommissionEmployees. Outputs there are none if // there are none. public void listCommission() { if (currentEmployees == 0) System.out.println("none"); else { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { if (employees[i] instanceof CommissionEmployee) System.out.println(employees[i].toString()); } } } } public void resetWeek() { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { employees[i].resetWeek();
  • 25. } } } public double calculatePayout() { double payOut = 0; for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { payOut += employees[i].calculateWeeklyPay(); } } return payOut; } public int getIndex(int employeeNum) { for (int i = 0; i < employees.length; i++) { if (employees[i].getEmployeeNumber() == employeeNum) { return i; } } return -1; } public void annualRaises() { for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { employees[i].annualRaise(); } } } public double holidayBonuses() { double holiBonus = 0; for (int i = 0; i < currentEmployees; i++) { if (employees[i] != null) { holiBonus += employees[i].holidayBonus(); } } return holiBonus; }
  • 26. // Increase the hours worked of the Employee at the given index by the given // double amount. public void increaseHours(int index, double amount) { if (employees[index] != null && employees[index] instanceof HourlyEmployee) { HourlyEmployee employee = (HourlyEmployee) employees[index]; employee.increaseHours(amount); } } // Increase the sales of the Employee at the given index by the given double // amount. public void increaseSales(int index, double amount) { if (employees[index] != null && employees[index] instanceof CommissionEmployee) { CommissionEmployee employee = (CommissionEmployee) employees[index]; employee.increaseSales(amount); } } } import java.util.Scanner; public class EmployeeDriver { static Scanner in = new Scanner(System.in); public static int menu(String... options) { int choice; for (int line = 0; line < options.length; line++) System.out.printf("%d. %s ", line + 1, options[line]); do { System.out.print("Enter 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
  • 27. int en; // Inputting an employee number int index; double amount; EmployeeManager em = new EmployeeManager(); // The EmployeManager object // Main control loop, keep coming back to the // Main menu after each selection is finished do { // This is the main menu. Displays menu // and asks for a choice, validaties that // what is entered is a valid choice System.out.println(" Main Menu "); em.listAll(); mainInput = menu("Employee Submenu", "Add Employee", "Remove Employee", "Calculate Weekly Payout", "Calculate Bonus", "Annual Raises", "Reset Week", "Quit"); // Perform the correct action based upon Main menu input switch (mainInput) { // Employee Submenu case 1: do { subInput1 = menu("Hourly Employees", "Salary Employee", "Comission Employees", "Back"); switch (subInput1) { case 1: em.listHourly(); do { subInput2 = menu("Add Hours", "Back"); if (subInput2 == 1) { System.out.println("Employee Number: "); en = in.nextInt(); index = em.getIndex(en); if (index != -1) { System.out.print("Enter Hours: "); amount = in.nextDouble(); em.increaseHours(index, amount); } else {
  • 28. System.out.println("Employee not found!"); } } } while (subInput2 != 2); break; case 2: em.listSalary(); subInput2 = menu("Back"); break; case 3: em.listCommission(); do { subInput2 = menu("Add Sales", "Back"); if (subInput2 == 1) { System.out.println("Employee Number: "); en = in.nextInt(); index = em.getIndex(en); if (index != -1) { System.out.print("Enter Sales: "); amount = in.nextDouble(); em.increaseSales(index, amount); } else { System.out.println("Employee not found!"); } } } while (subInput2 != 2); break; } } while (subInput1 != 4); break; // Add Employee case 2: String fn, ln; char mi, g,
  • 29. f; boolean ft = true; subInput1 = menu("Hourly", "Salary", "Commission"); System.out.print("Enter Last Name: "); ln = in.next(); System.out.print("Enter First Name: "); fn = in.next(); System.out.print("Enter Middle Initial: "); mi = in.next().charAt(0); System.out.print("Enter Gender: "); g = in.next().charAt(0); System.out.print("Enter Employee Number: "); en = in.nextInt(); System.out.print("Full Time? (y/n): "); f = in.next().charAt(0); if (f == 'n' || f == 'N') { ft = false; } if (subInput1 == 1) { System.out.print("Enter wage: "); } else if (subInput1 == 2) { System.out.print("Enter salary: "); } else { System.out.print("Enter rate: "); } amount = in.nextDouble(); em.addEmployee(subInput1, fn, ln, mi, g, en, ft, amount); break; // Remove Employee case 3: System.out.print("Enter Employee Number to Remove: "); en = in.nextInt(); index = em.getIndex(en); em.removeEmployee(index); break; // Calculate Weekly Payout
  • 30. case 4: System.out.printf("Total weekly payout is %.2f ", em.calculatePayout()); break; // Calculate Bonus case 5: amount = em.holidayBonuses(); System.out.printf("Total holiday bonus payout is %.2f ", amount); break; // Apply Annual Raises case 6: em.annualRaises(); System.out.println("Annual Raises applied."); break; // Reset the weeks values case 7: em.resetWeek(); System.out.println("Weekly values reset."); break; // Exit case 8: System.out .println(" Thank you for using the Employee Manager! "); } } while (mainInput != 8); } }