//看看这样行吗?以前做过这道题
public class EmployeeTest {
public static void main(String[] args) {
Employee e1 = new SalariedEmployee(200);
System.out.println("工资为:"+e1.salary());
Employee e2 = new HourlyEmployee(50, 100);
System.out.println("工资为:"+e2.salary());
Employee e3 = new CommissionEmployee(1000, 0.5);
System.out.println("工资为:"+e3.salary());
Employee e4 = new BCommissionEmployee(200, 2000,0.3);
System.out.println("工资为:"+e4.salary());
}
}
class Employee {
public double salary(){
return 0;
}
}
class SalariedEmployee extends Employee{
double s;//基本工资
public SalariedEmployee(double s){
this.s = s;
}
public double salary(){
return s;
}
}
class HourlyEmployee extends Employee{
double time;
double s;
public HourlyEmployee(double s,double time){
this.s = s;
this.time = time;
}
public double salary(){
if(time < 40)
return s*time;
return (time - 40)*1.5*s+40*s;
}
}
class CommissionEmployee extends Employee{
double results;
double rate;
public CommissionEmployee(double results,double rate){
this.results = results;
this.rate = rate;
}
public double salary(){
return results*rate;
}
}
class BCommissionEmployee extends Employee{
double s;
double results;
double rate;
public BCommissionEmployee(double s,double results,double rate){
this.s = s;
this.results = results;
this.rate = rate;
}
public double salary(){
return results*rate+s;
}
}
追问好滴谢谢
我看哈
本回答被提问者和网友采纳