Java面向对象实践--开发团队调度软件(二)

简介: Java面向对象实践--开发团队调度软件(二)

三、代码实现



项目结构


image.png


工具类


用来读取键盘的输入


package com.caq.team.view;
import java.util.Scanner;
/**
 * @ClassName TSUtility01
 * @Description 工具类,用来读取用户的输入
 * @Author Jack
 * @Date 2021/11/8 8:01
 * @Version 1.0
 */
public class TSUtility {
    //System.in作为参数传递给Scanner的构造函数,使Scanner用键盘作为输入,然后用new在内存中实例化一个Scanner出来,使得其它变量能调用这块内存区。
    private static Scanner scan = new Scanner(System.in);
    /**
     * 用来接受用户输入的方法
     * @param limit
     * @param blackReturn
     * @return
     */
    private static String readKeyBoard(int limit, boolean blackReturn) {
        String line = "";
        while (scan.hasNext()) {
            line = scan.nextLine();
            if (line.length() == 0) {
                if (blackReturn) {
                    return line;
                } else continue;
            }
            if (line.length() < 1 || line.length() > limit) {
                System.out.println("输入长度不大于(不大于" + limit + ")" + "请重新输入");
                continue;
            }
            break;
        }
        return line;
    }
    /**
     * 读取菜单中的选项
     * @return 1,2,3,4数字
     */
    public static char readMenuSelection() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' && c != '3' && c != '4'){
                System.out.println("输入错误,请重新输入");
            }else break;
        }
        return c;
    }
    /**
     * 提升并等待,直到用户按回车后返回
     */
    public static void readReturn(){
        System.out.println("按回车继续........");
        readKeyBoard(100,true);
    }
    /**
     * 读取字符串,将字符串转化为int类型的数
     * @return 一个整数
     */
    public static int readInt(){
        int n;
        for (;;){
            String str = readKeyBoard(2,false);
            // parseInt(String s) 将字符串参数解析为带符号的十进制整数。
            try {
                n = Integer.parseInt(str);
                break;
            }catch (NumberFormatException e){
                System.out.println("数字输入错误,请重新输入");
            }
        }
        return n;
    }
    /**
     * 从键a盘读取Y和N,并将其作为返回值
     * @return
     */
    public static char readConfirmSelection(){
        char c;
        for (;;){
            String str = readKeyBoard(1,false);
            c = str.charAt(0);
            if (c == 'Y' || c == 'N'){
                break;
            }else {
                System.out.println("请输入Y或N!");
            }
        }
        return c;
    }
}


Data类

存放用户的信息


package com.caq.team.service;


public class Data {
    //一些常量
    public static final int EMPLOYEE = 10;
    public static final int PROGRAMMER = 11;
    public static final int DESIGNER = 12;
    public static final int ARCHITECT = 13;
    public static final int PC = 21;
    public static final int NOTEBOOK = 22;
    public static final int PRINTER = 23;
    //Employee  :  10, id, name, age, salary
    //Programmer:  11, id, name, age, salary
    //Designer  :  12, id, name, age, salary, bonus(分红)
    //Architect :  13, id, name, age, salary, bonus, stock(股票)
    //定义二维数组,用来存放职员信息
    //格式为:二维数组存放数据类型[][] 数组名 = {{},{},{}...}
    public static final String[][] EMPLOYEES = {
        {"10", "1", "马云云", "22", "3000"},
        {"13", "2", "马化腾", "32", "18000", "15000", "2000"},
        {"11", "3", "李彦宏", "23", "7000"},
        {"11", "4", "刘强东", "24", "7300"},
        {"12", "5", "雷军军", "28", "10000", "5000"},
        {"11", "6", "任志强", "22", "6800"},
        {"12", "7", "柳传志", "29", "10800","5200"},
        {"13", "8", "杨元庆", "30", "19800", "15000", "2500"},
        {"12", "9", "史玉柱", "26", "9800", "5500"},
        {"11", "10", "丁磊磊", "21", "6600"},
        {"11", "11", "张朝阳", "25", "7100"},
        {"12", "12", "杨致远", "27", "9600", "4800"}
    };
    //如下的EQUIPMENTS数组与上面的EMPLOYEES数组元素一一对应
    //PC      :21, model, display
    //NoteBook:22, model, price
    //Printer :23, name, type 
    public static final String[][] EQUIPMENTS = {
        {},
        {"22", "联想T4", "6000"},
        {"21", "戴尔", "NEC17寸"},
        {"21", "戴尔", "三星 17寸"},
        {"23", "佳能 2900", "激光"},
        {"21", "华硕", "三星 17寸"},
        {"21", "华硕", "三星 17寸"},
        {"23", "爱普生20K", "针式"},
        {"22", "惠普m6", "5800"},
        {"21", "戴尔", "NEC 17寸"},
        {"21", "华硕","三星 17寸"},
        {"22", "惠普m6", "5800"}
    };
}


Equipment接口

package com.caq.team.domain;


public interface Equipment {
    //接口中的方法默认修饰为public abstract,可省略
    String getDescription();
}


PC


实现Equipment接口,返回PC的信息


package com.caq.team.domain;


public class PC implements Equipment{
    private String model;
    private String display;
    public PC() {
    }
    public PC(String model, String display) {
        this.model = model;
        this.display = display;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public String getDisplay() {
        return display;
    }
    public void setDisplay(String display) {
        this.display = display;
    }
    @Override
    public String getDescription() {
        return model + "(" + display + ")";
    }
}


Printer


实现Equipment接口,返回Printer的信息


package com.caq.team.domain;


/**
 * @ClassName Printer
 * @Description TODO
 * @Author Jack
 * @Date 2021/11/8 11:11
 * @Version 1.0
 */
public class Printer implements Equipment {
    private String name;
    private String type;
    public Printer() {
    }
    public Printer(String name, String type) {
        this.name = name;
        this.type = type;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    @Override
    public String getDescription() {
        return name + "(" + type + ")";
    }
}


NoteBook


实现Equipment接口,返回NoteBook的信息


package com.caq.team.domain;


public class NoteBook implements Equipment {
    private String model;   //机器型号
    private double price;   //价格
    public NoteBook() {
    }
    public NoteBook(String model, double price) {
        this.model = model;
        this.price = price;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    @Override
    public String getDescription() {
        return model + "(" + price + ")";
    }
}


Employee对象


将Data类中数组的数据取出,封装到对象中


package com.caq.team.domain;


/**
 * @ClassName Employee
 * @Description TODO
 * @Author Jack
 * @Date 2021/11/8 11:15
 * @Version 1.0
 */
public class Employee {
    private int id;
    private String name;
    private int age;
    private double salary;
    public Employee() {
    }
    public Employee(int id, String name, int age, double salary) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.salary = salary;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public double getSalary() {
        return salary;
    }
    public void setSalary(double salary) {
        this.salary = salary;
    }
    public String getDetails(){
        return id + "\t" + name + "\t" + age + "\t" + salary;
    }
    @Override
    public String toString() {
        return getDetails();
    }
}


Programmer


Employee的子类,有自己的属型和方法


package com.caq.team.domain;


import com.caq.team.service.Status;


/**
 * @ClassName Programmer
 * @Description TODO
 * @Author Jack
 * @Date 2021/11/8 11:17
 * @Version 1.0
 */
public class Programmer extends Employee {
    private int memberId;   //开发团队中的id
    private Status status = Status.FREE;
    private Equipment equipment;
    public Programmer() {
    }
    public Programmer(int id, String name, int age, double salary, Equipment equipment) {
        super(id, name, age, salary);
        this.equipment = equipment;
    }
    public int getMemberId() {
        return memberId;
    }
    public void setMemberId(int memberId) {
        this.memberId = memberId;
    }
    public Status getStatus() {
        return status;
    }
    public void setStatus(Status status) {
        this.status = status;
    }
    public Equipment getEquipment() {
        return equipment;
    }
    public void setEquipment(Equipment equipment) {
        this.equipment = equipment;
    }
    @Override
    public String toString() {
        return getDetails() + "\t程序员\t" + status + "\t\t\t" + equipment.getDescription();
    }
    public String getTeamBaseDetails() {
        return memberId + "/" + getId() + "\t" + getName() + "\t" + getAge() + "\t" + getSalary();
    }
    //2/6  任志强    22 6800.0 程序员
    public String getDetailsForTeam() {
        return getTeamBaseDetails() + "\t程序员";
    }
}


Designer


同上


package com.caq.team.domain;


/**
 * @ClassName Designer
 * @Description TODO
 * @Author Jack
 * @Date 2021/11/8 11:38
 * @Version 1.0
 */
public class Designer extends Programmer{
    private double bonus;//奖金
    public Designer() {
    }
    public Designer(int id, String name, int age, double salary, Equipment equipment, double bonus) {
        super(id, name, age, salary, equipment);
        this.bonus = bonus;
    }
    public double getBonus() {
        return bonus;
    }
    public void setBonus(double bonus) {
        this.bonus = bonus;
    }
    @Override
    public String toString() {
        return getDetails() + "\t设计师\t" + getStatus() + "\t" + bonus + "\t\t" + getEquipment().getDescription();
    }
    public String getDetailsForTeam() {
        return  getTeamBaseDetails() + "\t设计师\t" + getBonus();
    }
}


Architect


package com.caq.team.domain;


/**
 * @ClassName Architect
 * @Description TODO
 * @Author Jack
 * @Date 2021/11/8 11:41
 * @Version 1.0
 */
public class Architect extends Designer{
    private int stock;//股票
    public Architect() {
    }
    public Architect(int id, String name, int age, double salary, Equipment equipment, double bonus, int stock) {
        super(id, name, age, salary, equipment, bonus);
        this.stock = stock;
    }
    public int getStock() {
        return stock;
    }
    public void setStock(int stock) {
        this.stock = stock;
    }
    @Override
    public String toString() {
        return getDetails() + "\t架构师\t" + getStatus() + "\t" + getBonus() + "\t" + stock + "\t" + getEquipment().getDescription();
    }
    public String getDetailsForTeam() {
        return getTeamBaseDetails() + "\t架构师\t" + getBonus() + "\t" + getStock();
    }
}


NameListService


package com.caq.team.service;
import com.caq.team.domain.*;
import static com.caq.team.service.Data.*;
/**
 * @ClassName NameListService
 * @Description 负责将data中的数据封装到Employee[]数组中,同时提供相关操作Employee[]的方法
 * @Author Jack
 * @Date 2021/11/8 11:46
 * @Version 1.0
 */
public class NameListService {
    private Employee[] employees;
    /**
     * 给employees及数组元素进行初始化
     */
    public NameListService() {
        //根据项目提供的Data类构建相应大小的employees数组
        //再根据Data类中的数据构建不同的对象,包括Employee、Programmer、Designer和Architect对象,以及相关联的Equipment子类的对象
        //将对象存于数组中
        //Data类位于com.caq.team.service包中
        employees = new Employee[EMPLOYEES.length];
        /**
         * 程序解析
         * 通过一个循环来获取数组中的信息
         * 用到了包装类的常用操作,以及常用的结构
         * 通过包装类的方法将字符转化为想要的基本数据类型,与前面定义的常量通过switch结构进行匹配,
         * 对应的数字代表一种对象类型(EMPLOYEE,PROGRAMMER,DESIGNER,ARCHITECT),不同的对象有不同装备的方法,
         * 也是用switch结构进行匹配,对应的数字有特殊的Equipment匹配过后返回一个Equipment对象作为
         * (EMPLOYEE,PROGRAMMER,DESIGNER,ARCHITECT)的参数一同加入数组employees中.
         * 最后提供了相关操作Employee[]的方法
         */
        for (int i = 0; i < employees.length; i++) {
            //获取员工信息
            int type = Integer.parseInt(EMPLOYEES[i][0]);
            //获取Employee的4个基本信息
            int id = Integer.parseInt(EMPLOYEES[i][1]);
            String name = EMPLOYEES[i][2];
            int age = Integer.parseInt(EMPLOYEES[i][3]);
            double salary = Integer.parseInt(EMPLOYEES[i][4]);
            Equipment equipment;
            double bonus;
            int stock;
            switch (type) {
                case EMPLOYEE:
                    employees[i] = new Employee(id, name, age, salary);
                    break;
                case PROGRAMMER:
                    equipment = createEquipment(i);
                    employees[i] = new Programmer(id, name, age, salary, equipment);
                    break;
                case DESIGNER:
                    equipment = createEquipment(i);
                    bonus = Double.parseDouble(EMPLOYEES[i][5]);
                    employees[i] = new Designer(id, name, age, salary, equipment, bonus);
                    break;
                case ARCHITECT:
                    equipment = createEquipment(i);
                    bonus = Double.parseDouble(EMPLOYEES[i][5]);
                    stock = Integer.parseInt(EMPLOYEES[i][6]);
                    employees[i] = new Architect(id, name, age, salary, equipment, bonus, stock);
                    break;
            }
        }
    }
    /**
     * 获取指定index上员工的位置
     *
     * @param index
     * @return
     */
    private Equipment createEquipment(int index) {
        //找到EQUIPMENT数组中的type和model类型,并把它转换为int类型
        int key = Integer.parseInt(EQUIPMENTS[index][0]);
        String modelOrName = EQUIPMENTS[index][1];
        switch (key) {
            case PC://21
                String display = EQUIPMENTS[index][2];
                return new PC(modelOrName, display);
            case NOTEBOOK://22
                double price = Double.parseDouble(EQUIPMENTS[index][2]);
                return new NoteBook(modelOrName, price);
            case PRINTER://23
                String type = EQUIPMENTS[index][2];
                return new Printer(modelOrName, type);
        }
        return null;
    }
    /**
     * 获取当前所有员工
     */
    public Employee[] getAllEmployees() {
        return employees;
    }
    /**
     * 获取指定ID的员工对象。
     * @param id
     * @return
     * @throws TeamException
     */
    public Employee getEmployee(int id) throws TeamException {
        for (int i = 0; i < employees.length; i++) {
            if (employees[i].getId() == id) {
                return employees[i];
            }
        }
        throw new TeamException("找不到指定的员工");
    }
}


status类


表示员工的状态


package com.caq.team.service;
/**
 * @ClassName Status
 * @Description 表示员工的状态
 * @Author Jack
 * @Date 2021/11/8 11:22
 * @Version 1.0
 */
public class Status {
    private final String NAME;
    private Status(String name) {
        this.NAME = name;
    }
    public static final Status FREE = new Status("FREE");
    public static final Status BUSY = new Status("BUSY");
    public static final Status VOCATION = new Status("VOCATION");
    //只能有get方法了,因为上面是常量
    public String getNAME() {
        return NAME;
    }
    @Override
    public String toString() {
        return NAME;
    }
}


TeamException


TeamException
package com.caq.team.service;
/**
 * @ClassName TeamException
 * @Description TODO
 * @Author Jack
 * @Date 2021/11/8 22:09
 * @Version 1.0
 */
public class TeamException extends Exception {
    static final long serialVersionUID = -3387514229948L;
    public TeamException() {
        super();
    }
    public TeamException(String msg) {
        super(msg);
    }
}


TeamService

关于开发团队成员的管理:添加、删除等。


package com.caq.team.service;
import com.caq.team.domain.Architect;
import com.caq.team.domain.Designer;
import com.caq.team.domain.Employee;
import com.caq.team.domain.Programmer;
import com.caq.team.service.Status;
import com.caq.team.service.TeamException;
/**
 * 关于开发团队成员的管理:添加、删除等。
 */
public class TeamService {
   private static int counter = 1;//给memberId赋值使用
   private final int MAX_MEMBER = 5;//限制开发团队的人数
   private Programmer[] team = new Programmer[MAX_MEMBER];//保存开发团队成员
   private int total;//记录开发团队中实际的人数
   public TeamService() {
      super();
   }
   /**
    * 获取开发团队中的所有成员
    * @return
    */
   public Programmer[] getTeam(){
      Programmer[] team = new Programmer[total];
      for(int i = 0;i < team.length;i++){
         team[i] = this.team[i];
      }
      return team;
   }
   /**
    * 将指定的员工添加到开发团队中
    * @param e
    * @throws TeamException
    */
   public void addMember(Employee e) throws TeamException {
//    成员已满,无法添加
      if(total >= MAX_MEMBER){
         throw new TeamException("成员已满,无法添加");
      }
//    该成员不是开发人员,无法添加
      if(!(e instanceof Programmer)){
         throw new TeamException("该成员不是开发人员,无法添加");
      }
//    该员工已在本开发团队中
      if(isExist(e)){
         throw new TeamException("该员工已在本开发团队中");
      }
//    该员工已是某团队成员
//    该员正在休假,无法添加
      Programmer p = (Programmer)e;//一定不会出现ClassCastException
      if("BUSY".equalsIgnoreCase(p.getStatus().getNAME())){//if(p.getStatus().getNAME().equals("BUSY")){
         throw new TeamException("该员工已是某团队成员");
      }else if("VOCATION".equalsIgnoreCase(p.getStatus().getNAME())){
         throw new TeamException("该员正在休假,无法添加");
      }
//    团队中至多只能有一名架构师
//    团队中至多只能有两名设计师
//    团队中至多只能有三名程序员
      //获取team已有成员中架构师,设计师,程序员的人数
      int numOfArch = 0,numOfDes = 0,numOfPro = 0;
      for(int i = 0;i < total;i++){
         if(team[i] instanceof Architect){
            numOfArch++;
         }else if(team[i] instanceof Designer){
            numOfDes++;
         }else if(team[i] instanceof Programmer){
            numOfPro++;
         }
      }
      //正确的
      if(p instanceof Architect){
         if(numOfArch >= 1){
            throw new TeamException("团队中至多只能有一名架构师");
         }
      }else if(p instanceof Designer){
         if(numOfDes >= 2){
            throw new TeamException("团队中至多只能有两名设计师");
         }
      }else if(p instanceof Programmer){
         if(numOfPro >= 3){
            throw new TeamException("团队中至多只能有三名程序员");
         }
      }
      //错误的
//    if(p instanceof Architect && numOfArch >= 1){
//       throw new TeamException("团队中至多只能有一名架构师");
//    }else if(p instanceof Designer && numOfDes >= 2){
//       throw new TeamException("团队中至多只能有两名设计师");
//    }else if(p instanceof Programmer && numOfPro >= 3){
//       throw new TeamException("团队中至多只能有三名程序员");
//    }
      //将p(或e)添加到现有的team中
      team[total++] = p;
      //p的属性赋值
      p.setStatus(Status.BUSY);
      p.setMemberId(counter++);
   }
   /**
    * 判断指定的员工是否已经存在于现有的开发团队中
    * @param e
    * @return
    */
   private boolean isExist(Employee e) {
      for(int i = 0;i < total;i++){
         return team[i].getId() == e.getId();
      }
      return false;
   }
   /**
    *     从团队中删除成员
    */
   public void removeMember(int memberId) throws TeamException {
      int i = 0;
      for(;i < total;i++){
         if(team[i].getMemberId() == memberId){
            team[i].setStatus(Status.FREE);
            break;
         }
      }
      //未找到指定memberId的情况
      if(i == total){
         throw new TeamException("找不到指定memberId的员工,删除失败");
      }
      //后一个元素覆盖前一个元素,实现删除操作
      for(int j = i + 1;j < total;j++){
         team[j - 1] = team[j];
      }
      //写法一:
//    team[total-1] = null;
//    total--;
      //写法二:
      team[--total] = null;
   }
}


视图TeamView


package com.caq.team.view;
import com.atguigu.team.domain.Employee;
import com.atguigu.team.domain.Programmer;
import com.atguigu.team.service.NameListService;
import com.atguigu.team.service.TeamException;
import com.atguigu.team.service.TeamService;
import com.atguigu.team.view.TSUtility;
public class TeamView {
   private NameListService listSvc = new NameListService();
   private TeamService teamSvc = new TeamService();
   public void enterMainMenu(){
      boolean loopFlag = true;
      char menu = 0;
      while(loopFlag){
         if(menu != '1'){
            listAllEmployees();
         }
         System.out.print("1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):");
         menu = TSUtility.readMenuSelection();
         switch(menu){
         case '1':
            getTeam();
            break;
         case '2':
            addMember();
            break;
         case '3':
            deleteMember();
            break;
         case '4':
            System.out.print("确认是否退出(Y/N):");
            char isExit = TSUtility.readConfirmSelection();
            if(isExit == 'Y'){
               loopFlag = false;
            }
            break;
         }
      }
   }
   /**
    * 显示所有的员工信息
    * @Description 
    * @author shkstart
    * @date 2019年2月12日下午3:10:07
    */
   private void listAllEmployees(){
//    System.out.println("显示公司所有的员工信息");
      System.out.println("-------------------------------开发团队调度软件--------------------------------\n");
      Employee[] employees = listSvc.getAllEmployees();
      if(employees == null || employees.length == 0){
         System.out.println("公司中没有任何员工信息!");
      }else{
         System.out.println("ID\t姓名\t\t年龄\t\t工资\t\t职位\t\t状态\t\t奖金\t\t股票\t\t领用设备");
         for(int i = 0;i < employees.length;i++){
            System.out.println(employees[i]);
         }
      }
      System.out.println("-------------------------------------------------------------------------------");
   }
   private void getTeam(){
//    System.out.println("查看开发团队情况");
      System.out.println("--------------------团队成员列表---------------------\n");
      Programmer[] team = teamSvc.getTeam();
      if(team == null || team.length == 0){
         System.out.println("开发团队目前没有成员!");
      }else{
         System.out.println("TID/ID\t姓名\t年龄\t工资\t职位\t奖金\t股票\n");
         for(int i = 0;i < team.length;i++){
            System.out.println(team[i].getDetailsForTeam());
         }
      }
      System.out.println("-----------------------------------------------------");
   }
   private void addMember(){
//    System.out.println("添加团队成员");
      System.out.println("---------------------添加成员---------------------");
      System.out.print("请输入要添加的员工ID:");
      int id = TSUtility.readInt();
      try {
         Employee emp = listSvc.getEmployee(id);
         teamSvc.addMember(emp);
         System.out.println("添加成功");
      } catch (TeamException e) {
         System.out.println("添加失败,原因:" + e.getMessage());
      }
      //按回车键继续...
      TSUtility.readReturn();
   }
   private void deleteMember(){
//    System.out.println("删除团队成员");
      System.out.println("---------------------删除成员---------------------");
      System.out.print("请输入要删除员工的TID:");
      int memberId = TSUtility.readInt();
      System.out.print("确认是否删除(Y/N):");
      char isDelete = TSUtility.readConfirmSelection();
      if(isDelete == 'N'){
         return;
      }
      try {
         teamSvc.removeMember(memberId);
         System.out.println("删除成功");
      } catch (TeamException e) {
         System.out.println("删除失败,原因:" + e.getMessage());
      }
      //按回车键继续...
      TSUtility.readReturn();
   }
   public static void main(String[] args){
      TeamView view = new TeamView();
      view.enterMainMenu();
   }
}


测试类


package com.caq.team.junit;
import com.atguigu.team.service.TeamException;
import com.caq.team.domain.Employee;
import com.caq.team.service.NameListService;
import org.junit.Test;
/**
 * @ClassName NameListServiceTest
 * @Description 对NameList进行测试
 * @Author Jack
 * @Date 2021/11/8 22:16
 * @Version 1.0
 */
public class NameListServiceTest {
    @Test
    public void testGetAllEmployees(){
        //通过生成对象,调用构造方法会把Data类中的数据封装到Employee[]数组中
        NameListService service = new NameListService();
        //获取当前所有员工
        Employee[] employees = service.getAllEmployees();
        //遍历数组中所有的元素
        for (int i = 0; i < employees.length; i++) {
            System.out.println(employees[i]);
        }
    }
    @Test
    public void testGetEmployee(){
        com.atguigu.team.service.NameListService service = new com.atguigu.team.service.NameListService();
        int id = 1;
        id = 101;
        try {
            com.atguigu.team.domain.Employee employee = service.getEmployee(id);
            System.out.println(employee);
        } catch (TeamException e) {
            System.out.println(e.getMessage());
        }
    }
}


实现效果


-------------------------------开发团队调度软件--------------------------------
ID  姓名  年龄  工资  职位  状态  奖金  股票  领用设备
1 马云云 22  3000.0
2 马化腾 32  18000.0 架构师 FREE  15000.0 2000  联想T4(6000.0)
3 李彦宏 23  7000.0  程序员 FREE    戴尔(NEC17寸)
4 刘强东 24  7300.0  程序员 FREE    戴尔(三星 17寸)
5 雷军军 28  10000.0 设计师 FREE  5000.0  佳能 2900(激光)
6 任志强 22  6800.0  程序员 FREE    华硕(三星 17寸)
7 柳传志 29  10800.0 设计师 FREE  5200.0  华硕(三星 17寸)
8 杨元庆 30  19800.0 架构师 FREE  15000.0 2500  爱普生20K(针式)
9 史玉柱 26  9800.0  设计师 FREE  5500.0  惠普m6(5800.0)
10  丁磊磊 21  6600.0  程序员 FREE    戴尔(NEC 17寸)
11  张朝阳 25  7100.0  程序员 FREE    华硕(三星 17寸)
12  杨致远 27  9600.0  设计师 FREE  4800.0  惠普m6(5800.0)
-------------------------------------------------------------------------------
1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):2
---------------------添加成员---------------------
请输入要添加的员工ID:2
添加成功
按回车键继续...
-------------------------------开发团队调度软件--------------------------------
ID  姓名  年龄  工资  职位  状态  奖金  股票  领用设备
1 马云云 22  3000.0
2 马化腾 32  18000.0 架构师 BUSY  15000.0 2000  联想T4(6000.0)
3 李彦宏 23  7000.0  程序员 FREE    戴尔(NEC17寸)
4 刘强东 24  7300.0  程序员 FREE    戴尔(三星 17寸)
5 雷军军 28  10000.0 设计师 FREE  5000.0  佳能 2900(激光)
6 任志强 22  6800.0  程序员 FREE    华硕(三星 17寸)
7 柳传志 29  10800.0 设计师 FREE  5200.0  华硕(三星 17寸)
8 杨元庆 30  19800.0 架构师 FREE  15000.0 2500  爱普生20K(针式)
9 史玉柱 26  9800.0  设计师 FREE  5500.0  惠普m6(5800.0)
10  丁磊磊 21  6600.0  程序员 FREE    戴尔(NEC 17寸)
11  张朝阳 25  7100.0  程序员 FREE    华硕(三星 17寸)
12  杨致远 27  9600.0  设计师 FREE  4800.0  惠普m6(5800.0)
-------------------------------------------------------------------------------
1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):2
---------------------添加成员---------------------
请输入要添加的员工ID:3
添加成功
按回车键继续...
-------------------------------开发团队调度软件--------------------------------
ID  姓名  年龄  工资  职位  状态  奖金  股票  领用设备
1 马云云 22  3000.0
2 马化腾 32  18000.0 架构师 BUSY  15000.0 2000  联想T4(6000.0)
3 李彦宏 23  7000.0  程序员 BUSY    戴尔(NEC17寸)
4 刘强东 24  7300.0  程序员 FREE    戴尔(三星 17寸)
5 雷军军 28  10000.0 设计师 FREE  5000.0  佳能 2900(激光)
6 任志强 22  6800.0  程序员 FREE    华硕(三星 17寸)
7 柳传志 29  10800.0 设计师 FREE  5200.0  华硕(三星 17寸)
8 杨元庆 30  19800.0 架构师 FREE  15000.0 2500  爱普生20K(针式)
9 史玉柱 26  9800.0  设计师 FREE  5500.0  惠普m6(5800.0)
10  丁磊磊 21  6600.0  程序员 FREE    戴尔(NEC 17寸)
11  张朝阳 25  7100.0  程序员 FREE    华硕(三星 17寸)
12  杨致远 27  9600.0  设计师 FREE  4800.0  惠普m6(5800.0)
-------------------------------------------------------------------------------
1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):2
---------------------添加成员---------------------
请输入要添加的员工ID:4
添加成功
按回车键继续...
-------------------------------开发团队调度软件--------------------------------
ID  姓名  年龄  工资  职位  状态  奖金  股票  领用设备
1 马云云 22  3000.0
2 马化腾 32  18000.0 架构师 BUSY  15000.0 2000  联想T4(6000.0)
3 李彦宏 23  7000.0  程序员 BUSY    戴尔(NEC17寸)
4 刘强东 24  7300.0  程序员 BUSY    戴尔(三星 17寸)
5 雷军军 28  10000.0 设计师 FREE  5000.0  佳能 2900(激光)
6 任志强 22  6800.0  程序员 FREE    华硕(三星 17寸)
7 柳传志 29  10800.0 设计师 FREE  5200.0  华硕(三星 17寸)
8 杨元庆 30  19800.0 架构师 FREE  15000.0 2500  爱普生20K(针式)
9 史玉柱 26  9800.0  设计师 FREE  5500.0  惠普m6(5800.0)
10  丁磊磊 21  6600.0  程序员 FREE    戴尔(NEC 17寸)
11  张朝阳 25  7100.0  程序员 FREE    华硕(三星 17寸)
12  杨致远 27  9600.0  设计师 FREE  4800.0  惠普m6(5800.0)
-------------------------------------------------------------------------------
1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):1
--------------------团队成员列表---------------------
TID/ID  姓名  年龄  工资  职位  奖金  股票
1/2 马化腾 32  18000.0 架构师 15000.0 2000
2/3 李彦宏 23  7000.0  程序员
3/4 刘强东 24  7300.0  程序员
-----------------------------------------------------
1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):


相关文章
|
15天前
|
安全 前端开发 Java
《深入理解Spring》:现代Java开发的核心框架
Spring自2003年诞生以来,已成为Java企业级开发的基石,凭借IoC、AOP、声明式编程等核心特性,极大简化了开发复杂度。本系列将深入解析Spring框架核心原理及Spring Boot、Cloud、Security等生态组件,助力开发者构建高效、可扩展的应用体系。(238字)
|
2月前
|
Java
Java基础语法与面向对象
重载(Overload)指同一类中方法名相同、参数列表不同,与返回值无关;重写(Override)指子类重新实现父类方法,方法名和参数列表必须相同,返回类型兼容。重载发生在同类,重写发生在继承关系中。
98 1
|
2月前
|
消息中间件 人工智能 Java
抖音微信爆款小游戏大全:免费休闲/竞技/益智/PHP+Java全筏开源开发
本文基于2025年最新行业数据,深入解析抖音/微信爆款小游戏的开发逻辑,重点讲解PHP+Java双引擎架构实战,涵盖技术选型、架构设计、性能优化与开源生态,提供完整开源工具链,助力开发者从理论到落地打造高留存、高并发的小游戏产品。
|
2月前
|
存储 Java 关系型数据库
Java 项目实战基于面向对象思想的汽车租赁系统开发实例 汽车租赁系统 Java 面向对象项目实战
本文介绍基于Java面向对象编程的汽车租赁系统技术方案与应用实例,涵盖系统功能需求分析、类设计、数据库设计及具体代码实现,帮助开发者掌握Java在实际项目中的应用。
72 0
|
3月前
|
安全 Java 编译器
Java面向对象
本文深入讲解了Java面向对象编程(OOP)的四大特性:封装、继承、多态与抽象,以及方法的设计与使用。通过示例展示了如何用类和对象组织代码,提升程序的可维护性与扩展性。
|
设计模式 Oracle Java
Java进阶专题(三) 软件架构设计原则(下)
今天开始我们专题的第二课了,本章节继续分享软件架构设计原则的下篇,将介绍:接口隔离原则、迪米特原则、里氏替换原则和合成复用原则。本章节参考资料书籍《Spring 5核心原理》中的第一篇 Spring 内功心法(没有电子档,都是我取其精华并结合自己的理解,一个字一个字手敲出来的)。
317 0
|
Java Go 数据安全/隐私保护
Java进阶专题(二) 软件架构设计原则(上)
今天开始我们专题的第一课了,也是我开始进阶学习的第一天,我们先从经典设计思想开始,看看大牛市如何写代码的,提升技术审美、提高核心竞争力。本章节参考资料书籍《Spring 5核心原理》中的第一篇 Spring 内功心法(没有电子档,都是我取其精华并结合自己的理解,一个字一个字手敲出来的)
5505 0
|
Java 关系型数据库 Go
Java进阶专题(二) 软件架构设计原则(上)
今天开始我们专题的第一课了,也是我开始进阶学习的第一天,我们先从经典设计思想开始,看看大牛市如何写代码的,提升技术审美、提高核心竞争力。本章节参考资料书籍《Spring 5核心原理》中的第一篇 Spring 内功心法(没有电子档,都是我取其精华并结合自己的理解,一个字一个字手敲出来的)。
337 0
|
23天前
|
JSON 网络协议 安全
【Java】(10)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
88 1
下一篇
开通oss服务