当前位置:首页 > JAVA课程设计 - 员工工资管理(类的继承)
JAVA课程设计——员工工资管理
importjava.util.Scanner; class Employee{ private String name; privateintbirthmonth; public String getName() { returnname; } publicvoidsetName(String name) { this.name = name; } publicintgetBirthmonth() { returnbirthmonth; } publicvoidsetBirthmonth(intbirthmonth) { this.birthmonth = birthmonth; } publicdoublegetSalary(intthismonth){ if(birthmonth==thismonth){ return 100; } else return 0; } publicvoid print(){ System.out.print(\员工信息:\\n姓名:\+name+\,出生月份:\+birthmonth+\,\); } public Employee(String name,intbirthmonth){ setName(name); setBirthmonth(birthmonth); } }
//固定工资
classSalariedEmployeeextends Employee{ privateintsalary; publicSalariedEmployee(String name, intbirthmonth,int salary) { super(name, birthmonth); this.salary=salary; } publicdoublegetSalary(intthismonth) { returnsalary+super.getSalary(thismonth); } publicintbasesalary(){returnsalary;} }
//小时工
classHourlyEmployeeextends Employee{ privateinthoursalary; privateintmonthhour; privateintsalary; publicHourlyEmployee(String name,
intbirthmonth,inthoursalary,intmonthhour) { super(name, birthmonth);
this.hoursalary=hoursalary; this.monthhour=monthhour; this.salary=hoursalary*monthhour; } publicdoublegetSalary(intthismonth) { if(this.getMonthhour()<160){returnsalary+super.getSalary(thismonth); } else {returnsalary+super.getSalary(thismonth)+0.5*this.getHoursalary()*(this.getMonthhour()-160);} } publicintgetHoursalary() { returnhoursalary; } publicintgetMonthhour() { returnmonthhour; } }
//销售人员
classSalesEmployeeextends Employee{ privateintmonthsales; privatedoublepercent; privatedoublesalary; publicSalesEmployee(String name, intbirthmonth,intmonthsales,double percent) { super(name, birthmonth); this.monthsales=monthsales; this.percent=percent; this.salary=monthsales*percent; } publicdoublegetSalary(intthismonth) { returnsalary+super.getSalary(thismonth); } publicintgetMonthsales() { returnmonthsales; } publicdoublegetPercent() { returnpercent; } }
//销售+底薪
classBasePlusSalesEmployeeextendsSalesEmployee{ privateintbasesalary; privatedoublesalary; publicBasePlusSalesEmployee(String name, intbirthmonth,intmonthsales, doublepercent,intbasesalary) { super(name, birthmonth,monthsales, percent); this.basesalary=basesalary; this.salary=monthsales*percent; } publicdoublegetSalary(intthismonth) { returnsuper.getSalary(thismonth)+basesalary;
} publicvoidsetSalary(double salary) { this.salary = salary; } publicintgetBasesalary() { returnbasesalary; } publicvoidsetBasesalary(intbasesalary) { this.basesalary = basesalary; } }
publicclass Work1 { publicstaticvoid main(String[] args) { choice(); } publicstaticvoid choice(){ inttype; int i=1; while(i<2){ Scanner sca=newScanner(System.in); System.out.println(\); System.out.println(\请输入员工类型:***************\); System.out.println(\固定工资)***********\); System.out.println(\小时工)***************\); System.out.println(\销售提成)**************\); System.out.println(\销售提成+底薪)*\); System.out.println(\退出选项*****************************\); System.out.println(\); int x=sca.nextInt(); switch(x) { case 1: SalariedEmployee a=newSalariedEmployee(\张三\,6,3000); a.print(); System.out.print(\基本工资:\+a.basesalary()+\实际工资:\); System.out.println(a.getSalary(6));break; case 2:HourlyEmployee b=newHourlyEmployee(\李四\,6,10,170); b.print(); System.out.print(\每小时工资:\+b.getHoursalary()+\,工作总时间:\+b.getMonthhour()+\,总工资:\); System.out.println(b.getSalary(6));break; case 3:SalesEmployee c=newSalesEmployee(\王五\,6,100000,0.02); c.print(); System.out.print(\销售总额:\+c.getMonthsales()+\,销售提成:\+c.getPercent()+\,总工资:\); System.out.println(c.getSalary(6));break; case 4:BasePlusSalesEmployee d=newBasePlusSalesEmployee(\王五\,6,100000,0.01,1000); d.print();
System.out.print(\销售总额:\+d.getMonthsales()+\,销售提
成:\+d.getPercent()+\,底薪:\+d.getBasesalary()+\,总工资:\); System.out.println(d.getSalary(6));break; case 5: i=5;break; default:System.out.println(\所选择的输出信息有误,请重新输入!!!\);break;
} } } }
共分享92篇相关文档