Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, you are going to enhance the Employee Hierarchy that you cr

ID: 3788591 • Letter: F

Question

For this assignment, you are going to enhance the Employee Hierarchy that you created in Programming Assignment 2. The following are the requirements to modify programming Assignment 2:

1) Make the Employee Class an abstract class and declare in it the abstract method earnings().

2) Add the abstract method void raise(double percent) to the Employee class.

3) Implement the raise method in each of the subclasses in the following manner:

CommissionEmployee Class - increase the commission rate by the percent specified.

BasePlusCommissionEmployee Class - increase the commission rate by the percent specified and increase the base salary by the percent specified.

SalariedEmployee - increase the salary by the percent specified.

HourlyEmployee - increase the hourly wage by the percent specified.

4) In your main method, after the code from Programming Assignment 2, you will add code to polymorphically process an array of Employees to give each employee a raise. You will create a 5 element Employee array and assign each of the 5 employees to an element of the array. You will then write an java enhanced for loop to loop through the array and give each employee a 2 percent raise except SalariedEmployees will be given a 4 percent raise. Print out each employee to show the new information for each employee.

You should use good standard programming practices in all of your coding.

The output from your program should look like the following:


Employee information.
Commissioned Employee: Fred Jones with ssn: 111-11-1111
   Gross Sales: 2000.00
   Commission Rate: 0.0500
   Earnings: $100.00
Base Salary Plus Commissioned Employee: Sue Smith with ssn: 222-22-2222
   Gross Sales: 3000.00
   Commission Rate: 0.0500
   with Base Salary of: $300.00
   Earnings: $450.00
Salaried Employee: Sha Yang with ssn: 333-33-3333
   Salary: 1150.00
   Earnings: $1150.00
Hourly Employee: Ian Tanning with ssn: 444-44-4444
   Hourly Wage: 15.00
   Hours Worked: 50.00
   Earnings: $825.00
Hourly Employee: Angela Domchek with ssn: 555-55-5555
   Hourly Wage: 20.00
   Hours Worked: 40.00
   Earnings: $800.00

Employee information after raises.
Commissioned Employee: Fred Jones with ssn: 111-11-1111
   Gross Sales: 2000.00
   Commission Rate: 0.0510
   Earnings: $102.00
Base Salary Plus Commissioned Employee: Sue Smith with ssn: 222-22-2222
   Gross Sales: 3000.00
   Commission Rate: 0.0510
   with Base Salary of: $306.00
   Earnings: $459.00
Salaried Employee: Sha Yang with ssn: 333-33-3333
   Salary: 1196.00
   Earnings: $1196.00
Hourly Employee: Ian Tanning with ssn: 444-44-4444
   Hourly Wage: 15.30
   Hours Worked: 50.00
   Earnings: $841.50
Hourly Employee: Angela Domchek with ssn: 555-55-5555
   Hourly Wage: 20.40
   Hours Worked: 40.00
   Earnings: $816.00

---------------------------------------------------------------------

My code is

Employee.java

public class Employee
{
String FirstName;
String LastName;
String socialSecurityNumber;
  
public String getFirstName()
{
return FirstName;
}
public String getLastName()
{
return LastName;
}
public String getSocialSecurityNumber()
{
return socialSecurityNumber;
}

public static void main(String[] args)
{
CommissionEmployee employee1 = new CommissionEmployee("Fred", "Jones", "111-11-1111", 2000.0, .05);
BasePlusCommissionEmployee employee2 = new BasePlusCommissionEmployee("Sue", "Smith", "222-22-2222", 3000.0, .05, 300);
SalariedEmployee employee3 = new SalariedEmployee("Sha", "Yang", "333-33-3333", 1150.0);
HourlyEmployee employee4 = new HourlyEmployee("Ian", "Tanning", "444-44-4444", 15.0, 50);
HourlyEmployee employee5 = new HourlyEmployee("Angela", "Domchek", "555-55-5555", 20.0, 40);
System.out.printf("%s%s%s%s%s", employee1, employee2, employee3, employee4, employee5);
}
  }

-----------------------------------------------------------------------------------------------------------

EmployeeHierachy.java

class EmployeeHierachy extends Employee
{
String FirstName;
String LastName;
String SocialSecurityNumber;

public EmployeeHierachy(String firtname, String lastname, String ssn)
{
this.FirstName = firtname;
this.LastName = lastname;
this.SocialSecurityNumber = ssn;
}
}
class SalariedEmployee extends EmployeeHierachy
{
private double salary;

public SalariedEmployee(String firtname, String lastname, String ssn, double salary)
{
super(firtname,lastname,ssn);
this.salary = salary;
}

public double getSalary()
{
return salary;
}

public void setSalary(int salary)
{
this.salary = salary;
}
  
public String toString()
{
return "Salaried Employee: " + FirstName + " " + LastName + " with ssn: " + SocialSecurityNumber + " " +
" Salary: " + salary +
" Earnings: $" + salary + " ";
}
}


class HourlyEmployee extends EmployeeHierachy
{

private double hourlyWage;
private int hoursWorked;
  
public HourlyEmployee(String firtname, String lastname, String ssn, double hourlyWage, int hoursWorked) {
super(firtname,lastname,ssn);
this.hourlyWage = hourlyWage;
this.hoursWorked = hoursWorked;
}

public double getHourlyWage()
{
return hourlyWage;
}

public void setHourlyWage(double hourlyWage)
{
this.hourlyWage = hourlyWage;
}

public int getHoursWorked()
{
return hoursWorked;
}

public void setHoursWorked(int hoursWorked)
{
this.hoursWorked = hoursWorked;
}

public double getSalary()
{
double sum = 0;
if (this.hoursWorked > 40)
{
sum = 40* this.hourlyWage + (this.hoursWorked - 40) * 1.5 * this.hourlyWage;
}
else
{
sum = this.hoursWorked * this.hourlyWage;
}
return sum;
}

  
public String toString()
{
return "Hourly Employee: " + FirstName + " " + LastName + " with ssn: " + SocialSecurityNumber + " " +
" Hourly Wage: " + hourlyWage +
" Hours Worked: " + hoursWorked +
" Earnings: $" + getSalary() + " ";
}
}

---------------------------------------------------------------------------------------------------------------

//Fig 9.10 : CommissionEmployee.java

class CommissionEmployee extends Employee
{
double grossSales;
double commissionRate;
  
public CommissionEmployee(String fname, String lname, String ssn, double gsales, double commissionRate)
{
if (grossSales < 0.0)
throw new IllegalArgumentException("Grow sales must be >= 0.0");
if (commissionRate <= 0.0 || commissionRate >= 1.0)
throw new IllegalArgumentException("Commission rate must be > 0.0 and < 1.0");
this.FirstName = fname;
this.LastName = lname;
this.socialSecurityNumber = ssn;
this.grossSales = gsales;
this.commissionRate = commissionRate;
}
public void setGrossSales(double gsales)
{
if (grossSales < 0.0)
throw new IllegalArgumentException("Grow sales must be >= 0.0");
this.grossSales = gsales;
}
public double getGrossSales()
{
return grossSales;
}
public void setCommissionRate(double crate)
{
if (commissionRate <= 0.0 || commissionRate >= 1.0)
throw new IllegalArgumentException("Commission rate must be > 0.0 and < 1.0");
this.commissionRate = crate;
}
public double getCommissionRate()
{
return commissionRate;
}
public double earnings()
{
return getCommissionRate() * getGrossSales();
}
public String toString()
{
return "Employee information. " + "Commissioned Employee: " + FirstName + " " + LastName + " with ssn: " + socialSecurityNumber + " " +
" Gross Sales: " + grossSales + " " + " Commission Rate" + commissionRate +
" Earnings: $" + earnings() + " ";
}
}
class BasePlusCommissionEmployee extends CommissionEmployee
{
private double baseSalary;
public BasePlusCommissionEmployee(String fname, String lname, String ssn, double gsales, double crate, double bsalary)
{
super(fname, lname, ssn, gsales, crate);
this.baseSalary = bsalary;
  
if (baseSalary < 0.0)
throw new IllegalArgumentException("Base salary must be >= 0.0");
}
public void setBaseSalary(double bsalary)
{
if (baseSalary < 0.0)
throw new IllegalArgumentException("Base salary must be >= 0.0");
this.baseSalary = bsalary;
}
public double getBaseSalary()
{
return baseSalary;
}
public double earnings()
{
return getBaseSalary() + super.earnings();
}
public String toString()
{
return "Base Salary Plus Commissioned Employee: " + FirstName + " " + LastName + " with ssn: " + socialSecurityNumber + " " +
" Gross Sales: " + grossSales + " " + " Commission Rate" + commissionRate + "with Base Salary of" + baseSalary +
" Earnings: $" + earnings() + " ";
}
}

Explanation / Answer

Employee.java

public abstract class Employee {
//Declaring instance variables
private String firstname;
private String lastname;
  
private String socialSecurityNumber;
public Employee() {
}
//Parameterised constructor
public Employee(String firstname, String lastname,
String socialSecurityNumber) {
super();
this.firstname = firstname;
this.lastname = lastname;
this.socialSecurityNumber = socialSecurityNumber;
}
//Setters and Getters.
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 String getSocialSecurityNumber() {
return socialSecurityNumber;
}
public void setSocialSecurityNumber(String socialSecurityNumber) {
this.socialSecurityNumber = socialSecurityNumber;
}
@Override
public String toString() {
System.out.println(getFirstname()+" "+getLastname()+" with ssn: "+getSocialSecurityNumber());
return " ";
}
//declaring abstract method
public abstract double earnings();

//declaring abstract method
public abstract void raise(double percent);
}

______________

HourlyEmployee.java

public class HourlyEmployee extends Employee {

//Declaring instance variables

private double hourlyWage;

private int hoursworked;

//Parameterised constructor

public HourlyEmployee(String firstname, String lastname, String ssn,

double hourlyWage, int hoursworked) {

super(firstname,lastname,ssn);

this.hourlyWage=hourlyWage;

this.hoursworked=hoursworked;

  

}

//Setters and Getters.

public double getHourlyWage() {

return hourlyWage;

}

public void setHourlyWage(double hourlyWage) {

if(hourlyWage>0)

{

this.hourlyWage = hourlyWage;   

}

else

{

throw new IllegalArgumentException("HourlyWage must be greater than 0.0");

}

  

}

public int getHoursworked() {

return hoursworked;

}

public void setHoursworked(int hoursworked) {

if(hoursworked>0 && hoursworked<=168)

{

this.hoursworked = hoursworked;   

}

else

{

throw new IllegalArgumentException("Hours Worked must be greater than 0 and less than 168");

}

  

}

/*earnings() will return the money earned by that person

* Params: void

* Return : double

*/

@Override

public double earnings()

{

double sal=0;

if(hoursworked<=40)

sal= hourlyWage*hoursworked;

else if(hoursworked>40)

{

sal= (40*hourlyWage)+((hoursworked-40)*(hourlyWage*1.5));   

}

return sal;

}

//toString() method will display the contents of the Object.

@Override

public String toString() {

System.out.print("Hourly Employee:");

super.toString();

System.out.printf("Hourly Wage :%.2f ",getHourlyWage());

System.out.println("Hours Worked :"+getHoursworked());

System.out.printf("Earnings :%.2f ",earnings());

  

return " ";

}

@Override

public void raise(double percent) {

setHourlyWage(getHourlyWage()+(getHourlyWage()*percent/100));

}

}

____________________

SalariedEmployee.java

public class SalariedEmployee extends Employee {

//Declaring instance variables

private double salary;

//Parameterised constructor

public SalariedEmployee(String firstname, String lastname, String ssn,double salary)

{

super(firstname,lastname,ssn);

this.salary=salary;

}

//Setters and Getters.

public double getSalary() {

return salary;

}

public void setSalary(double salary) {

if(salary>0)

{

this.salary = salary;   

}

else

{

throw new IllegalArgumentException("Salary must be greater than 0");

}

  

}

/*earnings() will return the money earned by that person

* Params: void

* Return : double

*/

@Override

public double earnings()

{

return getSalary();

}

//toString() method will display the contents of the Object.

@Override

public String toString() {

System.out.print("Salaried Employee:");

super.toString();

System.out.printf("Salary :%.2f ",getSalary());

System.out.printf("Earnings:%.2f ",earnings());

return " ";

}

@Override

public void raise(double percent) {

setSalary(getSalary()+(getSalary()*percent/100));

}

}

_____________________

CommissionEmployee.java

public class CommissionEmployee extends Employee

{

//Declaring instance variables

private double grossSlaes;

private double commissionRate;

//Parameterised constructor

public CommissionEmployee(String firstname, String lastname, String ssn,

double grossSales, double commissionrate) {

super(firstname,lastname,ssn);

this.grossSlaes=grossSales;

this.commissionRate=commissionrate;

}

//Setters and Getters.

public double getGrossSlaes() {

return grossSlaes;

}

public void setGrossSlaes(double grossSlaes) {

this.grossSlaes = grossSlaes;

}

public double getCommissionRate() {

return commissionRate;

}

public void setCommissionRate(double commissionRate) {

this.commissionRate = commissionRate;

}

/*earnings() will return the money earned by that person

* Params: void

* Return : double

*/

@Override

public double earnings()

{

return getCommissionRate()*getGrossSlaes();

}

//toString() method will display the contents of the Object.

@Override

public String toString() {

System.out.print("Commissioned Employee :");

super.toString();

System.out.printf("Gross Sales: %.2f ",getGrossSlaes());

System.out.printf("Commission Rate: %.2f ",getCommissionRate());

System.out.printf("Earnings:%.2f ",earnings());

return "";

}

@Override

public void raise(double percent) {

setCommissionRate(getCommissionRate()+(getCommissionRate()*percent/100));

}

}

__________________

BasePlusCommissionEmployee.java

public class BasePlusCommissionEmployee extends CommissionEmployee{

//Declaring instance variables

private double baseSalary;

  

//Parameterised constructor

public BasePlusCommissionEmployee(String firstname, String lastname, String ssn,

double grossSales, double commissionrate,double basesalary)

{

super(firstname,lastname,ssn,grossSales,commissionrate);

this.baseSalary=basesalary;

}

//Setters and Getters.

public double getBaseSalary() {

return baseSalary;

}

public void setBaseSalary(double baseSalary) {

this.baseSalary = baseSalary;

}

/*earnings() will return the money earned by that person

* Params: void

* Return : double

*/

@Override

public double earnings()

{

return getBaseSalary()+super.earnings();

}

//toString() method will display the contents of the Object.

@Override

public String toString() {

System.out.print("Base Salary Plus ");

super.toString();

System.out.printf(" with Base Salary of:%.2f ",getBaseSalary());

System.out.printf("Earnings:%.2f ",earnings());

return " ";

}

@Override

public void raise(double percent) {

setCommissionRate(getCommissionRate()+(getCommissionRate()*percent/100));

}

}

_____________________

Test.java

public class Test {

public static void main(String[] args) {

  

  

  

Employee arr[]={new CommissionEmployee("Fred", "Jones", "111-11-1111", 2000.0, .05),

new BasePlusCommissionEmployee("Sue", "Smith", "222-22-2222", 3000.0, .05, 300),

new SalariedEmployee("Sha", "Yang", "333-33-3333", 1150.0),

new HourlyEmployee("Ian", "Tanning", "444-44-4444", 15.0, 50),

new HourlyEmployee("Angela", "Domchek", "555-55-5555", 20.0, 40)};

  

for(int i=0;i<arr.length;i++)

{

System.out.printf("%s",arr[i]);

}

for(int i=0;i<arr.length;i++)

{

if(arr[i] instanceof SalariedEmployee)

{

arr[i].raise(4);

}

else

{

arr[i].raise(2);

}

}

System.out.println("Employee information after raises.");

for(int i=0;i<arr.length;i++)

{

System.out.printf("%s",arr[i]);

}

}

}

____________________

Output:

Commissioned Employee :Fred Jones with ssn: 111-11-1111
Gross Sales: 2000.00
Commission Rate: 0.05
Earnings:100.00
Base Salary Plus Commissioned Employee :Sue Smith with ssn: 222-22-2222
Gross Sales: 3000.00
Commission Rate: 0.05
Earnings:450.00
with Base Salary of:300.00
Earnings:450.00
Salaried Employee:Sha Yang with ssn: 333-33-3333
Salary :1150.00
Earnings:1150.00
Hourly Employee:Ian Tanning with ssn: 444-44-4444
Hourly Wage :15.00
Hours Worked :50
Earnings :825.00
Hourly Employee:Angela Domchek with ssn: 555-55-5555
Hourly Wage :20.00
Hours Worked :40
Earnings :800.00
Employee information after raises.
Commissioned Employee :Fred Jones with ssn: 111-11-1111
Gross Sales: 2000.00
Commission Rate: 0.05
Earnings:102.00
Base Salary Plus Commissioned Employee :Sue Smith with ssn: 222-22-2222
Gross Sales: 3000.00
Commission Rate: 0.05
Earnings:453.00
with Base Salary of:300.00
Earnings:453.00
Salaried Employee:Sha Yang with ssn: 333-33-3333
Salary :1196.00
Earnings:1196.00
Hourly Employee:Ian Tanning with ssn: 444-44-4444
Hourly Wage :15.30
Hours Worked :50
Earnings :841.50
Hourly Employee:Angela Domchek with ssn: 555-55-5555
Hourly Wage :20.40
Hours Worked :40
Earnings :816.00

_______________Could you plz rate me well.Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote