/**
*
* @Description Java 开发人员调度软件项目 (java基础编程总结项目)
* +javaBean+测试代码+数组知识+数据结构+继承+多态+封装+自定义异常,异常处理
* +构造器知识+重载+重写+接口+实现接口+关键字使用(static +equalsIgnoreCase+fianl+instanceof判断类型)
* +向下转型与向上转型
* @author Bytezero·zhenglei! Email:420498246@qq.com
* @version
* @date 下午12:00:33
* @
*
*/
com.bytezero.team.domain
1 package com.bytezero.team.domain; 2 3 public class Architect extends Designer { 4 5 private int stock; //股票 6 7 public Architect() { 8 super(); 9 } 10 11 public Architect(int id, String name, int age, double salary, Equipment equipment, double bonus, int stock) { 12 super(id, name, age, salary, equipment, bonus); 13 this.stock = stock; 14 } 15 16 public int getStock() { 17 return stock; 18 } 19 20 public void setStock(int stock) { 21 this.stock = stock; 22 } 23 24 // @Override 25 // public String toString() { 26 // return getDetails() +"\t架构师\t" +getStatus() +"\t" +getBonus() + "\t" + stock +"\t"+getEquipment().getDescription(); 27 // } 28 29 30 @Override 31 public String toString() { 32 33 return getDetails() + "\t架构师\t" +getStatus() +"\t" + getBonus() +"\t" + stock + "\t" + getEquipment().getDescription(); 34 } 35 36 public String getDetailsForTeam() { 37 38 return getTeamBaseDetails() + "\t架构师\t"+getBonus()+"\t"+getStock(); 39 40 } 41 42 43 }
1 package com.bytezero.team.domain; 2 3 public class Designer extends Programmer{ 4 5 private double bonus; //奖金 6 7 public Designer() { 8 super(); 9 } 10 11 public Designer(int id, String name, int age, double salary, Equipment equipment, double bonus) { 12 super(id, name, age, salary, equipment); 13 this.bonus = bonus; 14 } 15 16 public double getBonus() { 17 return bonus; 18 } 19 20 public void setBonus(double bonus) { 21 this.bonus = bonus; 22 } 23 24 25 // @Override 26 // public String toString() { 27 // 28 // return getDetails() +"\t设计师\t" +getStatus() +"\t" +bonus + "\t\t"+getEquipment().getDescription(); 29 // } 30 31 @Override 32 public String toString() { 33 34 return super.getDetails() + "\t设计师\t" +getStatus() +"\t" + bonus +"\t\t"+ getEquipment().getDescription(); 35 } 36 37 public String getDetailsForTeam() { 38 39 return getTeamBaseDetails()+"\t设计师\t"+getBonus(); 40 41 } 42 43 }
1 package com.bytezero.team.domain; 2 3 public class Employee { 4 5 private int id; 6 private String name; 7 private int age; 8 private double salary; 9 10 11 12 13 public int getId() { 14 return id; 15 } 16 public void setId(int id) { 17 this.id = id; 18 } 19 public String getName() { 20 return name; 21 } 22 public void setName(String name) { 23 this.name = name; 24 } 25 public int getAge() { 26 return age; 27 } 28 public void setAge(int age) { 29 this.age = age; 30 } 31 public double getSalary() { 32 return salary; 33 } 34 public void setSalary(double salary) { 35 this.salary = salary; 36 } 37 public Employee() { 38 super(); 39 } 40 public Employee(int id, String name, int age, double salary) { 41 super(); 42 this.id = id; 43 this.name = name; 44 this.age = age; 45 this.salary = salary; 46 } 47 48 // public String getDetails() { 49 // return id +"\t" + name +"\t" + age +"\t" +salary; 50 // } 51 // 52 public String getDetails() { 53 return id +"\t" + name +"\t" + age +"\t" +salary; 54 } 55 56 57 @Override 58 public String toString() { 59 60 //return id +"\t" + name +"\t" + age +"\t" +salary; 61 //return getDetails(); 62 63 return getDetails(); 64 65 } 66 67 68 69 }
1 package com.bytezero.team.domain; 2 3 public interface Equipment { 4 5 public abstract String getDescription(); 6 7 8 }
1 package com.bytezero.team.domain; 2 3 public class NoteBook implements Equipment { 4 5 private String model; //机器型号 6 private double price; //价格 7 8 public String getModel() { 9 return model; 10 } 11 public void setModel(String model) { 12 this.model = model; 13 } 14 public double getPrice() { 15 return price; 16 } 17 public void setPrice(double price) { 18 this.price = price; 19 } 20 21 22 public NoteBook(String model, double price) { 23 super(); 24 this.model = model; 25 this.price = price; 26 } 27 public NoteBook() { 28 super(); 29 } 30 31 @Override 32 public String getDescription() { 33 34 return model +"(" + price +")"; 35 } 36 37 38 39 40 41 42 }
1 package com.bytezero.team.domain; 2 3 public class PC implements Equipment{ 4 5 private String model; //机器型号 6 private String display; //显示器名称 7 8 9 public PC(String model, String display) { 10 super(); 11 this.model = model; 12 this.display = display; 13 } 14 15 16 public PC() { 17 super(); 18 } 19 20 21 public String getModel() { 22 return model; 23 } 24 25 26 public void setModel(String model) { 27 this.model = model; 28 } 29 30 31 public String getDisplay() { 32 return display; 33 } 34 35 36 public void setDisplay(String display) { 37 this.display = display; 38 } 39 40 41 @Override 42 public String getDescription() { 43 44 return model +"(" + display +")"; 45 } 46 47 48 49 50 }
1 package com.bytezero.team.domain; 2 3 public class Printer implements Equipment { 4 5 private String name; //机器型号 6 private String type; //机器类型 7 public String getName() { 8 return name; 9 } 10 public void setName(String name) { 11 this.name = name; 12 } 13 public String getType() { 14 return type; 15 } 16 public void setType(String type) { 17 this.type = type; 18 } 19 public Printer() { 20 super(); 21 } 22 public Printer(String name, String type) { 23 super(); 24 this.name = name; 25 this.type = type; 26 } 27 28 @Override 29 public String getDescription() { 30 return name +"(" + type +")"; 31 } 32 33 34 35 }
1 package com.bytezero.team.domain; 2 3 import com.bytezero.team.service.Status; 4 5 public class Programmer extends Employee { 6 7 private int memberId; //开发团队中的Id 8 private Status status = Status.FREE; 9 private Equipment equipment; 10 11 public Programmer() { 12 super(); 13 } 14 public Programmer(int id, String name, int age, double salary, Equipment equipment) { 15 super(id, name, age, salary); 16 17 this.equipment = equipment; 18 } 19 public int getMemberId() { 20 return memberId; 21 } 22 public void setMemberId(int memberId) { 23 this.memberId = memberId; 24 } 25 public Status getStatus() { 26 return status; 27 } 28 public void setStatus(Status status) { 29 this.status = status; 30 } 31 public Equipment getEquipment() { 32 return equipment; 33 } 34 public void setEquipment(Equipment equipment) { 35 this.equipment = equipment; 36 } 37 38 39 // @Override 40 // public String toString() { 41 // 42 // return getDetails() + "\t程序员\t" + status + "\t\t\t"+equipment.getDescription() ; 43 // } 44 45 @Override 46 public String toString() { 47 48 return getDetails() + "\t程序员\t" + status +"\t\t\t" + equipment.getDescription() ; 49 } 50 51 public String getTeamBaseDetails() { 52 return memberId +"/" +getId()+"\t"+getName()+"\t"+getAge()+"\t"+getSalary(); 53 } 54 55 public String getDetailsForTeam() { 56 57 return getTeamBaseDetails() +"\t程序员"; 58 59 } 60 61 62 }
com.bytezero.team.service
1 package com.bytezero.team.service; 2 3 /** 4 * 5 * @Description 存放的数据 6 * @author Bytezero·zhenglei! Email:420498246@qq.com 7 * @version 8 * @date 上午10:37:01 9 * @ 10 * 11 */ 12 public class Data { 13 14 public static final int EMPLOYEE = 10; 15 public static final int PROGRAMMER = 11; 16 public static final int DESIGNER = 12; 17 public static final int ARCHITECT = 13; 18 19 20 public static final int PC =21; 21 public static final int NOTEBOOK = 22; 22 public static final int PRINTER = 23; 23 24 25 //Employee : 10, id, name, age, salary 26 //Programmer : 11, id, name, age, salary 27 //Designer : 12, id, name, age, salary,bonus 28 //Architect : 13, id, name, age, salary,bonus, stock 29 30 public static final String[][] EMPLOYEES = { 31 {"10", "1", "男枪", "22", "3000"}, 32 {"13", "2", "亚索", "32", "13000", "15000", "2000"}, 33 {"11", "3", "皇子", "21", "6000"}, 34 {"11", "4", "螳螂", "24", "5000"}, 35 {"12", "5", "瑞文", "26", "30000","1200"}, 36 {"11", "6", "雪人", "22", "3900"}, 37 {"12", "7", "诺手", "27", "3500", "2500"}, 38 {"13", "8", "劫", "62", "4200", "9822", "6500"}, 39 {"12", "9", "青钢影", "34", "7000", "7894"}, 40 {"11", "10", "盲僧", "29", "6500"}, 41 {"11", "11", "梦魇", "32", "7600"}, 42 {"12", "12", "剑姬", "52", "7300", "4800"}, 43 44 45 }; 46 47 48 //如下 EQUIPMENTS数组与上面的EMPLOYEES数组元素一一对应 49 //PC : 21, model, display 50 //NoteBook : 22, model, price 51 //Printer : 23, name, type 52 53 public static final String[][] EQUIPMENTS = { 54 {}, 55 {"22", "联想T4", "6000"}, 56 {"21", "戴尔", "NEC17寸"}, 57 {"21", "戴尔", "三星17寸"}, 58 {"23", "佳能2900", "激光"}, 59 {"21", "华硕", "三星17寸"}, 60 {"21", "华硕", "三星17寸"}, 61 {"23", "爱普生20K", "针式"}, 62 {"22", "惠普m6", "5800"}, 63 {"21", "戴尔","NEC17寸"}, 64 {"21", "华硕", "三星17寸"}, 65 {"22", "惠普m6","5800"} 66 67 68 69 }; 70 71 72 }
1 package com.bytezero.team.service; 2 3 import com.bytezero.team.domain.Architect; 4 import com.bytezero.team.domain.Designer; 5 import com.bytezero.team.domain.Employee; 6 import com.bytezero.team.domain.Equipment; 7 import com.bytezero.team.domain.NoteBook; 8 import com.bytezero.team.domain.PC; 9 import com.bytezero.team.domain.Printer; 10 import com.bytezero.team.domain.Programmer; 11 12 import static com.bytezero.team.service.Data.*; 13 /** 14 * 15 * @Description 负责将Data中的数据封装到Employee[]数组中,同时提供相关操作Employee[]的方法 16 * 17 * @author Bytezero·zhenglei! Email:420498246@qq.com 18 * @version v1.0 19 * @date 上午9:47:38 20 * @ 21 * 22 */ 23 public class NameListService { 24 25 private Employee[] employees; 26 27 /** 28 * 给employee及数组元素进行初始化 29 */ 30 public NameListService() { 31 32 //1.根据项目提供的Data类构建相应大小的employee数组 33 //2.再根据Data类中的数据构建不同的对象,包括 Employee,Programmer,Designer和Architect对象,以及 34 //相关联的Equipment子类的对象 35 //3.将对象存于数组中 36 37 //employees = new Employee[Data.EMPLOYEES.length]; 38 //导入 静态结构 import static com.bytezero.team.service.Data.*; 39 employees = new Employee[EMPLOYEES.length]; 40 41 for(int i = 0; i <employees.length;i++) { 42 //获取员工的类型 43 int type = Integer.parseInt(EMPLOYEES[i][0]); 44 45 //获取Employee的4个基本信息 46 int id = Integer.parseInt(EMPLOYEES[i][1]); 47 String name = EMPLOYEES[i][2]; 48 int age = Integer.parseInt(EMPLOYEES[i][3]); 49 double salary = Double.parseDouble(EMPLOYEES[i][4]); 50 Equipment equipment; 51 double bonus; 52 int stock; 53 54 switch(type) { 55 case EMPLOYEE: 56 employees[i] = new Employee(id,name,age,salary); 57 break; 58 case PROGRAMMER: 59 equipment = createEquipment(i); 60 employees[i] = new Programmer(id, name, age, salary, equipment); 61 break; 62 case DESIGNER: 63 equipment = createEquipment(i); 64 bonus = Double.parseDouble(EMPLOYEES[i][5]); 65 employees[i] = new Designer(id, name, age, salary, equipment, bonus); 66 break; 67 case ARCHITECT: 68 equipment = createEquipment(i); 69 bonus = Double.parseDouble(EMPLOYEES[i][5]); 70 stock = Integer.parseInt(EMPLOYEES[i][6]); 71 72 employees[i] = new Architect(id, name, age, salary, equipment, bonus, stock); 73 74 break; 75 } 76 77 } 78 79 } 80 /** 81 * 82 * @Description 获取指定index上的员工设备 83 * @author Bytezero·zhenglei! Email:420498246@qq.com 84 * @version 85 * @date 下午2:22:35 86 * @ 87 * 88 */ 89 90 private Equipment createEquipment(int index) { 91 92 int key = Integer.parseInt(EQUIPMENTS[index][0]) ; 93 94 String modelOrNama = EQUIPMENTS[index][1]; 95 96 switch(key) { 97 case PC: //21 98 String display = EQUIPMENTS[index][2]; 99 100 //return new PC(EMPLOYEES[index][1],EMPLOYEES[index][2]); 101 return new PC(modelOrNama,display); 102 103 case NOTEBOOK: //22 104 double price = Double.parseDouble(EQUIPMENTS[index][2]); 105 return new NoteBook(modelOrNama, price); 106 107 case PRINTER: //23 108 109 String type = EQUIPMENTS[index][2]; 110 return new Printer(modelOrNama, type); 111 112 } 113 114 115 return null; 116 } 117 118 /** 119 * 获取当前所有员工 120 * @return 121 */ 122 public Employee[] getAllEmployees() { 123 124 return employees; 125 } 126 /** 127 * 128 * @param id 129 * @return 130 * @throws TeamException 131 */ 132 public Employee getEmployee(int id) throws TeamException { 133 for(int i = 0; i <employees.length;i++) { 134 if(employees[i].getId() == id) { 135 return employees[i]; 136 } 137 } 138 139 140 141 throw new TeamException("找不到指定的员工"); 142 } 143 144 145 146 147 148 }
1 package com.bytezero.team.service; 2 3 /** 4 * 5 * @Description 表示员工的状态 6 * @author Bytezero·zhenglei! Email:420498246@qq.com 7 * @version 8 * @date 上午11:12:06 9 * @ 10 * 11 */ 12 public class Status { 13 14 private final String NAME; 15 private Status(String name) { 16 this.NAME = name; 17 18 } 19 public static final Status FREE = new Status("FREE"); 20 public static final Status BUSY = new Status("BUSY"); 21 public static final Status VOCATION = new Status("VOCATION"); 22 public String getNAME() { 23 return NAME; 24 } 25 26 @Override 27 public String toString() { 28 return NAME; 29 } 30 31 32 }
1 package com.bytezero.team.service; 2 3 /** 4 * 5 * @Description 自定义异常类 6 * @author Bytezero·zhenglei! Email:420498246@qq.com 7 * @version 8 * @date 下午3:02:41 9 * @ 10 * 11 */ 12 public class TeamException extends Exception{ 13 14 static final long serialVersionUID = -338751699329948L; 15 16 public TeamException() { 17 18 super(); 19 } 20 21 public TeamException(String msg) { 22 super(msg); 23 } 24 25 }
1 package com.bytezero.team.service; 2 3 import com.bytezero.team.domain.Architect; 4 import com.bytezero.team.domain.Designer; 5 import com.bytezero.team.domain.Employee; 6 import com.bytezero.team.domain.Programmer; 7 8 /** 9 * 10 * @Description 关于团队成员的管理:添加,删除等 11 * @author Bytezero·zhenglei! Email:420498246@qq.com 12 * @version 13 * @date 上午8:34:27 14 * @ 15 * 16 */ 17 public class TeamService { 18 19 private static int counter = 1; //给memberId赋值使用 20 private int MAX_MEMBER = 5; //限制开发团队的人数 21 22 private Programmer[] team = new Programmer[MAX_MEMBER];//保存开发团队成员 23 24 private int total; //记录开发团队的实际人数 25 26 public TeamService() { 27 super(); 28 } 29 30 /** 31 * 获取开发团队中的所有成员 32 * @return 33 */ 34 public Programmer[] getTeam() { 35 Programmer[]team = new Programmer[total]; 36 for(int i = 0;i < team.length;i++) { 37 team[i] = this.team[i]; 38 } 39 40 return team; 41 } 42 43 44 /** 45 * 将指定的员工添加开发团队中 46 * @param e 47 * @throws TeamException 48 */ 49 public void addMenmber(Employee e) throws TeamException { 50 //成员已满,无法添加 51 if(total >=MAX_MEMBER) { 52 throw new TeamException("成员已满,无法添加"); 53 } 54 //该成员不是开发人员,无法添加 55 if(!(e instanceof Programmer)) { 56 throw new TeamException("该成员不是开发人员,无法添加"); 57 58 } 59 //该员工已在本开发团队中 60 if(isExist(e)) { 61 throw new TeamException("该员工已在本开发团队中"); 62 } 63 //该员工已是某队成员 64 //该员工正在休假,无法添加 65 Programmer p = (Programmer )e; //一定不会出现ClassCastException 66 // if(p.getStatus().getNAME().equals("BUSY")) { 67 // 68 // } 69 70 if("BUSY".equalsIgnoreCase(p.getStatus().getNAME())) { 71 throw new TeamException("该员工已是某队成员"); 72 }else if("VOCATION".equalsIgnoreCase(p.getStatus().getNAME())) { 73 throw new TeamException("该员工正在休假,无法添加"); 74 } 75 76 //团队中至多只能有一名架构师 77 78 79 //团队中至多只能有两名设计师 80 //团队中至多只能有三名程序员 81 82 //获取team中已有成员中架构师,设计师,程序员的人数 83 int numOfArch = 0,numOfDes = 0,numOfPro =0; 84 for(int i =0;i<total;i++) { 85 if(team[i] instanceof Architect) { 86 numOfArch++; 87 }else if(team[i] instanceof Designer) { 88 numOfDes++; 89 }else if(team[i] instanceof Programmer) { 90 numOfPro++; 91 } 92 } 93 94 if(p instanceof Architect) { 95 if(numOfArch >= 1) { 96 throw new TeamException("团队中至多只能有一名架构师"); 97 } 98 }else if(p instanceof Designer ) { 99 if(numOfDes >= 2) { 100 throw new TeamException("团队中至多只能有两名设计师"); 101 } 102 }else if( p instanceof Programmer) { 103 if(numOfPro >= 3) { 104 throw new TeamException("团队中至多只能有三名程序员"); 105 } 106 } 107 108 //将P(或e)添加到现有的team中 109 team[total++]= p; 110 //p 的属性赋值 111 p.setStatus(Status.BUSY); 112 p.setMemberId(counter++); 113 114 115 116 } 117 /** 118 * 判断指定的员工是否已经存在于现有的开发团队中 119 * @param e 120 * @return 121 */ 122 private boolean isExist(Employee e) { 123 124 for(int i = 0; i< total; i++) { 125 // if(team[i].getId() == e.getId()) { 126 // return true; 127 return team[i].getId() == e.getId(); 128 } 129 //} 130 131 132 return false; 133 } 134 135 136 /** 137 * 从团队当中 删除成员 138 * @param memberId 139 * @throws TeamException 140 */ 141 142 public void removeMember(int memberId) throws TeamException { 143 int i =0; 144 for(;i <total;i++) { 145 if(team[i].getMemberId() == memberId) { 146 team[i].setStatus(Status.FREE); 147 break; 148 } 149 } 150 151 152 //未找到memberId的情况 153 if(i == total) { 154 throw new TeamException("找不到指定memberId的员工,删除失败"); 155 } 156 157 //后面元素覆盖前一个元素,实现了删除操作 158 for(int j = i+1;j < total;j++) { 159 team[j-1] = team[j]; 160 } 161 162 // for(int j = i; j <total -1;j++) { 163 // team[j] = team[j+1]; 164 // } 165 166 //写法一 167 // team[total -1] = null; 168 // total--; 169 170 //或 171 //写法二 172 team[--total] = null; 173 174 175 } 176 177 }
com.bytezero.team.junit
1 package com.bytezero.team.junit; 2 3 4 5 6 7 8 9 10 11 12 13 import org.junit.jupiter.api.Test; 14 15 import com.bytezero.team.domain.Employee; 16 import com.bytezero.team.service.NameListService; 17 import com.bytezero.team.service.TeamException; 18 19 /** 20 * 21 * @Description 对NameListService 类的测试 22 * @author Bytezero·zhenglei! Email:420498246@qq.com 23 * @version 24 * @date 下午3:12:19 25 * @ 26 * 27 */ 28 public class NameListServiceTest { 29 @Test 30 public void testGetAllEmployees() { 31 NameListService service = new NameListService(); 32 33 Employee[] employees = service.getAllEmployees(); 34 35 for(int i = 0; i < employees.length;i++) { 36 37 System.out.println(employees[i]); 38 } 39 40 } 41 42 @Test 43 public void testGetEmployee() { 44 NameListService service = new NameListService(); 45 int id = 1; 46 id = 101; 47 try { 48 Employee employee = service.getEmployee(id); 49 System.out.println(employee); 50 } catch (TeamException e) { 51 52 System.out.println(e.getMessage()); 53 } 54 55 } 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 }
com.bytezero.team.view
1 package com.bytezero.team.view; 2 3 import java.util.Scanner; 4 5 /** 6 * 7 * @Description 项目中提供了TSUtility.java类,可用来方便地实现键盘访问 8 * @author Bytezero·zhenglei! Email:420498246@qq.com 9 * @version 10 * @date 上午9:53:19 11 * @ 12 * 13 */ 14 public class TSUtility { 15 private static Scanner scanner = new Scanner(System.in); 16 17 /** 18 * 19 * @Description 该方法读取键盘 如果用户键入 1-4 中的任意字符,则方法返回,返回值为用户键入字符 20 * @author Bytezero·zhenglei! Email:420498246@qq.com 21 * @version 22 * @date 上午9:53:19 23 * @ 24 * 25 */ 26 27 public static char readMenuSelection() { 28 29 char c; 30 for(;;) { 31 String str = readKeyBoard(1,false); 32 c = str.charAt(0); 33 if( c != '1' && c != '2' && c != '3' && c != '4') { 34 System.out.println("选择错误,请重新输入:"); 35 }else break; 36 37 } 38 return c; 39 } 40 41 /** 42 * 43 * @Description 该方法提示并等待,直到用户按回车键后返回 44 * @author Bytezero·zhenglei! Email:420498246@qq.com 45 * @version 46 * @date 上午9:53:19 47 * @ 48 * 49 */ 50 public static void readReturn() { 51 System.out.println("按回车键继续..."); 52 readKeyBoard(100,true); 53 } 54 55 /** 56 * 57 * @Description 该方法从键盘读取一个长度不超过2位的整数,并将其作为方法的返回值 58 * @author Bytezero·zhenglei! Email:420498246@qq.com 59 * @version 60 * @date 上午9:53:19 61 * @ 62 * 63 */ 64 public static int readInt() { 65 66 int n ; 67 for(;;) { 68 String str = readKeyBoard(2,false); 69 try { 70 n = Integer.parseInt(str); 71 break; 72 }catch(NumberFormatException e) { 73 System.out.println("数字输入错误,请重新输入:"); 74 } 75 } 76 return n; 77 } 78 79 /** 80 * 81 * @Description 从键盘读取‘Y’或‘N’,并将其作为方法的返回值 82 * @author Bytezero·zhenglei! Email:420498246@qq.com 83 * @version 84 * @date 上午9:53:19 85 * @ 86 * 87 */ 88 public static char readConfirmSelection() { 89 char c; 90 for(;;) { 91 String str = readKeyBoard(1,false).toUpperCase(); 92 c = str.charAt(0); 93 if(c == 'Y' || c == 'N') { 94 break; 95 }else { 96 System.out.println("选择错误,请重新输入:"); 97 } 98 } 99 return c; 100 } 101 102 private static String readKeyBoard(int limit,boolean blankReturn) { 103 String line = ""; 104 105 while(scanner.hasNextLine()) { 106 line = scanner.nextLine(); 107 if(line.length() == 0) { 108 if(blankReturn) return line; 109 else continue; 110 } 111 112 if(line.length() < 1 || line.length() > limit) { 113 System.out.println("输入长度(不大于" + limit + ")错误,请重新输入:"); 114 continue; 115 } 116 break; 117 } 118 return line; 119 } 120 121 122 123 124 125 126 127 128 129 }
1 package com.bytezero.team.view; 2 3 import com.bytezero.team.domain.Employee; 4 import com.bytezero.team.domain.Programmer; 5 import com.bytezero.team.service.NameListService; 6 import com.bytezero.team.service.TeamException; 7 import com.bytezero.team.service.TeamService; 8 9 public class TeamView { 10 11 12 private NameListService listSvc = new NameListService(); 13 14 private TeamService teamSvc = new TeamService(); 15 16 public void enterMainMenu() { 17 18 19 boolean loopFlag = true; 20 char menu =0; 21 while(loopFlag) { 22 23 if(menu != '1') { 24 listAllEmployee(); 25 } 26 27 28 System.out.println("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4): " ); 29 menu = TSUtility.readMenuSelection(); 30 switch(menu) { 31 case '1': 32 getTeam(); 33 break; 34 35 case '2': 36 37 addMember(); 38 break; 39 40 case '3': 41 42 deleteMember(); 43 break; 44 45 case '4': 46 //System.out.println("退出"); 47 System.out.print("确认是否要退出(Y/N): "); 48 char isExit = TSUtility.readConfirmSelection(); 49 if(isExit =='Y') { 50 loopFlag = false; 51 System.out.println("已成功退出!"); 52 } 53 break; 54 } 55 56 } 57 58 } 59 /*** 60 * 显示所有员工的信息 61 */ 62 private void listAllEmployee() { 63 // System.out.println("显示所有员工的信息"); 64 65 System.out.println("---------------------------------开发团队调度软件--------------------------------------"); 66 System.out.println(" ----author: (Bytezero·zhenglei!)\n"); 67 68 Employee[] employees = listSvc.getAllEmployees(); 69 if(employees == null && employees.length ==0) { 70 System.out.println("公司中没有任何员工信息!"); 71 }else { 72 System.out.println("ID\t姓名\t年龄\t工资\t职位\t状态\t奖金\t股票\t领用设备"); 73 74 for(int i =0;i<employees.length;i++) { 75 System.out.println(employees[i]); 76 } 77 78 } 79 System.out.println("----------------------------------------------------------------------------------------"); 80 81 } 82 private void getTeam() { 83 // System.out.println("查看开发团队情况"); 84 85 System.out.println("--------------------团队成员列表--------------------\n"); 86 87 Programmer[] team = teamSvc.getTeam(); 88 if(team == null || team.length ==0) { 89 System.out.println("开发团队目前没有成员!"); 90 91 }else { 92 System.out.println("TID/ID\t姓名\t年龄\t工资\t职位\t奖金\t股票\n"); 93 for(int i =0;i<team.length;i++) { 94 System.out.println(team[i].getDetailsForTeam()); 95 } 96 97 } 98 99 System.out.println("---------------------------------------------------"); 100 101 102 103 } 104 private void addMember() { 105 // System.out.println("添加团队成员"); 106 107 System.out.println("----------------------添加成员----------------------"); 108 System.out.print("请输入要添加成员的ID:"); 109 int id = TSUtility.readInt(); 110 111 try { 112 Employee emp = listSvc.getEmployee(id); 113 teamSvc.addMenmber(emp); 114 System.out.println("添加成功"); 115 116 117 } catch (TeamException e) { 118 System.out.println("添加失败,原因:"+ e.getMessage()); 119 } 120 121 //按回车键继续 122 TSUtility.readReturn(); 123 124 125 } 126 private void deleteMember() { 127 // System.out.println("删除团队成员"); 128 System.out.println("----------------------删除员工----------------------"); 129 System.out.println("请输入要删除员工的TID: "); 130 int memberId = TSUtility.readInt(); 131 132 133 System.out.print("确认是否删除(Y/N): "); 134 char isDelete = TSUtility.readConfirmSelection(); 135 if(isDelete=='N') { 136 return; 137 } 138 try { 139 teamSvc.removeMember(memberId); 140 System.out.println("删除成功"); 141 } catch (TeamException e) { 142 System.out.println("删除失败,原因:"+e.getMessage()); 143 } 144 145 //按回车键继续 146 TSUtility.readReturn(); 147 148 } 149 150 151 152 public static void main(String[] args) { 153 TeamView view = new TeamView(); 154 view.enterMainMenu(); 155 } 156 }
/** * * @Description Java 开发人员调度软件项目 (java基础编程总结项目) * +javaBean+测试代码+数组知识+数据结构+继承+多态+封装+自定义异常,异常处理 * +构造器知识+重载+重写+接口+实现接口+关键字使用(static +equalsIgnoreCase+fianl+instanceof判断类型) * +向下转型与向上转型 * @author Bytezero·zhenglei! Email:420498246@qq.com * @version * @date 下午12:00:33 * @ * */