java编程---某公司的雇员分为以下若干类:Employee:这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:getSalary(intmonth)根据参数月份来确定工资。

题目:
某公司的雇员分为以下若干类:
Employee:这是所有员工总的父类,
属性:
员工的姓名,员工的生日月份。
方法:getSalary(intmonth)
根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。

SalariedEmployee:
	Employee 的子类,拿固定工资的员工。
	属性:月薪

HourlyEmployee: 
	Employee 的子类, 按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。
	属性:每小时的工资、每月工作的小时数

SalesEmployee:
	Employee 的子类,销售人员,工资由月销售额和提成率决定。 
	属性:月销售额、提成率

BasePlusSalesEmployee:
	SalesEmployee 的子类,有固定底薪的销售人员,工资 由底薪加上销售提成部分。
	属性:底薪。

根据要求创建 SalariedEmployee 、 HourlyEmployees 、SaleEmployee 和 BasePlusSalesEmployee四个类的对象各一个,
并计算某个月这四个对象的工资。

注意:要求把每个类都做成完全封装,不允许非私有化属性。
//Employee类
public class Employee{
	private String name;
	private int month;
	private double salary;
    //无参构造函数
	public Employee(){

	}
	//有参构造函数
	public Employee(String name,int month,double salary){
		this.name=name;
		this.month=month;
		this.salary=salary;
	}
	public void setName(String name){
		this.name=name;
	}
	public String getName(){
		return name;
	}
	public void setMonth(int month){
		this.month=month;
	}
	public int getMonth(){
		return month;
	}
	public void setSalary(double salary){
		this.salary=salary;
	}
	public double getSalary(){
		return salary;
	}

	public double getSalary(int month){
		if(this.month == month){
			salary += 100;
		}
		System.out.println("员工"+ getName()+"的薪水为:"+salary);
		return salary;
	}
}
//SalariedEmployee类
public class SalariedEmployee extends Employee{
	private double salary1;
	 //无参构造函数
	public  SalariedEmployee(){

	}
	//有参构造函数
	public  SalariedEmployee(double salary1){
		this.salary1=salary1;
	}
	public void setSalary1(double salary1){
		this.salary1=salary1;
	}
	public double getSalary1(){
		return salary1;
	}

	public double getSalary(int month){		
		if(this.getMonth() == month){
			salary1 += 100;
		}
		System.out.println("该员工"+getName()+"的薪水为:"+salary1);
		return salary1;
	}	

}
//HourlyEmployee类
public class HourlyEmployee extends Employee{
	private int hour;
	private double price;
	private double salary2;
	//无参构造函数
	public  HourlyEmployee(){

	}
	//有参构造函数
	public  HourlyEmployee(int hour,double price,double salary2){
		this.hour=hour;
		this.price=price;
		this.salary2=salary2;
	}
	public void setHour(int hour){
		this.hour=hour;
	}
	public int getHour(){
		return hour;
	}
	public void setPrice(double price){
		this.price=price;
	}
	public double getPrice(){
		return price;
	}
	public void setSalary2(double salary2){
		this.salary2=salary2;
	}
	public double getSalary2(){
		return salary2;
	}

	public double getSalary(int month){
		
		if( hour <= 160){
			salary2=price * hour;
		}
		else{
			hour=hour-160;
			salary2=160 * price + hour *1.6*price;
		}
		if(getMonth() == month){
			salary2+=100;
		}
		System.out.println("该员工"+getName()+"的薪水为:"+salary2);
		return salary2;
	}
	

}
//SalesEmployee类
public class SalesEmployee extends Employee{
	private double salemonth;
	private double rate;
	//无参构造函数
	public  SalesEmployee(){

	}
	//有参构造函数
	public SalesEmployee(double salemonth,double rate){
		this.salemonth=salemonth;
		this.rate=rate;
	}
	public void setSalemonth(double salemonth){
		this.salemonth=salemonth;
	}
	public double getSalemonth(){
		return salemonth;
	}
	public void setRate(double rate){
		this.rate=rate;
	}
	public double getRate(){
		return rate;
	}
	public double getSalary(int month){
		if(this.getMonth() == month){
		System.out.println("该员工"+getName()+"的薪水为:"+(100+salemonth*rate));
		return (salemonth * rate)+100;
		}else{
		System.out.println("该员工"+getName()+"的薪水为:"+salemonth * rate);
		return salemonth * rate;
		}
	}
	
}
//BasePlusSalesEmployee类
public class BasePlusSalesEmployee extends Employee{
	private double minsalary;
	private double salemonth1;
	private double rate1;

	//无参构造函数
	public  BasePlusSalesEmployee(){

	}
	//有参构造函数
	public BasePlusSalesEmployee(double minsalary,double salemonth1,double rate1){
		this.minsalary=minsalary;
		this.salemonth1=salemonth1;
		this.rate1=rate1;
	}
	public void setMinsalary(double minsalary){
		this.minsalary=minsalary;
	}
	public double getMinsalary(){
		return minsalary;
	}
	public void setSalemonth1(double salemonth1){
		this.salemonth1=salemonth1;
	}
	public double getSalemonth1(){
		return salemonth1;
	}
	public void setRate1(double rate1){
		this.rate1=rate1;
	}
	public double getRate1(){
		return rate1;
	}
	public double getSalary(int month){
		if(this.getMonth() == month){
			System.out.println("该员工"+getName()+"的薪水为:"+(minsalary+salemonth1*rate1+100));
			return minsalary+salemonth1*rate1+100;
		}
		System.out.println("该员工"+getName()+"的薪水为:"+(minsalary+salemonth1*rate1));
		return minsalary+salemonth1*rate1;
	}
}
//某公司
public class test{
	public static void main(String[] args){
		Employee e1 = new Employee("张三",9,0);
		e1.getSalary(6);
		SalariedEmployee s1 = new SalariedEmployee();
		s1.setName("李四");
		s1.setSalary1(6300);
		s1.setMonth(6);
		s1.getMonth();
		s1.getSalary(6);
		HourlyEmployee h1 = new HourlyEmployee(192,36,0);
		h1.setName("王二");
		h1.setMonth(6);
		h1.getMonth();
		h1.getSalary(6);
		SalesEmployee ss1 = new SalesEmployee(26000,0.4);
		ss1.setName("陈一");
		ss1.setMonth(9);
		ss1.getMonth();
		ss1.getSalary(6);
		//System.out.println("该员工"+ss1.getName()+"的薪水为:"+ss1.getSalary(6));
		BasePlusSalesEmployee b1 =new BasePlusSalesEmployee(3000,9000,0.5);
		b1.setName("刘六");
		b1.setMonth(9);
		b1.getMonth();
		System.out.println("输出刘六的生日月份:"+b1.getMonth());
		b1.getSalary(9);

	}
}

运行结果:
截图

  • 32
    点赞
  • 158
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值