第四题Cola公司的雇员分为以下若干类:(知识点:多态) [必做题]

4.1 ColaEmployee :这是所有员工总的父类,属性:员工的姓名,员工的生日月份。方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。

private String name;
		private int months;
		private int birthday;
		
		
		public String getName() {
			return name;
		}


		public void setName(String name) {
			this.name = name;
		}


		public int getMonths() {
			return months;
		}


		public void setMonths(int months) {
			this.months = months;
		}


		public int getBirthday() {
			return birthday;
		}


		public void setBirthday(int birthday) {
			this.birthday = birthday;
		}


		public ColaEmployee(String name, int months,int birthday) {
			super();
			this.name = name;
			this.months = months;
			this.birthday = birthday;
		}


		void getSalary() {
			
		}

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

private double mone;
	public SalariedEmployee(String name, int months, int birthday,double money) {
		super(name, months, birthday);
		if(super.getMonths()==super.getBirthday()) {
			System.out.println("员工"+name+months+"月的工资为"+(money+100));
		}else {
			System.out.println("员工"+name+months+"月的工资为"+money);
		}
	}

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

	private double hours;
		private int mon;
	public HourlyEmployee(String name, int months, int birthday,double hours,int mon) {
		super(name, months, birthday);
		this.hours=hours;
		this.mon=mon;
		if(super.getBirthday()!=super.getMonths()&&super.getMonths()>=160) {
		System.out.println("员工"+name+months+"月的工资为"+(mon*160+(hours-160)*mon*1.5));
	}else  if(super.getBirthday()==super.getMonths()&&super.getMonths()>=160){
		System.out.println("员工"+name+months+"月的工资为"+(mon*160+(hours-160)*mon*1.5+100));
	}else if(super.getBirthday()==super.getMonths()&&super.getMonths()<160) {
		System.out.println("员工"+name+months+"月的工资为"+(mon*hours+100));
	}else if(super.getBirthday()!=super.getMonths()&&super.getMonths()<160) {
		System.out.println("员工"+name+months+"月的工资为"+mon*hours);
	}
	}

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

private double x;
				private double L;
	public SalesEmployee(String name, int months, int birthday,double x,double L) {
		super(name, months, birthday);
		if(super.getMonths()==super.getBirthday()) {
			System.out.println("员工"+super.getName()+"工资为"+x*L+100);
		}else{
			System.out.println("员工"+super.getName()+"工资为"+x*L);
		}
		
	}

4.5 定义一个类Company,在该类中写一个方法,调用该方法可以打印出某月某个员工的工资数额,写一个测试类TestCompany,在main方法,把若干各种类型的员工放在一个ColaEmployee 数组里,并单元出数组中每个员工当月的工资。

	ColaEmployee[]y=new ColaEmployee[6];
				y[0]=new SalariedEmployee("tofm", 2, 2, 2000);
				y[1]=new HourlyEmployee("tom", 4, 4, 170, 13);
				y[2]=new SalariedEmployee("to", 6, 6, 2000);
				y[3]=new SalariedEmployee("tm", 3, 3, 2000);
				y[4]=new SalesEmployee("tosm", 7, 7, 20000, 0.13);
				y[5]=new SalesEmployee("tmu",8, 8, 20000, 0.13);
  • 8
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
公司员工有经理Manager、技术人员Technicist和营销人员SalsePerson,他们的薪金计算方法如下: 经理按计酬,方法是:基本工资+奖金;技术人员按计酬,方法是:基本工资;营销人员按计酬,方法是:基本工资+销售利润*5%。 每类人员都有职工编号、姓名、性别、入职时间、职位、基本工资等数据,其中为入职时间定义Date类,并为该类重载运算符<<,实现入职时间的输入;各类人员使用统一接口getpay()计算各类人员的薪。其次,设计一个统计并输出该公司每个人员某几个薪金情况的报表类Report,该类提供add接口向Report类的容器中添加员工信息,并提供print接口用于输出每个员工的职工编号、姓名、性别、入职时间、职位和在设定的份时间段中该员工的薪酬额。为了方便实现查找功能,为Report类重载[]运算符的功能,下标值为职位,能根据职位信息查找出所有符合该职位的员工,并重载print接口,输出查找出的员工信息,信息包括职工编号、姓名、性别、入职时间、职位、基本工资。在主函数中对实现的类进行测试,首先,创建各类人员对象,通过Report类的add接口向报表中添加这些人员信息,然后通过Report类的print接口输出报表。其次测试报表的查找功能,输入要查找的员工职位信息,通过Report类的print接口输出查找到的员工基本信息报表。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值