项目开发团队分配管理软件

项目仍有些小bug 后期完善  

目录

一、功能需求

 二、目标

 三、需求说明

四、软件设计结构

​1.domain模块

①Equipment接口、PC、NoteBook、Printer类

②Employee及其子类

③Programmer类(项目)

 2.Service模块

①TeamException(自定义异常)

②NameListService

③TeamService

④ProjectService

3.view模块

①LoginView类


一、功能需求

 二、目标

 三、需求说明

四、软件设计结构

1.domain模块

①Equipment接口、PC、NoteBook、Printer类

package domain;

public interface Equipment {
	String getDescription();
}
package domain;
import view.TSUtility;
//台式电脑
	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;
	}
    
    //进行添加电脑的操作
	public PC  addPC()
	{
		System.out.println("请输入需要配置的台式电脑的型号:");
		String model = TSUtility.readKeyBoard(10, false);
		System.out.println("请输入需要配置的台式电脑的显示器名称:");
		String display = TSUtility.readKeyBoard(10, false);
		System.out.println("设备添加成功!");
		return new PC(model, display);

	}
	@Override
	public String getDescription() {
		return model + "(" + display + ")";
	}
	
}
package domain;
import view.TSUtility;

//笔记本电脑
public class NoteBook implements Equipment{
	private String model;//机器的型号
	private double price;//价格
	
	
	public NoteBook() {
		super();
	}


	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;
	}

    //进行添加笔记本的操作
	public NoteBook addNoteBook()
	{
		System.out.println("请输入需要配置的笔记本电脑的型号:");
		String model = TSUtility.readKeyBoard(10, false);
		System.out.println("请输入需要配置的笔记本电脑的价格:");
		Double price = TSUtility.readDouble();
		System.out.println("设备添加成功!");
		return new NoteBook(model, price);
	}


	@Override
	public String getDescription() {
		return model + "(" + price + ")";
	}
	
	

}
package domain;

import view.TSUtility;
//打印机
public class Printer implements Equipment{
	private String name;//名称
	private String 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;
	}

    //进行添加打印机的操作
	public Printer addPrinter()
	{
		System.out.println("请输入需要配置的打印机的名称:");
		String model = TSUtility.readKeyBoard(10, false);
		System.out.println("请输入需要配置的打印机的类型:");
		String display = TSUtility.readKeyBoard(10, false);
		System.out.println("设备添加成功!");
		return new Printer(model, display);
	}

	@Override
	public String getDescription() {
		return name + "(" + type + ")";
	}
	
	

}

②Employee及其子类

package domain;

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 getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    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 double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    protected String getDetails() {
        return id + "\t" + name + "\t" + age+ "\t\t" +salary;
    }

    @Override
    public String toString() {
        return getDetails();
    }
}

 

package domain;

public class Programmer extends Employee {
    private int memberId;
    //用来记录成员加入开发团队后在团队中的ID
    private boolean status = true;
    //表示项目中人员的状态,先赋值为true,当添加到团队时为alse
    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 Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public Equipment getEquipment() {
        return equipment;
    }

    public void setEquipment(Equipment equipment) {
        this.equipment = equipment;
    }

    public int getMemberId() {
        return memberId;
    }

    public void setMemberId(int memberId) {
        this.memberId = memberId;
    }

    protected String getMemberDetails() {
        return getMemberId() + "/" + getDetails();
    }

    public String getDetailsForTeam() {
        return getMemberDetails() + "\t程序员";
    }

    @Override
    public String toString() {
        return getDetails() + "\t程序员\t" + status + "\t\t\t\t\t" +         
           equipment.getDescription() ;
    }
}

package domain;

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;
    }

    public String getDetailsForTeam() {
        return getMemberDetails() + "\t设计师\t" + getBonus();
    }

    @Override
    public String toString() {
        return getDetails() + "\t设计师\t" + getStatus() + "\t" +
               getBonus() +"\t\t\t" + getEquipment().getDescription();
    }
}

③Programmer类(项目)

package domain;

public class  Project {
    /**
     * 项目号 proId
     * 项目名称 projectName
     * 项目描述 desName
     * 开发团队 team
     * 开发团队名称 teamName
     * 开发状态 status (true为开发中,false为未开发中))
     */
    private int proId;
    private String proName;
    private String desName;
    private Programmer[] team;
    private String teamName;
    private boolean status = false;

    public Project() {
    }

    public Project(int proId, String proName, String desName, Programmer[] team, String teamName, boolean status) {
        this.proId = proId;
        this.proName = proName;
        this.desName = desName;
        this.team = team;
        this.teamName = teamName;
        this.status = status;
    }

    public int getProId() {
        return proId;
    }

    public void setProId(int proId) {
        this.proId = proId;
    }

    public String getProName() {
        return proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public String getDesName() {
        return desName;
    }

    public void setDesName(String desName) {
        this.desName = desName;
    }

    public Programmer[] getTeam() {
        return team;
    }

    public void setTeam(Programmer[] team) {
        this.team = team;
    }

    public String getTeamName() {
        return teamName;
    }

    public void setTeamName(String teamName) {
        this.teamName = teamName;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }


    public String des() {
        return "项目{" +
                "项目号='" + proId + '\'' +
                "项目名='" + proName + '\'' +
                ", 项目描述='" + desName + '\'' +
                ", 开发团队名称='" + teamName + '\'' +
                ", 开发状态=" + status +
                '}' + "\n";
    }

    @Override
    public String toString() {
        des();
        if (status) {
            return "项目【" + proName + "】" + "---->正在被团队【" + teamName + "】开发中!";
        } else {
            return des() + "项目【" + proName + "】---->" + "未被开发!";
        }
    }
}

 2.Service模块

①TeamException(自定义异常)

package service;

public class TeamException extends Exception {

	public TeamException() {
	}

	public TeamException(String message) {
		super(message);
	}
}

②NameListService

定义员工集合、员工id

  private ArrayList<Employee> employees = new ArrayList<>();
    //添加员工id
    private int count = 1;

 初始化默认值

   //初始化默认值
    {
        employees.add(new Employee(count, "马云 ", 22, 3000));
        employees.add(new Architect(++count, "马化腾", 32, 18000, new NoteBook("联想T4", 6000), 60000, 5000));
        employees.add(new Programmer(++count, "李彦宏", 23, 7000, new PC("戴尔", "NEC 17寸")));
        employees.add(new Programmer(++count, "刘强东", 24, 7300, new PC("戴尔", "三星 17寸")));
        employees.add(new Designer(++count, "雷军 ", 50, 10000, new Printer("激光", "佳能2900"), 5000));
        employees.add(new Programmer(++count, "任志强", 30, 16800, new PC("华硕", "三星 17寸")));
        employees.add(new Designer(++count, "柳传志", 45, 35500, new PC("华硕", "三星 17寸"), 8000));
        employees.add(new Architect(++count, "杨元庆", 35, 6500, new Printer("针式", "爱普生20k"), 15500, 1200));
        employees.add(new Designer(++count, "史玉柱", 27, 7800, new NoteBook("惠普m6", 5800), 1500));
        employees.add(new Programmer(++count, "丁磊 ", 26, 6600, new PC("戴尔", "NEC17寸")));
        employees.add(new Programmer(++count, "张朝阳 ", 35, 7100, new PC("华硕", "三星 17寸")));
        employees.add(new Designer(++count, "杨致远", 38, 9600, new NoteBook("惠普m6", 5800), 3000));
    }

定义:添加员工方法

public void addEmployee() {
        System.out.println("请输入需要添加的雇员的职位:");
        System.out.println("1(无职位)");
        System.out.println("2(程序员)");
        System.out.println("3(设计师)");
        System.out.println("4(架构师)");
        String c = String.valueOf(TSUtility.readMenuSelection());
        //此处调用工具类  拖到底下就可以看到
        if (c.equals("1")) {
            System.out.println("当前职位分配为无");
            System.out.println("请输入当前雇员的姓名");
            String name = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入当前雇员的年龄:");
            int age = TSUtility.readInt();
            System.out.println("请输入当前雇员的工资:");
            Double salary = TSUtility.readDouble();
            Employee employee = new Employee(++count, name, age, salary);
            employees.add(employee);
            System.out.println("人员添加成功");
            TSUtility.readReturn();
        } else if (c.equals("2")) {
            System.out.println("当前雇员职位分配为:程序员");
            System.out.println("请输入当前雇员的姓名:");
            String name = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入当前雇员的年龄:");
            int age = TSUtility.readInt();
            System.out.println("请输入当前雇员的工资:");
            Double salary = TSUtility.readDouble();
            System.out.println("请为当前程序员配一台好的台式电脑:");
            PC pc = new PC().addPC();
            Programmer programmer = new Programmer(++count, name, age, salary, pc);
            employees.add(programmer);
            System.out.println("人员添加成功");
            TSUtility.readReturn();
        } else if (c.equals("3")) {
            System.out.println("`当前雇员职位分配为:设计师");
            System.out.println("请输入当前雇员的姓名:");
            String name = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入当前雇员的年龄:");
            int age = TSUtility.readInt();
            System.out.println("请输入当前雇员的工资:");
            Double salary = TSUtility.readDouble();
            System.out.println("请为当前设计师配一台好的笔记本电脑:");
            NoteBook noteBook=new NoteBook().addNoteBook();
            System.out.println("请输入当前设计师的奖金:");
            Double bonus = TSUtility.readDouble();
            Programmer programmer = new Designer(++count, name, age, salary, noteBook,bonus);
            employees.add(programmer);
            System.out.println("人员添加成功!");
            TSUtility.readReturn();
        } else {
            System.out.println("`当前雇员职位分配为:架构师");
            System.out.println("请输入当前雇员的姓名:");
            String name = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入当前雇员的年龄:");
            int age = TSUtility.readInt();
            System.out.println("请输入当前雇员的工资:");
            Double salary = TSUtility.readDouble();
            System.out.println("请为当前架构师配一台好的打印设备:");
            Printer printer = new Printer().addPrinter();
            System.out.println("请输入当前架构师的奖金:");
            Double bonus = TSUtility.readDouble();
            System.out.println("请输入当前架构师的股票:");
            Integer stock = TSUtility.readstock();
            Architect architect = new Architect(++count, name, age, salary, printer, bonus, stock);
            employees.add(architect);
            System.out.println("人员添加成功!");
            TSUtility.readReturn();
        }
    }

定义:删除员工方法

 public void delEmployee(int id){
        boolean flag = false;
        //删除通常可以定义一个boolean值
        //为true则打印输出成功 为false则抛出异常(try catch)
        for (int i = 0; i < employees.size(); i++) {
            if (employees.get(i).getId() == id) {
                employees.remove(i);
                for (i = id; i <= employees.size(); i++) {
                    employees.get(i - 1).setId(employees.get(i - 1).getId() - 1);
                }
                //如果删除的id为3 那么i就是2
                //首先先找到i  i和id的关系为id-1为i 所以先获得employees.get(i-1)
                //然后设置其 id(找到对应id减一)
                //id为3的设置id为(3-1)为2
                flag = true;
            }
        }
        if (flag) {
            //count--;不存在意义
            System.out.println("删除成功!");
        } else {
            try {
                throw new TeamException("该员工不存在");
            } catch (TeamException e) {
                e.printStackTrace();
            }
        }
    }

定义:修改员工方法

 public void modifyEmpolyee(int id){
        boolean flag=false;
        //定义boolean变量 如删除方法一致
        for (int i = 0; i <employees.size() ; i++) {
            Employee emp = employees.get(i);
            if (id==emp.getId()){
                System.out.print("姓名(" + emp.getName() + "):");
                String name = TSUtility.readString(4, emp.getName());
                System.out.print("年龄(" + emp.getAge() + "):");
                int age = Integer.parseInt(TSUtility.readString(2,emp.getAge()+""));
                System.out.print("工资(" + emp.getSalary() + "):");
                double salary =Double.parseDouble(TSUtility.readString(10, emp.getSalary()+""));
                emp.setName(name);
                emp.setAge(age);
                emp.setSalary(salary);
                flag=true;
        }
            }
        if (flag){
            System.out.println("修改 成功");
        }else {
            try {
                throw new TeamException("该成员不存在");
            }catch (TeamException e){
                e.printStackTrace();
            }
        }
    }

定义:查找员工方法

(1.查找每个员工 2.按照员工id来查找员工 3 .查找员工集合)

 public void showEmployee() {
        System.out.println("ID\t 姓名\t年龄\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
        for(Employee employee:employees){
            System.out.println(" "+employee);
        }
    }
   public Employee getEmployees(int id) throws TeamException {
        for (int i = 0; i < employees.size(); i++) {
            if (id == employees.get(i).getId()) {
                return employees.get(i);
            }
        }
        throw new TeamException("该员工不存在");
    }
   public ArrayList<Employee> geetAllEmployees() {
        return employees;
    }

该类全部代码(上述代码为各部分代码 怕有遗漏 )

package service;

import domain.*;
import view.TSUtility;

import java.util.ArrayList;

public class NameListService {
    private ArrayList<Employee> employees = new ArrayList<>();
    //添加员工id
    private int count = 1;

    //初始化默认值
    {
        employees.add(new Employee(count, "马云 ", 22, 3000));
        employees.add(new Architect(++count, "马化腾", 32, 18000, new NoteBook("联想T4", 6000), 60000, 5000));
        employees.add(new Programmer(++count, "李彦宏", 23, 7000, new PC("戴尔", "NEC 17寸")));
        employees.add(new Programmer(++count, "刘强东", 24, 7300, new PC("戴尔", "三星 17寸")));
        employees.add(new Designer(++count, "雷军 ", 50, 10000, new Printer("激光", "佳能2900"), 5000));
        employees.add(new Programmer(++count, "任志强", 30, 16800, new PC("华硕", "三星 17寸")));
        employees.add(new Designer(++count, "柳传志", 45, 35500, new PC("华硕", "三星 17寸"), 8000));
        employees.add(new Architect(++count, "杨元庆", 35, 6500, new Printer("针式", "爱普生20k"), 15500, 1200));
        employees.add(new Designer(++count, "史玉柱", 27, 7800, new NoteBook("惠普m6", 5800), 1500));
        employees.add(new Programmer(++count, "丁磊 ", 26, 6600, new PC("戴尔", "NEC17寸")));
        employees.add(new Programmer(++count, "张朝阳 ", 35, 7100, new PC("华硕", "三星 17寸")));
        employees.add(new Designer(++count, "杨致远", 38, 9600, new NoteBook("惠普m6", 5800), 3000));
    }

    public ArrayList<Employee> geetAllEmployees() {
        return employees;
    }

    public Employee getEmployees(int id) throws TeamException {
        for (int i = 0; i < employees.size(); i++) {
            if (id == employees.get(i).getId()) {
                return employees.get(i);
            }
        }
        throw new TeamException("该员工不存在");
    }

    public void addEmployee() {
        System.out.println("请输入需要添加的雇员的职位:");
        System.out.println("1(无职位)");
        System.out.println("2(程序员)");
        System.out.println("3(设计师)");
        System.out.println("4(架构师)");
        String c = String.valueOf(TSUtility.readMenuSelection());
        if (c.equals("1")) {
            System.out.println("当前职位分配为无");
            System.out.println("请输入当前雇员的姓名");
            String name = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入当前雇员的年龄:");
            int age = TSUtility.readInt();
            System.out.println("请输入当前雇员的工资:");
            Double salary = TSUtility.readDouble();
            Employee employee = new Employee(++count, name, age, salary);
            employees.add(employee);
            System.out.println("人员添加成功");
            TSUtility.readReturn();
        } else if (c.equals("2")) {
            System.out.println("当前雇员职位分配为:程序员");
            System.out.println("请输入当前雇员的姓名:");
            String name = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入当前雇员的年龄:");
            int age = TSUtility.readInt();
            System.out.println("请输入当前雇员的工资:");
            Double salary = TSUtility.readDouble();
            System.out.println("请为当前程序员配一台好的台式电脑:");
            PC pc = new PC().addPC();
            Programmer programmer = new Programmer(++count, name, age, salary, pc);
            employees.add(programmer);
            System.out.println("人员添加成功");
            TSUtility.readReturn();
        } else if (c.equals("3")) {
            System.out.println("`当前雇员职位分配为:设计师");
            System.out.println("请输入当前雇员的姓名:");
            String name = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入当前雇员的年龄:");
            int age = TSUtility.readInt();
            System.out.println("请输入当前雇员的工资:");
            Double salary = TSUtility.readDouble();
            System.out.println("请为当前设计师配一台好的笔记本电脑:");
            NoteBook noteBook=new NoteBook().addNoteBook();
            System.out.println("请输入当前设计师的奖金:");
            Double bonus = TSUtility.readDouble();
            Programmer programmer = new Designer(++count, name, age, salary, noteBook,bonus);
            employees.add(programmer);
            System.out.println("人员添加成功!");
            TSUtility.readReturn();
        } else {
            System.out.println("`当前雇员职位分配为:架构师");
            System.out.println("请输入当前雇员的姓名:");
            String name = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入当前雇员的年龄:");
            int age = TSUtility.readInt();
            System.out.println("请输入当前雇员的工资:");
            Double salary = TSUtility.readDouble();
            System.out.println("请为当前架构师配一台好的打印设备:");
            Printer printer = new Printer().addPrinter();
            System.out.println("请输入当前架构师的奖金:");
            Double bonus = TSUtility.readDouble();
            System.out.println("请输入当前架构师的股票:");
            Integer stock = TSUtility.readstock();
            Architect architect = new Architect(++count, name, age, salary, printer, bonus, stock);
            employees.add(architect);
            System.out.println("人员添加成功!");
            TSUtility.readReturn();
        }
    }

    public void delEmployee(int id){
        boolean flag = false;
        //删除通常可以定义一个boolean值
        //为true则打印输出成功 为false则抛出异常(try catch)
        for (int i = 0; i < employees.size(); i++) {
            if (employees.get(i).getId() == id) {
                employees.remove(i);
                for (i = id; i <= employees.size(); i++) {
                    employees.get(i - 1).setId(employees.get(i - 1).getId() - 1);
                }
                //如果删除的id为3 那么i就是2
                //首先先找到i  i和id的关系为id-1为i 所以先获得employees.get(i-1)
                //然后设置其 id(找到对应id减一)
                //id为3的设置id为(3-1)为2
                flag = true;
            }
        }
        if (flag) {
            //count--;不存在意义
            System.out.println("删除成功!");
        } else {
            try {
                throw new TeamException("该员工不存在");
            } catch (TeamException e) {
                e.printStackTrace();
            }
        }
    }
    public void showEmployee() {
        System.out.println("ID\t 姓名\t年龄\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
        for(Employee employee:employees){
            System.out.println(" "+employee);
        }
    }

    public void modifyEmpolyee(int id){
        boolean flag=false;
        //定义boolean变量 如删除方法一致
        for (int i = 0; i <employees.size() ; i++) {
            Employee emp = employees.get(i);
            if (id==emp.getId()){
                System.out.print("姓名(" + emp.getName() + "):");
                String name = TSUtility.readString(4, emp.getName());
                System.out.print("年龄(" + emp.getAge() + "):");
                int age = Integer.parseInt(TSUtility.readString(2,emp.getAge()+""));
                System.out.print("工资(" + emp.getSalary() + "):");
                double salary =Double.parseDouble(TSUtility.readString(10, emp.getSalary()+""));
                emp.setName(name);
                emp.setAge(age);
                emp.setSalary(salary);
                flag=true;
        }
            }
        if (flag){
            System.out.println("修改 成功");
        }else {
            try {
                throw new TeamException("该成员不存在");
            }catch (TeamException e){
                e.printStackTrace();
            }
        }
    }
}

③TeamService

 定义变量

 private static int counter = 1;
    //序号
    private final int MAX_MEMBER = 5;
    //数组最大值
    private Programmer[] team = new Programmer[MAX_MEMBER];
    //创建数组
    private int total = 0;
    //实际长度

 ①增加人员(将人员添加到数组)

 判断人员是否已满  判断是否为开发人员

public void addMember(Employee e) throws TeamException {
        if (total >= MAX_MEMBER) {
            throw new TeamException("成员已满,无法添加");
        }
        if (!(e instanceof Programmer)) {
            throw new TeamException("该成员不是开发人员,无法添加");
        }

1. 判断人员是否在团队里面(前面已经给了条件:开发人员才能才能添加,隐藏条件:把方法Employee类转化为Programmer类)

2.判断人员是否在本团队(再次定义方法isExit( ))或者已在其他团队

    if (isExist(p)) {
            throw new TeamException("该员工已在本团队中");
        }
        if (!p.getStatus()) {
            throw new TeamException("该员工已是某团队成员");
        }

        private boolean isExist(Programmer p) {
        for (int i = 0; i < total; i++) {
            if (team[i].getId() == p.getId()) return true;
        }
        return false;
    }

判断团队成员组成

 int numOfArch = 0, numOfDsgn = 0, numOfPrg = 0;
        for (int i = 0; i < total; i++) {
            if (team[i] instanceof Architect) {
                numOfArch++;
            } else if (team[i] instanceof Designer) {
                numOfDsgn++;
            } else if (team[i] instanceof Programmer) {
                numOfPrg++;
            }
        }
        //instanceof方法要从最小的类进行判断
        // (p为可能为Programmer类 也可能为Designer类 也可能为Architect类)
        if (p instanceof Architect) {
            if (numOfArch >= 1) {
                throw new TeamException("团队中至多只能有一名架构师");
            }
        } else if (p instanceof Designer) {
            if (numOfDsgn >= 2) {
                throw new TeamException("团队中至多只能有两名设计师");
            }
        } else if (p instanceof Programmer) {
            if (numOfPrg >= 3) {
                throw new TeamException("团队中至多只能有三名程序员");
            }
        }

数组的添加操作(设置编号,数组长度加一,并且把要添加的对象加到数组中去),把状态设置为false,防止重复添加)

        p.setStatus(false);
        p.setMemberId(counter++);
        team[total++] = p;

②人员删除(将人员从数组中删除)

    public void removeMember(int memberId) throws TeamException {
        int i = 0;
        //i要经常用 所以放在最前面 避免重复定义
        for(; i < total; i++) {
            if(memberId == team[i].getMemberId()) {
                team[i].setStatus(true);
                break;
            }
        }
        //如果遍历成功结束,说明没有找到
        if(i == total) {
            throw new TeamException("找不到指定memberId的员工,删除失败");
        }
        //开始删除,团队数组从找到的下标开始后一个对象进行覆盖
        //total-1是根据j+1来定的
        for(int j = i; j < total - 1; j++) {
            team[j] = team[j+1];
        }
//        for (int j=i;j<total+1;j++){
//            team[j]=team[j-1];
//        }
        //两种写法

        //将数组最后一个对象指向空,总数减一
        team[--total] = null;

③人员查看

public Programmer[] getTeam() {
        Programmer[] team = new Programmer[total];
        //创建一个长度为实际长度的数组
        if (total==0){
            System.out.println("前先添加团队");
        }//得先进行添加操作
        //不一定传了5个 节约空间么?
        for (int i = 0; i < total; i++) {
            team[i]=this.team[i];
            //this.team为方法体外面team
            //team[i]为方法体内部的(不赋值并没有意义)
        }
        return team;
    }

该类全部代码

package service;


import domain.Architect;
import domain.Designer;
import domain.Employee;
import domain.Programmer;



public class TeamService {
    private static int counter = 1;
    //序号
    private final int MAX_MEMBER = 5;
    //数组最大值
    private Programmer[] team = new Programmer[MAX_MEMBER];
    //创建数组
    private int total = 0;
    //实际长度
    public Programmer[] getTeam() {
        Programmer[] team = new Programmer[total];
        //创建一个长度为实际长度的数组
        if (total==0){
            System.out.println("前先添加团队");
        }//得先进行添加操作
        //不一定传了5个 节约空间么?
        for (int i = 0; i < total; i++) {
            team[i]=this.team[i];
            //this.team为方法体外面team
            //team[i]为方法体内部的(不赋值并没有意义)
        }
        return team;
    }
        //不做需求
//    public void clearTeam() {
//        team = new Programmer[MAX_MEMBER];
//        counter = 1;
//        total = 0;
//        this.team = team;
//    }
    //将人员添加到数组
    public void addMember(Employee e) throws TeamException {

        if (total >= MAX_MEMBER) {
            throw new TeamException("成员已满,无法添加");
        }
        if (!(e instanceof Programmer)) {
            throw new TeamException("该成员不是开发人员,无法添加");
        }
        //关键一步
        Programmer p = (Programmer) e;

        if (isExist(p)) {
            throw new TeamException("该员工已在本团队中");
        }
        if (!p.getStatus()) {
            throw new TeamException("该员工已是某团队成员");
        }


        int numOfArch = 0, numOfDsgn = 0, numOfPrg = 0;
        for (int i = 0; i < total; i++) {
            if (team[i] instanceof Architect) {
                numOfArch++;
            } else if (team[i] instanceof Designer) {
                numOfDsgn++;
            } else if (team[i] instanceof Programmer) {
                numOfPrg++;
            }
        }
        //instanceof方法要从最小的类进行判断
        // (p为可能为Programmer类 也可能为Designer类 也可能为Architect类)
        if (p instanceof Architect) {
            if (numOfArch >= 1) {
                throw new TeamException("团队中至多只能有一名架构师");
            }
        } else if (p instanceof Designer) {
            if (numOfDsgn >= 2) {
                throw new TeamException("团队中至多只能有两名设计师");
            }
        } else if (p instanceof Programmer) {
            if (numOfPrg >= 3) {
                throw new TeamException("团队中至多只能有三名程序员");
            }
        }
        p.setStatus(false);
        p.setMemberId(counter++);
        team[total++] = p;
    }

    private boolean isExist(Programmer p) {
        for (int i = 0; i < total; i++) {
            if (team[i].getId() == p.getId()) return true;
        }
        return false;
    }

    public void removeMember(int memberId) throws TeamException {
        int i = 0;
        //i要经常用 所以放在最前面 避免重复定义
        for(; i < total; i++) {
            if(memberId == team[i].getMemberId()) {
                team[i].setStatus(true);
                break;
            }
        }
        //如果遍历成功结束,说明没有找到
        if(i == total) {
            throw new TeamException("找不到指定memberId的员工,删除失败");
        }
        //开始删除,团队数组从找到的下标开始后一个对象进行覆盖
        //total-1是根据j+1来定的
        for(int j = i; j < total - 1; j++) {
            team[j] = team[j+1];
        }
//        for (int j=i;j<total+1;j++){
//            team[j]=team[j-1];
//        }
        //两种写法

        //将数组最后一个对象指向空,总数减一
        team[--total] = null;
    }

}

④ProjectService

创建项目集合和变量序号

    private ArrayList<Project> pro = new ArrayList<>();
    private int count = 1;

方法:添加项目

  //添加项目
    public void addProjects() {
        System.out.println("项目参考:--------------------------------------------------");
        System.out.println("1.小米官网:开发完成类似于小米官网的web项目.");
        System.out.println("2.公益在线商城:猫宁Morning公益商城是中国公益性在线电子商城.");
        System.out.println("3.博客系统:Java博客系统,让每一个有故事的人更好的表达想法!");
        System.out.println("4.在线协作文档编辑系统:一个很常用的功能,适合小组内的文档编辑。");
        System.out.println("------------------------------------------------------------");
        TSUtility.readReturn();
        System.out.println("请输入你想添加的项目名: ");
        char c = TSUtility.readMenuSelection();
        Project p;
        switch (c) {
            case '1':
                p = new Project();
                p.setProId(count++);
                p.setProName("小米官网");
                p.setDesName("开发完成类似小米官网的web项目");
                pro.add(p);
                System.out.println("已添加项目:" + p.getProName());
                break;
            case '2':
                p = new Project();
                p.setProId(count++);
                p.setProName("公益在线商城");
                p.setDesName("猫宁公益商城是中国公益性在线电子商城");
                pro.add(p);
                System.out.println("已经添加项目:" + p.getProName());
                break;
            case '3':
                p = new Project();
                p.setProId(count++);
                p.setProName("博客系统");
                p.setDesName("Java博客系统,让每一个有故事的人更好的表达想法!");
                pro.add(p);
                System.out.println("已添加项目:" + p.getProName());
                break;
            case '4':
                p = new Project();
                p.setProId(count++);
                p.setProName("在线协作文档编辑系统");
                p.setDesName("一个很常用的功能,适合小组内的文档编辑。");
                pro.add(p);
                System.out.println("已添加项目:" + p.getProName());
                break;
            default:
                System.out.println("项目不存在");
                break;
        }

    }

方法:删除项目

 public void delPro(int id){
        boolean flag=false;
        for (int i = 0; i <pro.size() ; i++) {
            if (id==pro.get(i).getProId()){
                pro.remove(i);
            }
            flag=true;
        }
        if (flag){
            System.out.println("删除成功");
            count--;
        }else{
            try {
                throw new TeamException("该项目不存在");
            }catch (TeamException e){
                e.printStackTrace();
            }
        }
    }

方法:查找项目(1.返回项目集合 2.返回每一个项目)

public ArrayList<Project> getAllPro(){
        return pro;
    }
public void showPro(){
    for (int i = 0; i < pro.size(); i++) {
            System.out.println(pro.get(i));
     }
}

方法:分配项目

public void dealingPro(Programmer[] team){
        System.out.println("当前团队有人员:");
        for (int i = 0; i < team.length; i++) {
            System.out.println(team[i]);
        }
        System.out.println("请为当前团队创建一个团队名称:");
        String teamName = TSUtility.readKeyBoard(6, false);
        //随机分配项目
        Random ra = new Random();
        int ranNum = ra.nextInt(pro.size());
        Project project = this.pro.get(ranNum);

        project.setTeamName(teamName);
        project.setTeam(team);
        project.setStatus(true);

        pro.set(ranNum,project);
    }

该类的所有代码

package service;

import domain.Programmer;
import domain.Project;
import view.TSUtility;

import java.util.ArrayList;
import java.util.Random;

public class ProjectService {
    private ArrayList<Project> pro = new ArrayList<>();
    private int count = 1;

    //添加项目
    public void addProjects() {
        System.out.println("项目参考:--------------------------------------------------");
        System.out.println("1.小米官网:开发完成类似于小米官网的web项目.");
        System.out.println("2.公益在线商城:猫宁Morning公益商城是中国公益性在线电子商城.");
        System.out.println("3.博客系统:Java博客系统,让每一个有故事的人更好的表达想法!");
        System.out.println("4.在线协作文档编辑系统:一个很常用的功能,适合小组内的文档编辑。");
        System.out.println("------------------------------------------------------------");
        TSUtility.readReturn();
        System.out.println("请输入你想添加的项目名: ");
        char c = TSUtility.readMenuSelection();
        Project p;
        switch (c) {
            case '1':
                p = new Project();
                p.setProId(count++);
                p.setProName("小米官网");
                p.setDesName("开发完成类似小米官网的web项目");
                pro.add(p);
                System.out.println("已添加项目:" + p.getProName());
                break;
            case '2':
                p = new Project();
                p.setProId(count++);
                p.setProName("公益在线商城");
                p.setDesName("猫宁公益商城是中国公益性在线电子商城");
                pro.add(p);
                System.out.println("已经添加项目:" + p.getProName());
                break;
            case '3':
                p = new Project();
                p.setProId(count++);
                p.setProName("博客系统");
                p.setDesName("Java博客系统,让每一个有故事的人更好的表达想法!");
                pro.add(p);
                System.out.println("已添加项目:" + p.getProName());
                break;
            case '4':
                p = new Project();
                p.setProId(count++);
                p.setProName("在线协作文档编辑系统");
                p.setDesName("一个很常用的功能,适合小组内的文档编辑。");
                pro.add(p);
                System.out.println("已添加项目:" + p.getProName());
                break;
            default:
                System.out.println("项目不存在");
                break;
        }

    }
    //处理队伍
    public void dealingPro(Programmer[] team){
        System.out.println("当前团队有人员:");
        for (int i = 0; i < team.length; i++) {
            System.out.println(team[i]);
        }
        System.out.println("请为当前团队创建一个团队名称:");
        String teamName = TSUtility.readKeyBoard(6, false);
        //随机分配项目
        Random ra = new Random();
        int ranNum = ra.nextInt(pro.size());
        Project project = this.pro.get(ranNum);

        project.setTeamName(teamName);
        project.setTeam(team);
        project.setStatus(true);

        pro.set(ranNum,project);
    }
    public void showPro(){
        for (int i = 0; i < pro.size(); i++) {
            System.out.println(pro.get(i));
        }
    }
    public ArrayList<Project> getAllPro(){
        return pro;
    }
    public void delPro(int id){
        boolean flag=false;
        for (int i = 0; i <pro.size() ; i++) {
            if (id==pro.get(i).getProId()){
                pro.remove(i);
            }
            flag=true;
        }
        if (flag){
            System.out.println("删除成功");
            count--;
        }else{
            try {
                throw new TeamException("该项目不存在");
            }catch (TeamException e){
                e.printStackTrace();
            }
        }
    }
}

3.view模块

①LoginView类

package view;

import java.util.Scanner;

public class LoginView {
    //简单的登录操作
    private String userName = "";
    //userName的内容 是空字符 不进行任何操作
    private String password = "";

    public void regist() {
        System.out.println("开始注册");
        System.out.println("请输入你要注册的账号");
        String userName = TSUtility.readKeyBoard(4, false);
        this.userName = userName;
        System.out.println("请输入你要注册的密码");
        String password = TSUtility.readKeyBoard(8, false);
        this.password = password;
        System.out.println("注册成功!请登录");
    }

    //登录
    public void login() {
        int count = 5;//定义变量count来限制登录的次数
        boolean flag = true;
        while (flag) {
            System.out.println("***   <登录界面>   ***");
            System.out.println("请输入你的登录账号");
            String userName = TSUtility.readKeyBoard(4, false);
            System.out.println("请输入你的密码");
            String password = TSUtility.readKeyBoard(8, false);
            //判断是否已经是注册了
            if (this.userName.length() == 0 || this.password.length() == 0) {
                System.out.println("未检测到您的账号,请先注册");
                regist();
            } else if (userName.equals(this.userName) && password.equals(this.password)) {
                System.out.println("登录成功,欢迎您" + userName);
                flag = false;
            } else {
                if (count <= 0) {
                    System.out.println("登录次数不足");
                    break;
                } else {
                    count--;
                    System.out.println("登录失败,账号和密码不匹配");
                    System.out.println("登录次数还剩" + count + "次请重新输入");
                }
            }
        }

    }
    //更新
    public void update(){
        boolean falg=true;
        while(falg){
            System.out.println("***   <修改界面>   ***");
            System.out.println("请输入你需要修改的类型:");
            System.out.println("1(修改用户名)");
            System.out.println("2(修改密码名)");
            System.out.println("3(修改用户名和密码名)");
            System.out.println("4(不修改,退出)");
            Scanner in=new Scanner(System.in);
            String options = in.next();
            if (options.equals("1")){
                System.out.println("请输入你的修改的账户名称");
                String userName = TSUtility.readKeyBoard(4, false);
                this.userName=userName;
                System.out.println("修改成功");
            }else if(options.equals("2")){
                System.out.println("请输入你的修改密码");
                String password = TSUtility.readKeyBoard(8,false);
                this.password=password;
                System.out.println("修改成功");
            }else if (options.equals("3")){
                System.out.println("请输入你的修改的账户名称");
                String userName = TSUtility.readKeyBoard(4, false);
                this.userName=userName;
                System.out.println("请输入你的修改密码");
                String password = TSUtility.readKeyBoard(8,false);
                this.password=password;
                System.out.println("修改成功");
            }else if(options.equals("4")){
                System.out.println("退出中");
                falg=false;
            }else {
                System.out.println("输入错误,请输入“1”或“2”或“3”或”4“:");

            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值