练习1 某公司的雇员分为以下若干类

1 /*某公司的雇员分为以下若干类: 2 Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。 3 SalariedEmployee:Employee的子类,拿固定工资的员工。属性:月薪 4 HourlyEmployee:Employee的子类,香港服务器租用,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。属性:每小时的工资、每月工作的小时数 5 SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率 6 BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。属性:底薪。 7 写一个程序,把若干各种类型的员工放在一个Employee数组里,香港服务器,写一个方法,香港虚拟主机,打印出某月每个员工的工资数额。注意:要求把每个类都做成完全封装,不允许非私有化属性。 Employee 14 {month;Employee(String name,int month) 19 { 20this.setName(name); 21this.setMonth(month); 22 }getSalary(int month) 25 {(month==this.month)?100:0; 28 } String getName() 31 { 32return name; 33 } setName(String name) 36 { 37this.name = name; 38 } getMonth() 41 { 42return month; 43 }setMonth(int month) 46 { 47this.month = month; 48 }}SalariedEmployee extends Employee 56 {monthPay; SalariedEmployee(String name,int month,double monthPay) 60 { 61super(name,month); 62this.setMonthPay(monthPay); 63 }getSalary(int month) 66 {.getMonthPay() + super.getSalary(month); 68 } getMonthPay() 71 { 72return monthPay; 73 }setMonthPay(double monthPay) 76 { 77this.monthPay = monthPay; 78 } 79 }HourlyEmployee extends Employee 84 {hour;hourPay; HourlyEmployee(String name,int month,int hour,int hourPay) 89 { 90super(name,month); 91this.setHour(hour); 92this.setHourPay(hourPay); 93 }getSalary(int month) 96 { 97if(hour>16) 98 { 99return 160*(this.getHourPay()) + (this.getHourPay())*1.5*(hour-160)+super.getSalary(month);100 }{103return hour*this.getHourPay()+super.getSalary(month);104 }105 } getHour()108 {109return hour;110 }setHour(int hour)113 {114this.hour = hour;115 } getHourPay()118 {119return hourPay;120 }setHourPay(double hourPay)123 {124this.hourPay = hourPay;125 }}SalesEmployee extends Employee132 {monthSales; rate; SalesEmployee(String name,int month,int monthSales,double rate)137 {138super(name,month);139this.setMonthSales(monthSales);140this.setRate(rate);141 }getSalary(int month)144 {.getRate()*this.getMonthSales() + super.getSalary(month);146 } getMonthSales()149 {150return monthSales;151 }setMonthSales(int monthSales)154 {155this.monthSales = monthSales;156 } getRate()159 {160return rate;161 }setRate(double rate)164 {165this.rate = rate;166 }}BasePlusSalesEmployee extends SalesEmployee174 { basePay;BasePlusSalesEmployee(String name,int month,int monthSales,double rate,double basePay)178 {179super(name,month,monthSales,rate);180this.setBasePay(basePay);181 }getSalary(int month)184 {.getSalary(month)+basePay;186 } getBasePay()189 {190return basePay;191 }setBasePay(double basePay)194 {195this.basePay = basePay;196 }} Test203 { main(String args[])205 {206Employee a[] = new Employee[4];207 208a[0] = new SalariedEmployee(“张三”, 2, 1000);209a[1] = new HourlyEmployee(“李四”, 3, 200, 2000);210a[2] = new SalesEmployee(“王五”, 4, 50000, (float) 0.1);211a[3] = new BasePlusSalesEmployee(“小明”, 5, 50000, (float) 0.1, 1000);212 213System.out.println(“张三的工资为” + a[0].getSalary(2));214System.out.println(“李四的工资为” + a[1].getSalary(2));215System.out.println(“王五的工资为” + a[2].getSalary(2));216System.out.println(“小明的工资为” + a[3].getSalary(2));217 218 }219 }人只要不失去方向,就不会失去自己

练习1 某公司的雇员分为以下若干类

相关文章:

你感兴趣的文章:

标签云: