In this lab, we have an abstract class, Employee.java , and three classes that e
ID: 3683214 • Letter: I
Question
In this lab, we have an abstract class, Employee.java, and three classes that extend that class: SalariedEmployee.java, HourlyEmployee.java, and SalesEmployee.java.
Your task in this lab is to fill in the missing code in SalesEmployee.java and EmployeeProgram.java.
this is the Employee.java class:
This is the SalesEmployee.java class:
This is the HourlyEmployee.java class:
This is the SalariedEmployee.java:
This is the EmployeeProgram.java class:
public abstract class Employee private String name; public Employee(String name) public Employee (String name) this.name name this.name = name; public string getName) i public String getName() ( return name; public void setName (String name) this.name name this.name = name; public String toString) t ostring) return Name: return "Name: "tis.name; public abstract double py)Explanation / Answer
Employee.java:
public abstract class Employee {
private String name;
public Employee(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public String toString(){
return "Name:"+this.name;
}
public abstract double pay();
}
SalesEmployee.java:
public class SalesEmployee extends Employee{
private int numWidgetSold;
private double ratePerWidget;
public SalesEmployee(String name,int numWidgetSold,double ratePerWidget){
super(name);
this.numWidgetSold=numWidgetSold;
this.ratePerWidget=ratePerWidget;
}
public void setNumWidgetSold(int numWidgetSold){
this.numWidgetSold=numWidgetSold;
}
public void setRatePerWidget(double ratePerWidget){
this.ratePerWidget=ratePerWidget;
}
public int getNumWidgetSold(int numWidgetSold){
return this.numWidgetSold=numWidgetSold;
}
public double getRatePerWidget(double ratePerWidget){
return this.ratePerWidget=ratePerWidget;
}
public String toString(){
return super.toString()+"/nType:Sales numWidgetSold:"+numWidgetSold+" ratePerWidget:"+ratePerWidget;
}
public double pay(){
return this.numWidgetSold*this.ratePerWidget;
}
}
HourlyEmployee.java:
public class HourlyEmployee extends Employee{
private double payRate;
private int hours;
public HourlyEmployee(String name,double payRate,int hours){
super(name);
this.payRate=payRate;
this.hours=hours;
}
public double getPayRate(){
return this.payRate;
}
public double getHours(){
return this.hours;
}
public void setPayRate(double payRate){
this.payRate=payRate;
}
public void setHours(int hours){
this.hours=hours;
}
public String toString(){
return super.toString()+" Type: Hourly PayRate:$"+payRate+" Hours:"+hours;
}
public double pay(){
return payRate*hours;
}
}
SalariedEmployee.java:
public class SalariedEmployee extends Employee {
private double salary;
public SalariedEmployee(String name,double salary){
super(name);
this.salary=salary;
}
public double getSalary(){
return this.salary;
}
public void setSalary(double salary){
this.salary=salary;
}
public String toString()
{
return super.toString()+" Type:Salaried Salary:$"+salary;
}
public double pay(){
return salary;
}
}
EmployeeProgram.java:
import java.io.*;
public class EmployeeProgram {
public static void main(String []args)throws IOException{
Employee[] emp=new Employee[5];
emp[0]=new SalariedEmployee("ganesh",25000.0);
emp[1]=new SalariedEmployee("ramesh",35000.0);
emp[2]=new HourlyEmployee("ramarao",40.00,150);
emp[3]=new HourlyEmployee("krishnarao",37.00,160);
emp[4]=new SalesEmployee("ramu",50,150.50);
for(int i=0;i<5;i++){
System.out.println(emp[i].toString());
}
}
}
output:
run:
Name:ganesh
Type:Salaried
Salary:$25000.0
Name:ramesh
Type:Salaried
Salary:$35000.0
Name:ramarao
Type: Hourly
PayRate:$40.0
Hours:150
Name:krishnarao
Type: Hourly
PayRate:$37.0
Hours:160
Name:ramu/nType:Sales
numWidgetSold:50
ratePerWidget:150.5
BUILD SUCCESSFUL (total time: 0 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.