继承练习 :开发一个系统时 需要对员工进行建模 员工包含3个属性 姓名 工号 工资 功能 work

/*
练习:
假如我们开发一个系统时
需要对员工进行建模 员工包含3个属性 姓名 工号 工资 功能 work
经理 也是员工 除了含有员工的属性外 另外还有一个奖金属性
请用继承的思想设计出 员工类 和 经理类 要求类中提供必要的方法进行属性访问
work 输出内容 是 姓名 工号 工资 有奖金 输出奖金 没奖金 就不输出奖金


分析:
经理是员工 但 经理和普通员工 工作不同 并且多了个奖金

*/



package Day10;
public class Test_03 {

	public static void main(String[] args) {
		//员工类:工号\职位\姓名\工资
		//经理级:奖金  (奖金和加班费分别用set和get是因为输错,所以单独输入)
		//后勤:加班费
		Manager s1 = new Manager("0001","总经理","张华",5000);
		s1.setBonus(500);//经理级奖金
		s1.work();
		
		Manager s2 = new Manager("0002","副经理","李小",4500);
		s2.setBonus(350);//经理级奖金
		s2.work();
		
		GeneralStaff s3 =new GeneralStaff("1000","后勤主管","叶斯",3300);
		s3.setOverTimePay(1000);//加班费
		s3.work();
		
		GeneralStaff s4 =new GeneralStaff("1001","后勤员工","雷五",2800);
		s4.setOverTimePay(1000);//加班费
		s4.work();
		
	}

}

class Manager extends Staff {//经理级
	public Manager(String id, String position, String name, double salary) {
		super(id, position, name, salary);
	}

	private double bonus;// 奖金

	 public void setBonus(double bonus) {
	 this.bonus = bonus;
	 }

	public void work() {
		super.work();
		System.out.println(";奖金:"+ bonus);
	}

}

class GeneralStaff extends Staff {// 普通员工类
	public GeneralStaff(String id, String position, String name, double salary) {
		super(id, position, name, salary);
		// TODO Auto-generated constructor stub
	}

	private double overtimepay;// 加班费
	
	public void setOverTimePay(double overtimepay) {
		this.overtimepay = overtimepay;
	}

	public void work() {
		super.work();
		System.out.println(";加班费:"+overtimepay);
	}
}

class Staff {// 员工类
	private String id;// 工号
	private String position;// 职位
	private String name;// 姓名
	private double salary;// 工资
	
		
	public Staff(String id, String position, String name, double salary) {
		super();
		this.id = id;
		this.position = position;
		this.name = name;
		this.salary = salary;
	}

	public void work() {
		System.out.print("工号:" + id + ";职位:" + position + ";姓名:" + name + ";工资:" + salary);
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值