关于接口,继承,this,super,构造器的综合实例

//Employee

package com.tedu.demo;

/*某五星级酒店,资金雄厚,要招聘多名员工(经理、厨师、服务员)。入职的员工需要记录个人信息(姓名、工号、经理特有奖金属性)。他们都有自己的工作要做。
本案例要完成如下需求:
    获取酒店幸运员工;
    酒店开设VIP服务,酒店的厨师与服务员可以提供VIP服务。(厨师做菜加量、服务员给顾客倒酒)。
    编写测试类
    向酒店中,增加多名员工(其中包含1名经理,1名厨师、2名服务员);
    调用酒店员工的工作功能
    调用酒店员工的VIP服务功能*/


public abstract class Employee {
    private String name ;
    private String Id ;
    
    //定义空参构造器
    public Employee(){
        
    }
    //定义全参构造器
    public Employee(String name,String Id){
        this.name = name;
        this.Id = Id;
    }
    
    //定义抽象方法work()
    public abstract void work();
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getId() {
        return Id;
    }
    public void setId(String id) {
        Id = id;
    }
    
    
}
============================================分割线============================================
//经理类
package com.tedu.demo;


public  class JingLi extends Employee {
    private double jj;
    
    public double getJj() {
        return jj;
    }

    public void setJj(double jj) {
        this.jj = jj;
    }

    public JingLi(String name,String Id,double jj){
        super(name,Id);
    }
    
    public void work() {
        System.out.println("经理在工作");

    }
    
    
}

//服务员类
package com.tedu.demo;


public class FuWuYuan extends Employee implements VIP {
    //定义全参构造器
    public FuWuYuan(String name,String Id){
        super(name,Id);
    }
    //服务员的VIP服务
    public void servces(){
        System.out.println("服务员VIP就是倒酒");
    }
    //服务员自己的方法
    public void work() {
        System.out.println("服务员端菜");
    }

}


//厨师类
package com.tedu.demo;

public class Cookeis extends Employee implements VIP {

    public Cookeis(String name,String Id){
        super(name,Id);
    }
    
    public void servces() {
        System.out.println("厨师VIP夹菜");

    }

    
    public void work() {
        System.out.println("厨师正在炒菜");

    }

}

//接口
package com.tedu.demo;

/*
 * 酒店开设VIP服务,酒店的厨师与服务员可以提供VIP服务。(厨师做菜加量、服务员给顾客倒酒)。
 */

public interface VIP {
    public abstract void servces();

}

//测试类
package com.tedu.demo;

import java.util.ArrayList;

public class Test {

    public static void main(String[] args) {
        ArrayList<Employee> arr = new ArrayList<Employee>();
        
        
        JingLi j = new JingLi("张三","管理层001",1234.44);
        j.work();
        
        FuWuYuan f = new FuWuYuan("翠花", "后勤003");
        f.work();
        f.servces();
        
        FuWuYuan w = new FuWuYuan("端菜", "后勤004");
        w.work();
        f.servces();
        
        Cookeis  c = new Cookeis("李四", "后勤007");
        c.work();
        c.servces();
        
        arr.add(j);
        arr.add(f);
        arr.add(w);
        arr.add(c);
        
        lucklyEmployee(arr);
        
    }
    
    //抽取幸运员工
    public static void lucklyEmployee(ArrayList<Employee> arr){
        int index = 0;
        for(int i=0;i<arr.size();i++){
            index = (int )(Math.random()*arr.size());
            
        }
        Employee ee = arr.get(index);
        System.out.println("幸运员工是:"+ee.getName()+ee.getId());
    }

}

 

posted @ 2017-06-19 20:45  M_S_N  阅读(381)  评论(0编辑  收藏  举报