I think this should work. (Haven't had a chance to test it...my compiler is broken...remember...
public abstract class Employee
{
private String EmpFirstName;
private String EmpLastName;
public Employee(String EmpFirstName, String EmpLastName)
{
setEmpFirstName(EmpFirstName);
setEmpLastName(EmpLastName);
}
public abstract int Earnings();
public String getEmpFirstName()
{
return EmpFirstName;
}
public void setEmpFirstName(String FName)
{
EmpFirstName = FName;
}
public String getEmpLastName()
{
return EmpLastName;
}
public void setEmpLastName(String LName)
{
EmpLastName = LName;
}
public String toString()
{
return ("Employee:" +getEmpFirstName() + " " + getEmpLastName());
}
}
class SalaryEmployee extends Employee
{
private int EmpSalary;
public SalaryEmployee(String EmpFirstName, String EmpLastName, int EmpSalary)
{
super(EmpFirstName, EmpLastName);
// what is line below for?
// EmpSalary = 2000000;
setSalary(EmpSalary);
}
public int Earnings()
{
return EmpSalary;
}
public void setSalary(int Salary)
{
this.EmpSalary = EmpSalary;
}
public int getSalary()
{
return EmpSalary;
}
public String toString()
{
return (super.toString() + " " +"Salaried:" + this.Earnings());
}
}
class CommissionEmployee extends Employee
{
private int BaseSalary;
private int NumProductsSold;
private int CommissionPercent;
public CommissionEmployee(String EmpFirstName, String EmpLastName, int BaseSalary, int NumProductsSold, int CommissionPercent )
{
super(EmpFirstName, EmpLastName);
// BaseSalary = 80000;
setBaseSalary(BaseSalary);
setNumProductsSold(NumProductsSold);
setCommissionPercent(CommissionPercent);
// NumProductsSold = 20;
// CommissionPercent = 10;
}
public int Earnings()
{
return BaseSalary;
}
public void setBaseSalary(int BSalary)
{
this.BaseSalary = BaseSalary;
}
public double setBaseSalary()
{
return BaseSalary;
}
public void setNumProductsSold(int NumProducts)
{
this.NumProductsSold = NumProductsSold;
}
public int getNumProductsSold()
{
return NumProductsSold;
}
public void setCommissionPercent(int ComPercent)
{
this.CommissionPercent = CommissionPercent;
}
public int getCommissionPercent()
{
return CommissionPercent;
}
public String toString()
{
return (super.toString() + " " + "Commissioned:" + BaseSalary);
}
}
public class MainEmployee
{
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);
System.out.println("Enter first name of Salary Employee");
String firstName = console.nextLine();
System.out.println("Enter last name");
String lastName = console.nextLine();
System.out.println("Enter salary");
int salary = console.nextInt();
SalaryEmployee Emp = new SalaryEmployee(firstName, lastName, salary);
System.out.println("Enter first name of Commission Employee");
String firstName2 = console.nextLine();
System.out.println("Enter last name");
String lastName2 = console.nextLine();
System.out.println("Enter base salary");
int baseSalary = console.nextInt();
System.out.println("Enter number of products sold");
int prodSold = console.nextInt();
System.out.println("Enter commission %");
int comPer = console.nextInt();
CommissionEmployee ComEmployee = new CommissionEmployee(firstName2, lastName2, baseSalary, prodSold, comPer);
System.out.println(Emp.toString());
System.out.println(ComEmployee.toString());
}
}