10、某公司的雇员分为以下若干类:
Employee:这是所有员工总的父类,属性:员工的姓名和生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,
则公司会额外奖励100元。
SalariedEmployee:Employee的子类,拿固定工资的员工。属性:月薪
HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160
小时的部分按照1.5倍工资发放
属性:每小时的工资、每月工作的小时数
SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定
属性:月销售额、提成率
BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,
工资由底薪加上销售提成部分 属性:底薪。
要求输出某月的工资表:
public class Employee {//员工类(父类)
private String name="未入职"; //定义name属性
private int month;//定义month属性
public Employee(){//无参构造方法
}
public Employee(String name,int month){//定义一个三个参数的构造函数
this.name=name;
this.month=month;
}
public String getName() {
return name;
}
public int getmonth() {
return month;
}
public double getSalary(int month) {//总工资计算方法
//如果月份为员工生日月份,则增加100的
if (month == this.month) {
return 100;
}
else {
return 0;
}
}
public static void main(String args[])
{
Employee p=new Employee("zhangsan",5);
SalariedEmployee p1=new SalariedEmployee("张三",5,4500);
System.out.println("SalariedEmployeel 类员工:\n"+"雇员姓名:"+p1.getName()+"\t生日月份:"
+p1.getmonth()+"\t\t月薪:"+p1.getmonthlypay()+"\t总工资"+p1.getSalary(5));
System.out.println();
HourlyEmployee p2=new HourlyEmployee("程思",8,18.0,234.6);
System.out.println("HourlyEmployee 类员工:\n"+"雇员姓名:"+p2.getName()+"\t生日月份:"
+p2.getmonth()+"\t\t每小时工资:"+p2.gethoursmoney()+"\t每月工作小时:"+p2.gethours()+"\t总工资"+p2.getSalary(5));
System.out.println();
SalesEmployee p3=new SalesEmployee("王五",3,50000,0.25);
System.out.println("SalesEmployee 类员工:\n"+"雇员姓名:"+p3.getName()+"\t生日月份:"
+p3.getmonth()+"\t\t月销售额:"+p3.getmonthsell()+"\t提成:"+p3.getbonus()+"\t总工资"+p3.getSalary(5));
System.out.println();
BasePlusSalesEmployee p4=new BasePlusSalesEmployee("赵柳",9,2000,0.25,2500);
System.out.println("BasePlusSalesEmployee 类员工:\n"+"雇员姓名:"+p4.getName()+"\t生日月份:"
+p4.getmonth()+"\t\t月销售额:"+p4.getmonthsell()+"\t提成:"+p4.getbonus()+"\t底薪:"+p4.getbasepay()+"\t总工资"+p4.getSalary(5));
}
}
//月工资员工
class SalariedEmployee extends Employee {
private double monthlypay; //定义月薪属性
public SalariedEmployee(){ //无参构造方法
}
public SalariedEmployee(String name,int month,double monthlypay ){//有参构造方法
super(name,month);
this.monthlypay=monthlypay;
}
public double getmonthlypay() {
return monthlypay;
}
public double getSalary(int month) {//总工资计算方法
return monthlypay + super.getSalary(month);
}
}
//小时工
class HourlyEmployee extends Employee{
private double hoursmoney;//定义小时属性
private double hours; //
public HourlyEmployee(){//无参构造
}
public double gethoursmoney() {
return hoursmoney;
}
public double gethours() {
return hours;
}
public HourlyEmployee(String name,int month,double hoursmoney,double hours){
super(name,month);
this.hoursmoney=hoursmoney;
this.hours=hours;
}
public double getSalary(int month) {//总工资计算方法
if (hours > 160) {
return (double) (hoursmoney * 160 + (hours - 160) * hoursmoney * 1.5
+ super.getSalary(month));
}
else {
return hoursmoney * hours + super.getSalary(month);
}
}
}
//销售人员
class SalesEmployee extends Employee{
private double monthsell;//月销售额属性
private double bonus; //提成率属性
SalesEmployee(){//无参构造
}
SalesEmployee(String name,int month,double monthsell,double bonus){//有参构造
super(name,month);
this.monthsell=monthsell;//定义销售额属性
this.bonus=bonus;//定义提成属性
}
public double getmonthsell(){
return monthsell;
}
public double getbonus(){
return bonus;
}
public double getSalary(int month) {//总工资计算方法
return monthsell*bonus + super.getSalary(month);
}
}
//有底薪的销售员
class BasePlusSalesEmployee extends SalesEmployee{
private double basepay;//底薪属性
public BasePlusSalesEmployee(){
}
public BasePlusSalesEmployee(String name,int month,double monthsell,
double bonus,double basepay){
super(name,month,monthsell,bonus);
this.basepay=basepay;
}
public double getbasepay(){
return basepay;
}
public double getSalary(int month) {//有底薪的销售员
return basepay + super.getSalary(month);
}
}