package employeeType.employee;public class Employee { private.pdf
1. package employeeType.employee;
public 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 )
{
setFirstName(firstName);
setLastName(lastName);
setMiddleInitial(middleInitial);
setFulltime(fulltime);
setGender(gender);
setEmployeeNum(employeeNum);
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public char getMiddleInitial() {
return middleInitial;
}
public void setMiddleInitial(char middleInitial) {
2. this.middleInitial = middleInitial;
}
public boolean isFulltime() {
return fulltime;
}
public void setFulltime(boolean fulltime) {
this.fulltime = fulltime;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
if(gender=='M' || gender=='F')
{
this.gender = gender;
}
else
{
this.gender='F';
}
}
public int getEmployeeNum() {
return employeeNum;
}
public void setEmployeeNum(int employeeNum) {
while(true)
{
if(employeeNum>=10000 && employeeNum<=99999)
{
this.employeeNum = employeeNum;
}
else
{
new IllegalArgumentException("Invalid Employee Num.should be between 10000 and
99999(inclusive) ");
continue;
3. }
}
}
Override(Have to keep at the rate symbol before the override where ever it is in this project)
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (employeeNum != other.employeeNum)
return false;
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (fulltime != other.fulltime)
return false;
if (gender != other.gender)
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
if (middleInitial != other.middleInitial)
return false;
return true;
}
Override
public String toString() {
8. setSales(rate);
setSales(0.0);
}
public double getSales() {
return sales;
}
public void setSales(double sales) {
this.sales = sales;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public void increaseSales(double sales)
{
if(sales<0)
throw new IllegalArgumentException("Sales Must be greater than 0");
else
sales=getSales()+sales;
}
public double calculateWeeklyPay()
{
return getRate();
}
public void annualRaise()
{
rate=(getRate()+0.02);
}
public double holidayBonus()
{
return 0.0;
}
public void resetWeek()
{
9. setSales(0.0);
}
Override
public String toString() {
super.toString();
System.out.println("Rate: "+getRate());
System.out.println("Sales: "+getSales());
return " ";
}
}
__________________________________________________________________________
package employeeType.employee;
import employeeType.subTypes.HourlyEmployee;
import employeeType.subTypes.SalaryEmployee;
import employeeType.subTypes.CommissionEmployee;
import java.util.Scanner;
public class EmployeeTest
{
public static void main(String args[])
{
//Create references for our objects
HourlyEmployee hourly;
SalaryEmployee salary;
CommissionEmployee commission;
//The sum of all bonuses will be placed here
double bonusPayout = 0;
//Create and print a new HourlyEmployee
hourly = HourlyFactory();
System.out.printf(" %s ", hourly);
//Create and print a new SalaryEmployee
salary = SalaryFactory();
10. System.out.printf(" %s ", salary);
//Create and print a new CommissionEmployee
commission = CommissionFactory();
System.out.printf(" %s ", commission);
//Alter some values of Hourly and Commission
System.out.println("Increasing Hourly's hours worked by 50.");
hourly.increaseHours(50);
System.out.println("Increasing Commissions's sales by 150,000. ");
commission.increaseSales(150000);
//Output weekly pay for each Employee
System.out.printf("Hourly Payout: %.2f ", hourly.calculateWeeklyPay());
System.out.printf("Salary Payout: %.2f ", salary.calculateWeeklyPay());
System.out.printf("Commission Payout: %.2f ", commission.calculateWeeklyPay());
//Find total bonus payout
System.out.println("Finding total bonus payout...");
bonusPayout += hourly.holidayBonus();
bonusPayout += salary.holidayBonus();
bonusPayout += commission.holidayBonus();
System.out.printf("Bonus Payout is %.2f ", bonusPayout);
//Reset the week and apply raises to all Employees
System.out.println("Applying annual raises and resetting week...");
hourly.resetWeek();
hourly.annualRaise();
salary.resetWeek();
salary.annualRaise();
commission.resetWeek();
commission.annualRaise();
//Output Employees after changes
11. System.out.printf("%s %s %s ", hourly, salary, commission);
}
//Retrieve input and create HourlyEmployee
public static HourlyEmployee HourlyFactory()
{
System.out.println("Creating HourlyEmployee...");
return new HourlyEmployee("Steve", "Rogers", 'A', 'M', 12345, true, 15.34);
}
//Retrieve input and create SalaryEmployee
public static SalaryEmployee SalaryFactory()
{
System.out.println("Creating SalaryEmployee...");
return new SalaryEmployee("Kitty", "Pryde", 'X', 'F', 54321, true, 75000);
}
//Retrieve input and create CommissionEmployee
public static CommissionEmployee CommissionFactory()
{
System.out.println("Creating CommissionEmployee...");
return new CommissionEmployee("Johnny", "Storm", 'F', 'L', 976499, false, 2.5);
}
}
________________________________________________________________________
Solution
package employeeType.employee;
public class Employee {
private String firstName;
private String lastName;
private char middleInitial;
private boolean fulltime;
private char gender;
private int employeeNum;
12. public Employee(String firstName, String lastName, char middleInitial,char gender,int
employeeNum,boolean fulltime )
{
setFirstName(firstName);
setLastName(lastName);
setMiddleInitial(middleInitial);
setFulltime(fulltime);
setGender(gender);
setEmployeeNum(employeeNum);
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public char getMiddleInitial() {
return middleInitial;
}
public void setMiddleInitial(char middleInitial) {
this.middleInitial = middleInitial;
}
public boolean isFulltime() {
return fulltime;
}
public void setFulltime(boolean fulltime) {
this.fulltime = fulltime;
}
public char getGender() {
13. return gender;
}
public void setGender(char gender) {
if(gender=='M' || gender=='F')
{
this.gender = gender;
}
else
{
this.gender='F';
}
}
public int getEmployeeNum() {
return employeeNum;
}
public void setEmployeeNum(int employeeNum) {
while(true)
{
if(employeeNum>=10000 && employeeNum<=99999)
{
this.employeeNum = employeeNum;
}
else
{
new IllegalArgumentException("Invalid Employee Num.should be between 10000 and
99999(inclusive) ");
continue;
}
}
}
Override(Have to keep at the rate symbol before the override where ever it is in this project)
public boolean equals(Object obj) {
if (this == obj)
return true;
14. if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (employeeNum != other.employeeNum)
return false;
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (fulltime != other.fulltime)
return false;
if (gender != other.gender)
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
if (middleInitial != other.middleInitial)
return false;
return true;
}
Override
public String toString() {
System.out.println(getEmployeeNum());
System.out.println(getFirstName()+", "+getLastName()+" "+getMiddleInitial());
System.out.println("Gender: "+getGender());
if(isFulltime())
{
System.out.println("Status: Full Time");
}
else
{
19. public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public void increaseSales(double sales)
{
if(sales<0)
throw new IllegalArgumentException("Sales Must be greater than 0");
else
sales=getSales()+sales;
}
public double calculateWeeklyPay()
{
return getRate();
}
public void annualRaise()
{
rate=(getRate()+0.02);
}
public double holidayBonus()
{
return 0.0;
}
public void resetWeek()
{
setSales(0.0);
}
Override
public String toString() {
super.toString();
System.out.println("Rate: "+getRate());
System.out.println("Sales: "+getSales());
return " ";
20. }
}
__________________________________________________________________________
package employeeType.employee;
import employeeType.subTypes.HourlyEmployee;
import employeeType.subTypes.SalaryEmployee;
import employeeType.subTypes.CommissionEmployee;
import java.util.Scanner;
public class EmployeeTest
{
public static void main(String args[])
{
//Create references for our objects
HourlyEmployee hourly;
SalaryEmployee salary;
CommissionEmployee commission;
//The sum of all bonuses will be placed here
double bonusPayout = 0;
//Create and print a new HourlyEmployee
hourly = HourlyFactory();
System.out.printf(" %s ", hourly);
//Create and print a new SalaryEmployee
salary = SalaryFactory();
System.out.printf(" %s ", salary);
//Create and print a new CommissionEmployee
commission = CommissionFactory();
System.out.printf(" %s ", commission);
//Alter some values of Hourly and Commission
System.out.println("Increasing Hourly's hours worked by 50.");
hourly.increaseHours(50);
21. System.out.println("Increasing Commissions's sales by 150,000. ");
commission.increaseSales(150000);
//Output weekly pay for each Employee
System.out.printf("Hourly Payout: %.2f ", hourly.calculateWeeklyPay());
System.out.printf("Salary Payout: %.2f ", salary.calculateWeeklyPay());
System.out.printf("Commission Payout: %.2f ", commission.calculateWeeklyPay());
//Find total bonus payout
System.out.println("Finding total bonus payout...");
bonusPayout += hourly.holidayBonus();
bonusPayout += salary.holidayBonus();
bonusPayout += commission.holidayBonus();
System.out.printf("Bonus Payout is %.2f ", bonusPayout);
//Reset the week and apply raises to all Employees
System.out.println("Applying annual raises and resetting week...");
hourly.resetWeek();
hourly.annualRaise();
salary.resetWeek();
salary.annualRaise();
commission.resetWeek();
commission.annualRaise();
//Output Employees after changes
System.out.printf("%s %s %s ", hourly, salary, commission);
}
//Retrieve input and create HourlyEmployee
public static HourlyEmployee HourlyFactory()
{
System.out.println("Creating HourlyEmployee...");
return new HourlyEmployee("Steve", "Rogers", 'A', 'M', 12345, true, 15.34);
}
22. //Retrieve input and create SalaryEmployee
public static SalaryEmployee SalaryFactory()
{
System.out.println("Creating SalaryEmployee...");
return new SalaryEmployee("Kitty", "Pryde", 'X', 'F', 54321, true, 75000);
}
//Retrieve input and create CommissionEmployee
public static CommissionEmployee CommissionFactory()
{
System.out.println("Creating CommissionEmployee...");
return new CommissionEmployee("Johnny", "Storm", 'F', 'L', 976499, false, 2.5);
}
}
________________________________________________________________________