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

来源:互联网 发布:微信营销数据分析 编辑:程序博客网 时间:2024/05/21 10:20
/*
练习:
假如我们开发一个系统时
需要对员工进行建模 员工包含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);}}



阅读全文
0 0
原创粉丝点击