1、公司中程序员有姓名、工号、薪水、工作内容(编码)

对给出需求进行数据建模 需求:

1、公司中程序员有姓名、工号、薪水、工作内容(编码)。

2、项目经理除了有姓名、工号、薪水、还有奖金、工作内容(管理)。

分析:程序员和经理不存在着直接继承关系,但是程序员和经理却具有共性内容。可以进行抽取。因为他们都是公司的雇员可以将程序员和经理进行抽取,建立体系。

创建Employee类

public abstract class Employee {
    String name;
    String id;
    double pay;
   public Employee(String name, String id, double pay) {
       this.name = name;
       this.id = id;
       this.pay = pay;
   }   
   public abstract void work();
}
class Programmer extends Employee{
   public Programmer(String name, String id, double pay) {
       super(name, id, pay);
   }
   public void work(){
       System.out.println("程序员疯狂编码");
   }
}
class Manager extends Employee{
   private double bouns;
   public Manager(double bouns, String name, String id, double pay) {
       super(name, id, pay);
       this.bouns = bouns;
   }
   public void work(){
       System.out.println("项目经理谨慎管理");
   }
}

创建Test类

public class Test {
    public void workTest(Employee e){
        e.work();
    }
    public static void main(String[] args) {
        Test t = new Test();
        t.workTest(new Programmer("码农","01",20));
        t.workTest(new Manager(10000,"管理","02",20));
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值