0% found this document useful (0 votes)
38 views2 pages

employee Constructor: Employee Scanner Scanner System String String

The document defines an abstract Employee class with name and ID attributes and getter/setter methods. It also defines two subclasses: PartTimeEmp which extends Employee and includes hourly rate and hours worked, and FullTimeEmp which extends Employee and includes a salary attribute. Both subclasses override the toString method.

Uploaded by

avishana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

employee Constructor: Employee Scanner Scanner System String String

The document defines an abstract Employee class with name and ID attributes and getter/setter methods. It also defines two subclasses: PartTimeEmp which extends Employee and includes hourly rate and hours worked, and FullTimeEmp which extends Employee and includes a salary attribute. Both subclasses override the toString method.

Uploaded by

avishana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

public abstract class Employee {

Scanner keyboard = new Scanner(System.in);


public String name;
public String ID;

//Employee constructor
public Employee(String name, String ID) {
this.name = name;
this.ID = ID;
}

//ID setter
public void setID(String ID) {
ID = keyboard.nextLine();
this.ID = ID;
}

//name getter
public String getName() {
return name;
}

public abstract String getStatus();

public abstract double calculateMonthlyPay();

@Override
public String toString() {
return "Employee{" + "name=" + name + ", ID=" + ID + '}';
}
}

class PartTimeEmp extends Employee {


public double hourlyRate;
public int hoursPerWeek;
//PartTimeEmp constructor
public PartTimeEmp(String name, String ID){
super(name, ID);
}

public void setHours(int hoursPerWeek) {


this.hoursPerWeek = hoursPerWeek;
}

public void setRate(double hourlyRate) {


this.hourlyRate = hourlyRate;
}

@Override
public String toString() {
return "PartTimeEmp{" + "hourlyRate=" + hourlyRate + ", hoursPerWeek=" + hoursPerWeek + '}';
}
}

class FullTimeEmp extends Employee {


double salary;
//FullTimeEmp constructor
public FullTimeEmp(String name, String ID) {
super(name, ID);
}

//Set salary of employee


public void setSalary(double salary) {
this.salary = salary;
}

@Override
public String toString() {
return "FullTimeEmp{" + "salary=" + salary + '}';
}
}

You might also like