Re: Absract class and its sub clases
<teshmee@gmail.com> wrote:
hi,
this is the coding for abstract class Worker... Can anyone help me
with the codes for the subclass ParttimeWorker as the code below the
abstract class doesnt really work while i compile.
public class TestParttime {
public static void main(String[] args) {
ParttimeWorker w = new ParttimeWorker("5.15", '1', 40, 1);
w.calculate();
System.out.println(w.weeklySalary());
}
}
public abstract class Worker{
protected String name;
protected double salaryRate;
public String getName(){
return name;
}
public double getSalaryRate(){
return salaryRate;
}
public void setName(String n) {
name = n;
}
public void setSalaryRate(double sal){
salaryRate = sal;
}
public abstract double weeklySalary();
}
public class ParttimeWorker extends Worker{
private double salaryRate;
char type;
int normalHours;
int extraHours;
private double salary;
public ParttimeWorker(String salaryRate,
char type,
int normalHours,
int extraHours){
this.salaryRate = Double.parseDouble(salaryRate);
this.type = type;
this.normalHours = normalHours;
this.extraHours = extraHours;
}
public double getSalaryRate(){
return salaryRate;
}
public char getType(){
return type;
}
public int getNormalHours(){
return normalHours;
}
public int getExtraHours(){
return extraHours;
}
public void setSalaryRate(double s){
salaryRate = s;
}
public void setType(char t){
type = t;
}
public void setNormalHours(int n){
normalHours = n;
}
public void setExtraHours(int e){
extraHours = e;
}
public void calculate(){
if (this.normalHours > 40)
this.salary = (this.extraHours * 1.5) +
(this.normalHours * this.salaryRate);
else
this.salary = this.normalHours * this.salaryRate;
}
public double weeklySalary(){
// TODO Auto-generated method stub
return 0;
}
}