第十一周作业
package Wxte; public abstract class Car { String name; int month; public Car() { } public Car(String name, int month) { super(); this.name = name; this.month = month; } public double getSalary(int month) { return 0; } }
package Wxte; public class besk extends Car { double monSalary; public besk() { super(); } public besk(String name, int month, double monSalary) { super(name, month); this.monSalary = monSalary; } public double getSalary(int month) { if (super.month == month) { return monSalary + 100; } else { return monSalary; } } }
public class Dsksk extends Car { private int hourSalary; private int hourNum; public Dsksk(String name, int month, int hourSalary, int hourNum) { super(name, month); this.hourSalary = hourSalary; this.hourNum = hourNum; } public double getSalary(int month) { if (super.month == month) { if (hourNum > 160) { return hourSalary * 160 + hourSalary * (hourNum - 160) * 1.5 + 100; } else { return hourSalary * hourNum + 100; } } else { if (hourNum > 160) { return hourSalary * 160 + hourSalary * (hourNum - 160) * 1.5; } else { return hourSalary * hourNum; } } } }
package Wxte; public class Fly extends Car{ private int monthSales; private double royaltyRate; public Fly(String name, int month, int monthSales, double royaltyRate) { super(name, month); this.monthSales = monthSales; this.royaltyRate = royaltyRate; } public double getSalary(int month) { if (super.month == month) { return monthSales * royaltyRate + 100; } else { return monthSales * royaltyRate; } } }
package Wxte; public class Doog { public void getSalary(Car c, int month) { System.out.println(c.name + "在" + month + "月的月薪为" + c.getSalary(month) + "元"); } }
package Wxte; public class Best { public static void main(String[] args) { // TODO Auto-generated method stub Car[] cel = { new besk("Timi", 7, 45000), new Dsksk("按小时拿工资的员工", 6, 100, 300), new Fly("销售人员", 4, 8000000, 0.5) }; for (int i = 0; i < cel.length; i++) { new Doog().getSalary(cel[i], 8); } } }