第十一周作业
1.
package test; public class ColaEmployee { String name; int month; public ColaEmployee() { super(); } public ColaEmployee(String name, int month) { super(); this.name = name; this.month = month; } public double getSalary(int month){ return month; } }
2.
package test; public class SalariedEmployee extends ColaEmployee { double monthsalary ; public SalariedEmployee() { super(); } public SalariedEmployee(String name, int mouth ,double monthsalary) { super(name, mouth); this.monthsalary = monthsalary; } @Override public double getSalary(int month) { if (super.month == month) { return monthsalary + 100; } else { return monthsalary; } } }
3.
package test; public class HourlyEmployee extends ColaEmployee { int hourSalary; int hour; public HourlyEmployee() { super(); } public HourlyEmployee(String name, int month, int hourSalary, int hour) { super(name, month); this.hourSalary = hourSalary; this.hour = hour; } @Override public double getSalary(int month) { if(super.month == month){ if (hour > 160) { return hourSalary * 160+ (hour-160)*1.5*hourSalary + 100; } else { return hourSalary * hour + 100; } }else{ if (hour > 160) { return hourSalary * 160 +(hour - 160)*1.5*hourSalary ; } else { return hourSalary * hour; } } } }
4.
package test; public class SalesEmployee extends ColaEmployee { double monthsalary; double monthcommission ; public SalesEmployee() { super(); } public SalesEmployee(String name,int month,double monthsalary, double monthcommission) { super(name,month); this.monthsalary = monthsalary; this.monthcommission = monthcommission; } @Override public double getSalary(int month) { if (super.month == month) { return monthsalary*monthcommission + 100; } else { return monthsalary*monthcommission; } } }
5.
package test; public class Company { public void getSalary(ColaEmployee c, int month) { System.out.println(c.name + "在" + month + "月的月薪是:" + c.getSalary(month) + "元"); } }
6.
package test; public class TestCompany { public static void main(String[] args) { ColaEmployee[] cel = { new SalariedEmployee("按月数计算的员工", 5, 5000), new HourlyEmployee("按天数计算的员工", 10, 300,70), new SalesEmployee("按小时计算的员工", 15, 50, 100) }; for (int i = 0; i < cel.length; i++) { new Company().getSalary(cel[i],3); } } }