Question: I need help writing a JUnit test class to test these three classes in java Employee: abstract class Employee { private static int employeeIdStatic =

I need help writing a JUnit test class to test these three classes in java
Employee:
abstract class Employee {
private static int employeeIdStatic =1;
private String fName;
private String lName;
private int employeeId;
public Employee(String fName, String lName){
this.fName = fName;
this.lName = lName;
this.employeeId = employeeIdStatic;
employeeIdStatic++;
}
public String getfName(){
return fName;
}
public String getlName(){
return lName;
}
public int getEmployeeId(){
return employeeId;
}
public void setfName(String fName){
this.fName = fName;
}
public void setlName(String lName){
this.lName = lName;
}
public String toString(){
return "Id:"+ employeeId +"-"+ fName +","+ lName;
}
public abstract double GetPaycheck();
}
SalariedEmployee:
public class SalariedEmployee extends Employee {
protected double salary;
public SalariedEmployee(String fName, String lName, double salary){
super(fName, lName);
this.salary = salary;
}
public double GetPaycheck(){
return salary/26;
}
public double getSalary(){
return salary;
}
public void setSalary(double salary){
this.salary = salary;
}
@Override
public String toString(){
return String.format("Salaried, Base : $%,.2f; Id:%d -%s,%s", getSalary(), getEmployeeId(), getlName(), getfName());
}
}
HourlyEmployee:
public class HourlyEmployee extends Employee {
private double hourlyRate;
private double hoursWorked;
public HourlyEmployee(String fName, String lName, double hourlyRate){
super(fName, lName);
this.hourlyRate = hourlyRate;
}
public double GetPaycheck(){
return hourlyRate*hoursWorked;
}
public double getHourlyRate(){
return hourlyRate;
}
public double getHoursWorked(){
return hoursWorked;
}
public void setHourlyRate(double hourlyRate){
this.hourlyRate = hourlyRate;
}
public void setHoursWorked(double hoursWorked){
this.hoursWorked = hoursWorked;
}
@Override
public String toString(){
return String.format("Hourly: $%,.2f; Id:%d -%s,%s", hourlyRate, getEmployeeId(), getlName(), getfName());
}
}
CommissionedEmployee:
public class CommissionedEmployee extends SalariedEmployee {
private float[][] commissionSchedule;
private double unitsSold;
public CommissionedEmployee(String fName, String lName, float[][] commissionSchedule, double salary){
super(fName, lName, salary);
this.commissionSchedule = new float[commissionSchedule.length][];
for (int i =0; i < commissionSchedule.length; i++){
this.commissionSchedule[i]= new float[commissionSchedule[i].length];
for (int j =0; j < commissionSchedule[i].length; j++){
this.commissionSchedule[i][j]= commissionSchedule[i][j];
}
}
}
public double GetPaycheck(){
float[][] cs = commissionSchedule;
double highestVPU =0;
//goes through every row
for(int i =0; i < cs.length; i++){
//if it meets minimum units sold
if(unitsSold >= cs[i][0]){
if(cs[i][1]> highestVPU)
{
highestVPU = cs[i][1];
}
}
}
return ((getSalary()+highestVPU*unitsSold)/26) ;
}
public double getUnitsSold(){
return unitsSold;
}
public void setUnitsSold(int unitsSold){
this.unitsSold = unitsSold;
}
@Override
public String toString(){
return String.format("Commission: Base : $%,.2f; Id:%d -%s,%s", getSalary(), getEmployeeId(), getlName(), getfName());
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!