Cola公司的雇员分为以下若干类:(知识点:多态)
(1) ColaEmployee :这是所有员工总的父类,属性:员工的姓名,员工的生日月份。
- 方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。
(2) SalariedEmployee : ColaEmployee 的子类,拿固定工资的员工。
- 属性:月薪
(3)
:ColaEmployee 的子类,按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。
- 属性:每小时的工资、每月工作的小时数
(4) SalesEmployee :ColaEmployee 的子类,销售人员,工资由月销售额和提成率决定。
- 属性:月销售额、提成率
(5) 定义一个类Company,在该类中写一个方法,调用该方法可以打印出某月某个员工的工资数额,写一个测试类TestCompany,在main方法,把若干各种类型的员工放在一个ColaEmployee 数组里,并单元出数组中每个员工当月的工资。
package shizhousj; public class ColaEmployee { static String name; static int month; static int ebirth; static int ticheng; static int gz; public static int getGz() { return gz; } public void setGz(int gz) { this.gz = gz; } public static void getsalary(int month){ if(month==ebirth){ System.out.println("happ birthday"); ticheng=100; } } public ColaEmployee() { super(); // TODO Auto-generated constructor stub } public ColaEmployee(String name, int month) { super(); this.name = name; this.month = month; } public static String getName() { return name; } public void setName(String name) { this.name = name; } public static int getMonth() { return month; } public void setMonth(int month) { this.month = month; } public static int getEbirth() { return ebirth; } public static void setEbirth(int ebirth) { ColaEmployee.ebirth = ebirth; } public static int getTicheng() { return ticheng; } public static void setTicheng(int ticheng) { ColaEmployee.ticheng = ticheng; } public static void show(){ if(month==ebirth){ System.out.println(getName()+getMonth()+"月的工资是"+(getGz()+ticheng)); }else { System.out.println(getName()+getMonth()+"月的工资是"+getGz()); } } }
package shizhousj; public class SalariedEmployee extends ColaEmployee { static int gz=3500; public SalariedEmployee() { super(); // TODO Auto-generated constructor stub } public SalariedEmployee(String name, int month,int ebirth) { super(name, month); // TODO Auto-generated constructor stub } }
package shizhousj; public class HourlyEmployee extends ColaEmployee{ int hour; int hournum; int gz=hour*hournum; public HourlyEmployee() { super(); // TODO Auto-generated constructor stub } public HourlyEmployee(String name,int month,int ebirth,int hour, int hournum) { super(); this.hour = hour; this.hournum = hournum; } }
package shizhousj; public class SalesEmployee extends ColaEmployee{ int yue; int ticl; int gz=yue*ticl; public SalesEmployee() { super(); // TODO Auto-generated constructor stub } public SalesEmployee(String name,int month,int ebirth,int yue, int ticl) { super(); this.yue = yue; this.ticl = ticl; } }
package shizhousj; public class Company extends ColaEmployee { public void getSalary(ColaEmployee colaEmployee, int month) { // TODO Auto-generated method stub } }
package shizhousj; public class textCompany { public static void main(String[] args) { // TODO Auto-generated method stub SalariedEmployee ss= new SalariedEmployee("AA",5,12); HourlyEmployee hh=new HourlyEmployee("DD",5,7,24, 154); SalesEmployee sse=new SalesEmployee("SA",5,6,3600,1); ss.show(); hh.show(); sse.show(); } }