https://www.bilibili.com/video/BV1Kb411W75N
跟着尚硅谷网课做阶段小项目~
比较简单的一个小项目,主要是回顾下两周JAVA基础的学习





第一步——创建项目基本组件

键盘访问的实现

package kx.view;
import java.util.*;
/**
*
* @Description 项目中提供了TSUtility.java类,可用来方便地实现键盘访问。
* @author shkstart Email:shkstart@126.com
* @version
* @date 2019年2月12日上午12:02:58
*
*/
public class TSUtility {
private static Scanner scanner = new Scanner(System.in);
/**
*
* @Description 该方法读取键盘,如果用户键入’1’-’4’中的任意字符,则方法返回。返回值为用户键入字符。
* @author shkstart
* @date 2019年2月12日上午12:03:30
* @return
*/
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.print("选择错误,请重新输入:");
} else break;
}
return c;
}
/**
*
* @Description 该方法提示并等待,直到用户按回车键后返回。
* @author shkstart
* @date 2019年2月12日上午12:03:50
*/
public static void readReturn() {
System.out.print("按回车键继续...");
readKeyBoard(100, true);
}
/**
*
* @Description 该方法从键盘读取一个长度不超过2位的整数,并将其作为方法的返回值。
* @author shkstart
* @date 2019年2月12日上午12:04:04
* @return
*/
public static int readInt() {
int n;
for (; ; ) {
String str = readKeyBoard(2, false);
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
/**
*
* @Description 从键盘读取‘Y’或’N’,并将其作为方法的返回值。
* @author shkstart
* @date 2019年2月12日上午12:04:45
* @return
*/
public static char readConfirmSelection() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false).toUpperCase();
c = str.charAt(0);
if (c == 'Y' || c == 'N') {
break;
} else {
System.out.print("选择错误,请重新输入:");
}
}
return c;
}
private static String readKeyBoard(int limit, boolean blankReturn) {
String line = "";
while (scanner.hasNextLine()) {
line = scanner.nextLine();
if (line.length() == 0) {
if (blankReturn) return line;
else continue;
}
if (line.length() < 1 || line.length() > limit) {
System.out.print("输入长度(不大于" + limit + ")错误,请重新输入:");
continue;
}
break;
}
return line;
}
}
Euqipment接口及其实现子类的设计
package kx.domain;
/**
* @Description
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:00:50
*/
public interface Equipment {
public String getDescription();
}
package kx.domain;
/**
* @Description
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:03:06
*/
public class NoteBook implements Equipment{
private String model;
private double 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;
}
public NoteBook(String model, double price) {
super();
this.model = model;
this.price = price;
}
public NoteBook() {
super();
}
@Override
public String getDescription() {
return model + "(" + price + ")";
}
}
package kx.domain;
/**
* @Description String model,display;
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:10:17
*/
public class PC implements Equipment{
private String model,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;
}
public PC() {
super();
}
public PC(String model, String display) {
super();
this.model = model;
this.display = display;
}
@Override
public String getDescription() {
return model + "(" + display + ")";
}
}
package kx.domain;
/**
* @Description
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:08:03
*/
public class Printer implements Equipment{
private String name,type;
public Printer() {
super();
}
public Printer(String name, String type) {
super();
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 type + "(" + name + ")";
}
}
Employee类及其子类的设计


package kx.service;
/**
* @Description
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:22:33
*/
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 VOCATION = new Status("VOCATION");
public static final Status BUSY = new Status("BUSY");
public String getNAME() {
return NAME;
}
@Override
public String toString() {
return NAME;
}
}

package kx.domain;
/**
* @Description
* int id;
String name;
int age;
double salary;
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:01:00
*/
public class Employee {
int id;
String name;
int age;
double 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 Employee(int id, String name, int age, double salary) {
super();
this.id = id;
this.name = name;
this.age = age;
this.salary = salary;
}
public String getString() {
return "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary ;
}
@Override
public String toString() {
return "Employee [id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + "]";
}
}
package kx.domain;
import kx.service.Status;
/**
* @Description
* private int memberId;
private Status status = Status.FREE;
private Equipment equipment;
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:21:21
*/
public class Programmer extends Employee{
private int memberId;
private Status status = Status.FREE;
private Equipment equipment = null;
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;
}
public Programmer(int id, String name, int age, double salary, int memberId, Status status, Equipment equipment) {
super(id, name, age, salary);
this.memberId = memberId;
this.status = status;
this.equipment = equipment;
}
public String getString() {
return super.getString() + ", memberId=" + memberId + ", status=" + status + ", equipment=" + equipment.getDescription() ;
}
@Override
public String toString() {
return "Programmer [" + super.getString() + ", memberId=" + memberId + ", status=" + status + ", equipment=" + equipment.getDescription() + "]";
}
}
package kx.domain;
import kx.service.Status;
/**
* @Description
* Equipment equipment;
* double bouns;
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:29:58
*/
public class Designer extends Programmer{
private double bouns;
public double getBouns() {
return bouns;
}
public void setBouns(double bouns) {
this.bouns = bouns;
}
public Designer(int id, String name, int age, double salary, int memberId, Status status, Equipment equipment,
double bouns) {
super(id, name, age, salary, memberId, status, equipment);
this.bouns = bouns;
}
public String getString() {
return super.getString() + ", bouns=" + bouns ;
}
@Override
public String toString() {
return "Designer [" + super.getString() + ", bouns=" + bouns + "]";
}
}
package kx.domain;
import kx.service.Status;
/**
* @Description
* int stock;
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:30:10
*/
public class Architect extends Designer{
private int stock;
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
public Architect(int id, String name, int age, double salary, int memberId, Status status, Equipment equipment,
double bouns, int stock) {
super(id, name, age, salary, memberId, status, equipment, bouns);
this.stock = stock;
}
public String getString() {
return super.getString() + ", stock="+ stock ;
}
@Override
public String toString() {
return "Architect [" + super.getString() + ", stock="+ stock + "]";
}
}
实现service包中的类



package kx.service;
import org.junit.Test;
import kx.domain.Architect;
import kx.domain.Designer;
import kx.domain.Employee;
import kx.domain.Equipment;
import kx.domain.NoteBook;
import kx.domain.PC;
import kx.domain.Printer;
import kx.domain.Programmer;
/**
* @Description
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午2:36:41
*/
public class NameListService {
//employee是指针
private Employee []employee;
private int totalEmployee;
public int getTotalEmployee() {
return totalEmployee;
}
public NameListService() {
super();
totalEmployee = Data.EMPLOYEES.length;
employee = new Employee[totalEmployee];
for(int i = 0; i < totalEmployee; i++){
int type = Integer.parseInt(Data.EMPLOYEES[i][0]);
int id = Integer.parseInt(Data.EMPLOYEES[i][1]);
String name = Data.EMPLOYEES[i][2];
int age = Integer.parseInt(Data.EMPLOYEES[i][3]);
double salary = Double.parseDouble(Data.EMPLOYEES[i][4]);
int memberId = -1;//初始化均不在团队中
Status status = Status.FREE;//初始化均空闲状态
Equipment eq = null;//多态性的体现
double bouns;
int stock;
switch(type){
case Data.EMPLOYEE:
employee[i] = new Employee(id,name,age,salary);
break;
case Data.PROGRAMMER:
eq = getEquipment(i);
employee[i] = new Programmer(id,name,age,salary,memberId,status,eq);
break;
case Data.DESIGNER:
eq = getEquipment(i);
bouns = Double.parseDouble(Data.EMPLOYEES[i][5]);
employee[i] = new Designer(id,name,age,salary,memberId,status,eq,bouns);
break;
case Data.ARCHITECT:
eq = getEquipment(i);
bouns = Double.parseDouble(Data.EMPLOYEES[i][5]);
stock = Integer.parseInt(Data.EMPLOYEES[i][6]);
employee[i] = new Architect(id,name,age,salary,memberId,status,eq,bouns,stock);
break;
}
}
}
private Equipment getEquipment(int i){
int typeModel = Integer.parseInt(Data.EQUIPMENTS[i][0]);
String model = null,display = null,type = null,name = null;
double price = 0;
Equipment eq= null;
switch (typeModel){
case Data.PC:
model = Data.EQUIPMENTS[i][1];
display = Data.EQUIPMENTS[i][2];
eq = new PC(model,display);
break;
case Data.NOTEBOOK:
model = Data.EQUIPMENTS[i][1];
price = Double.parseDouble(Data.EQUIPMENTS[i][2]);
eq = new NoteBook(model,price);
break;
case Data.PRINTER:
name = Data.EQUIPMENTS[i][1];
type = Data.EQUIPMENTS[i][2];
eq = new Printer(name,type);
break;
}
return eq;
}
public Employee[] getAllEmployees(){
//要新建一个类数组对象,然后赋值,不能直接赋值this.employee指针(防止其被修改)
Employee []employee = new Employee[this.totalEmployee];
for(int i = 0;i < this.totalEmployee; i++)
employee[i] = this.employee[i];
return employee;
}
public Employee getEmployee(int id) throws TeamException{
if(id <= 0 || id > totalEmployee){
throw new TeamException("找不到指定的员工!");
}
return employee[id - 1];
}
}
TeamService类的设计


package kx.service;
import kx.domain.Architect;
import kx.domain.Designer;
import kx.domain.Employee;
import kx.domain.Programmer;
/**
* @Description
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午4:24:45
*/
public class TeamService {
private static int counter = 1;
private static int numProgrammer = 0;
private static int numDesigner = 0;
private static int numArchitect = 0;
private static final int MAX_MEMBER = 5;
private Programmer []team = new Programmer[5];
private int total = 0;
/**
*
* @Function: TeamService.java
* @Description: 添加团队成员
* @param: Employee类 团队成员
* @return:void
* @throws:TeamException
* @version: v1.0.0
* @author: KX
* @date: 2020年10月27日 下午9:34:17
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2020年10月27日 Administrator v1.0.0 修改原因
*/
public void addMember(Employee e)throws TeamException{
if(total >= MAX_MEMBER)
throw new TeamException("团队成员已满!");
if(!(e instanceof Programmer))
throw new TeamException("该成员不是开发人员,无法添加!");
Programmer tmp = (Programmer)e;
if(tmp.getStatus() == Status.VOCATION)
throw new TeamException("该员正在休假,无法添加!");
for(int i = 0 ;i < total ;i++){
if(team[i].getId() == e.getId())
throw new TeamException("该员工已在本开发团队中!");
}
if(tmp.getStatus() == Status.BUSY)
throw new TeamException("该员工已是某团队成员!");
if(e instanceof Architect){
if(numArchitect >=1)
throw new TeamException("团队中至多只能有一名架构师!");
numArchitect++;
}
else if(e instanceof Designer){
if(numDesigner >=2)
throw new TeamException("团队中至多只能有两名设计师!");
numDesigner++;
}
else{
if(numProgrammer >=3 )
throw new TeamException("团队中至多只能有三名程序员!");
numProgrammer++;
}
team[total] = tmp;
tmp.setStatus(Status.BUSY);
team[total++].setMemberId(counter++);
}
/**
*
* @Function: TeamService.java
* @Description: 删除团队成员
* @param: 待删除团队成员的团队TID
* @return:void
* @throws:TeamException
* @version: v1.0.0
* @author: KX
* @date: 2020年10月27日 下午9:34:17
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2020年10月27日 Administrator v1.0.0 修改原因
*/
public void removeMember(int memberId)throws TeamException{
for(int i = 0;i < total; i++){
if(team[i].getMemberId() == memberId){
team[i].setStatus(Status.FREE);
Programmer e = team[i];
if(e instanceof Architect){
numArchitect--;
}
else if(e instanceof Designer){
numDesigner--;
}
else{
numProgrammer--;
}
for(int j = i;j + 1 < total;j++){
team[j] = team[j + 1];
}
total--;
return ;
}
}
throw new TeamException("该成员不在团队中!");
}
public TeamService() {
super();
}
public TeamService(Programmer[] team, int total) {
super();
this.team = team;
this.total = total;
}
public static int getCounter() {
return counter;
}
public static void setCounter(int counter) {
TeamService.counter = counter;
}
public Programmer[] getTeam() {
Programmer[] team = new Programmer[total];
for(int i = 0; i < total; i++){
team[i] = this.team[i];
}
return team;
}
public void setTeam(Programmer[] team) {
this.team = team;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public static int getMaxMember() {
return MAX_MEMBER;
}
}
TeamException 自定义异常类
package kx.service;
/**
* @Description
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午6:36:58
*/
public class TeamException extends Exception{
static final long serialVersionUID = -1702031019931249948L;
public TeamException() {
super();
}
public TeamException(String message) {
super(message);
}
}
Data数据
package kx.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
/**
* {"10", "1", "马云", "22", "3000"},
* {"13", "2", "马化腾", "32", "18000", "15000", "2000"},
*/
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"}
};
}
第三步——实现view包中的类


package kx.view;
import java.util.Scanner;
import kx.domain.Architect;
import kx.domain.Designer;
import kx.domain.Employee;
import kx.domain.Programmer;
import kx.service.NameListService;
import kx.service.TeamException;
import kx.service.TeamService;
/**
* @Description
* @author 作者 KX
* @version
* @date 创建时间:2020年10月27日 下午8:29:24
-------------------------------开发团队调度软件--------------------------------
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):
--------------------团队成员列表---------------------
TID/ID 姓名 年龄 工资 职位 奖金 股票
1/3 李彦宏 23 7000.0 程序员
-----------------------------------------------------
*/
public class TeamView {
private NameListService listSvc = new NameListService();
private TeamService teamSvc= new TeamService();
public void enterMainMenu(){
boolean flag = true;
char opt = '0',confirm;
while(flag){
if(opt != '1')
listAllEmployees();
System.out.print("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4):");
TSUtility tsu = new TSUtility();
System.out.println("");
opt = tsu.readMenuSelection();
switch(opt){
case '1':
getTeam();
break;
case '2':
addMember();
break;
case '3':
deleteMember();
break;
case '4':
System.out.print("确认是否退出(Y/N):");
confirm = tsu.readConfirmSelection();
if(confirm == 'Y')
flag = false;
break;
}
}
}
/**
*
* @Function: TeamView.java
* @Description: 以表格形式列出公司所有成员
* @param:参数描述
* @return:返回结果描述
* @throws:异常描述
* @version: v1.0.0
* @author: KX
* @date: 2020年10月27日 下午9:25:46
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2020年10月27日 Administrator v1.0.0 修改原因
*/
private void listAllEmployees(){
System.out.println("-------------------------------开发团队调度软件--------------------------------");
System.out.println("ID\t姓名\t年龄\t工资\t职位\t状态\t奖金\t股票\t领用设备");
Employee[] es = listSvc.getAllEmployees();
for(int i = 0;i < es.length;i++){
if(es[i] instanceof Architect){
Architect tmp = (Architect)es[i];
System.out.println(tmp.getId() + "\t" + tmp.getName() + "\t" +tmp.getAge() + "\t"
+ tmp.getSalary() + "\t" + "架构师\t" + tmp.getStatus() + "\t" + tmp.getBouns()
+ "\t" + tmp.getStock() + "\t" + tmp.getEquipment().getDescription());
}
else if(es[i] instanceof Designer){
Designer tmp = (Designer)es[i];
System.out.println(tmp.getId() + "\t" + tmp.getName() + "\t" +tmp.getAge() + "\t"
+ tmp.getSalary() + "\t" + "设计师\t" + tmp.getStatus() + "\t" + tmp.getBouns()
+ "\t" + "\t" + tmp.getEquipment().getDescription());
}
else if(es[i] instanceof Programmer){
Programmer tmp = (Programmer)es[i];
System.out.println(tmp.getId() + "\t" + tmp.getName() + "\t" +tmp.getAge() + "\t"
+ tmp.getSalary() + "\t" + "程序员\t" + tmp.getStatus() + "\t"
+ "\t" + "\t" + tmp.getEquipment().getDescription());
}
else{
Employee tmp = es[i];
System.out.println(tmp.getId() + "\t" + tmp.getName() + "\t" +tmp.getAge() + "\t"
+ tmp.getSalary() + "\t" + "\t" + "\t"
+ "\t" + "\t");
}
}
System.out.println("-------------------------------------------------------------------------------");
}
/**
*
* @Function: TeamView.java
* @Description: 显示团队成员列表操作
* @param: void
* @return:void
* @throws:无
* @version: v1.0.0
* @author: KX
* @date: 2020年10月27日 下午9:24:59
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2020年10月27日 Administrator v1.0.0 修改原因
*/
private void getTeam(){
if(teamSvc.getTotal() == 0)
System.out.println("开发团队目前没有成员!");
else{
System.out.println("TID/ID\t姓名\t年龄\t工资\t职位\t奖金\t股票");
Programmer[] es = teamSvc.getTeam();
for(int i = 0; i < es.length; i++){
if(es[i] instanceof Architect){
Architect tmp = (Architect)es[i];
System.out.println(" " + tmp.getMemberId() + "/" + tmp.getId() + "\t" + tmp.getName()
+ "\t" +tmp.getAge() + "\t" + tmp.getSalary() + "\t" + "架构师\t"
+ "\t" + tmp.getBouns() + "\t" + tmp.getStock());
}else if(es[i] instanceof Designer){
Designer tmp = (Designer)es[i];
System.out.println(" " + tmp.getMemberId() + "/" + tmp.getId() + "\t" + tmp.getName()
+ "\t" +tmp.getAge() + "\t" + tmp.getSalary() + "\t" + "设计师\t"
+ "\t" + tmp.getBouns() + "\t");
}else {
Programmer tmp = es[i];
System.out.println(" " + tmp.getMemberId() + "/" + tmp.getId() + "\t" + tmp.getName()
+ "\t" +tmp.getAge() + "\t" + tmp.getSalary() + "\t" + "程序员\t"
+ "\t" + "\t");
}
}
}
}
/**
*
* @Function: TeamView.java
* @Description: 实现添加成员操作
* @param: 传入要添加成员的id
* @return:void
* @throws:TeamException - 会显示具体错误信息
* @version: v1.0.0
* @author: KX
* @date: 2020年10月27日 下午9:26:00
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2020年10月27日 Administrator v1.0.0 修改原因
*/
private void addMember(){
System.out.println("---------------------添加成员---------------------");
System.out.print("请输入要添加的员工ID:");
int id = TSUtility.readInt();
try{
Employee ep = listSvc.getEmployee(id);
teamSvc.addMember(ep);
System.out.println("添加成功!");
}catch(TeamException e){
System.out.print("添加失败,原因:");
System.out.println(e.getMessage());
}
TSUtility.readReturn();
}
/**
*
* @Function: TeamView.java
* @Description: 实现删除成员操作
* @param: 传入要删除的成员的团队TID
* @return:void
* @throws:TeamException - 会显示具体错误信息
* @version: v1.0.0
* @author: KX
* @date: 2020年10月27日 下午9:26:38
*
* Modification History:
* Date Author Version Description
*---------------------------------------------------------*
* 2020年10月27日 Administrator v1.0.0 修改原因
*/
private void deleteMember (){
System.out.println("---------------------删除成员---------------------");
System.out.print("请输入要删除员工的TID:");
int memberId = TSUtility.readInt();
System.out.print("确认是否删除(Y/N):");
char confirm = TSUtility.readConfirmSelection();
if(confirm == 'N')
return;
try{
teamSvc.removeMember(memberId);
System.out.println("删除成功!");
}catch(TeamException e){
System.out.print("删除失败,失败原因:");
System.out.println(e.getMessage());
}
TSUtility.readReturn();
}
public static void main(String[] args) {
TeamView tv1 = new TeamView();
tv1.enterMainMenu();
}
}
项目总结:
很简单的项目,但考察的东西很多(基础向):多态、封装、继承等都有体现、以及基本语法和数组的使用,异常处理等知识点。
是比较好巩固基础的一个项目,尚硅谷JAVA网课太NB了!
一些细节:
在输出表的时候,没有利用好toString,导致码量比标程要长。
一些小BUG用debug调试很快就能找出来,这种一般都是越界的bug。
以及,1000+的算法题编程积累下的码力还是很有用的。
最后接着学习尚硅谷JAVA高级去了~
版权声明:本文为bjfu170203101原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
