项目调度模拟

一、系统需求

该软件实现以下功能:

1.软件启动时,首先进入登录界面进行注册和登录功能。

2.当登陆成功后,进入菜单,首先就可以对开发人员账户和密码进行修改。

3.当登陆成功后,进入菜单,首先就可以对开发人员账户和密码进行修改。

4.人员添加成功后,根据菜单提示,基于现有的公司成员,组建一个开发团队以开发一个新的项目。

5.组建过程包括将成员插入到团队中,或从团队中删除某成员,还可以列出团队中现有成员的列表,开发团队成员包括架构师、设计师和程序员。

6.团队组建成功,则可以进入项目模块,添加项目,分配开发团队进行开发。

二、功能结构

在这里插入图片描述

三、设计结构

view

模块为主控模块,负责菜单的显示和处理用户操作

service

模块为实体对象(Employee及其子类如程序员等)的管理模块

domain

模块为Employee及其子类等JavaBean类所在的包

四、具体实现

首先在view包下定义一个PrintUtility类,用于打印各个界面,比如欢迎界面等。

然后定义LoginView类,用于实现注册方法,实现登录功能,实现修改用户信息功能。

再在domain包中完成各个类的实体类创建。

其中包括Employee(雇员)类,Programmer(程序员)类,Designer(设计师)类,Architect(架构师)类等。

在这里插入图片描述

其中程序员(Programmer)及其子类,均会领用某种电子设备(Equipment)。

Equipment接口及其实现子类根据需求进行设计,根据需要提供各个属性的get、set方法以及重载构造器。实现类实现接口的方法,返回各自属性的信息。

定义一个NameListService类,并在该类中完成功能操作:

1.实现员工的添加(根据职业添加(无,程序员,设计师,架构师))

2.实现员工的修改(至少修改员工的姓名,年龄,工资)

3.实现员工的删除(注意员工id需要动态显示,也就是删除后,员工id需要更新)

4.实现员工的查看 (显示所有数据)

在团队界面显示公司成员的列表(这些是默认值,在开发人员管理模块中实现)等等,分别进行设计并实现,最后在view包中实现IndexView类的设计,将前面4个模块的内容装在一起,并运行软件,操作基本功能,调试bug,项目开发完成。

源码:

domain包下

Empoyee(雇员)类

package domain;

public class Empoyee {
    private int id;
    private String name;
    private int age;
    private double salary;//工资

    public Empoyee() {//无参构造
    }

    public Empoyee(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;
    }

    protected String getDetails() {//获取详细信息
        return id + "\t" + name + "\t" + age+ "\t   " +salary;
    }

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

Programmer(程序员)类

package domain;

public class Programmer extends Empoyee {
    private int memberId;//会员编号
    private boolean status = true;
    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 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;
    }

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

Designer(设计师)类

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

Architect(架构师)类

package domain;

public class Architect extends Designer {
    static 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 static int getStock() {
        return stock;
    }

    public static void setStock(int stock) {
        Architect.stock = stock;
    }

    @Override
    public String getDetailsForTeam() {
        return getMemberDetails() + "\t架构师\t" +
                getBonus() + "\t" + getStock();
    }

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

Equipment接口

package domain;

public interface  Equipment {
    public abstract String getDescription();//返回各自属性的信息
}

NoteBook类

package domain;

import view.TSUtility;

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 + ")";
    }

    public NoteBook addNoteBook() {
        System.out.println("请为当前设计师配一台好的笔记本电脑:");
        System.out.println("请输入需要配置的笔记本电脑的型号:");
        String model = TSUtility.readKeyBoard(10, false);
        System.out.println("请输入需要配置的笔记本电脑的价格:");
        Double price = TSUtility.readDouble();
        System.out.println("设备添加成功!");
        return new NoteBook(model, price);
    }
}

PC类

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

    @Override
    public String getDescription() {
        return model+"("+display+")";
    }
    public PC addPC(){
        System.out.println("你的程序员需要一台好的台式电脑");
        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);
    }
}

Printer类

package domain;

import view.TSUtility;

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+")";
    }

    public Printer addPrinter() {
        System.out.println("请为当前架构师配一台好的打印设备:");
        System.out.println("请输入需要配置的打印机的型号:");
        String name = TSUtility.readKeyBoard(10, false);
        System.out.println("请输入需要配置的打印机的类型:");
        String type = TSUtility.readKeyBoard(10,false);
        System.out.println("设备添加成功!");
        return new Printer();
    }
}

Project类

package domain;

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

    public Project() {
    }

    public Project(int proId, String projectName, String desName, Programmer[] team, String teamName, boolean status) {
        this.proId = proId;
        this.projectName = projectName;
        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 getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    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 toString(){
        String s;
        if(status){
            s="项目["+projectName+"]------>正在被团队["+teamName+"]开发中";
        }else {
            s = "项目{项目号:‘" + proId + "'项目名=" + projectName + ",项目描述=’" + desName + "',开发团队名称=‘" + teamName+ "’,开发状态=" + status + "}\n" + "项目【" + projectName + "】----->未被开发";
        }
        return s;
    }
}

service包下

AccountInfo类

package service;

public class AccountInfo {//账户信息
    public AccountInfo() {}
    public static String userName="";
    public static String password="";
}

NameListService类

实现对员工的增删改查的操作

package service;

import domain.*;
import view.PrintUtility;
import view.TSUtility;

import java.util.ArrayList;

public class NameListService {
    private ArrayList<Empoyee> empoyees;
    private int count = 1;//员工总数

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

    public ArrayList<Empoyee> getAllEmployees() {
        return empoyees;//包含所有员工集合
    }

    public Empoyee getEmployee(int id) throws TeamException {
        for (int i = 0; i < empoyees.size(); i++) {

            if (empoyees.get(i).getId() == id) {
                return empoyees.get(i);
            }
        }
        throw new TeamException("该员工不存在");
    }

    public void addEmployee() {//添加员工
        PrintUtility.printAddEmp();
        String ch = String.valueOf(TSUtility.readMenuSelection());
        if (ch.equals("1")) {
            //无职位 new Employee(count++,"马云 ",22,3000)
            System.out.println("`当前雇员职位分配为:无`");
            System.out.println("请输入当前员工的姓名");
            String name = TSUtility.readKeyBoard(6, false);
            System.out.println("请输入当前员工的年龄");
            int age = TSUtility.readInt();
            System.out.println("请输入当前员工的工资");
            double salary = TSUtility.readDouble();
            Empoyee employee = new Empoyee(++count, name, age, salary);
            empoyees.add(employee);
            System.out.println("员工添加成功");
            TSUtility.readReturn();
        } else if (ch.equals("2")) {
            //程序员 new Programmer(count++,"张朝阳 ",35,7100,new PC("华硕","三星 17寸"))
            System.out.println("`当前雇员职位分配为:程序员`");
            System.out.println("请输入当前员工的姓名");
            String name = TSUtility.readKeyBoard(6, 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);
            empoyees.add(programmer);
            System.out.println("员工添加成功!");
            TSUtility.readReturn();
        } else if (ch.equals("3")) {
            //设计师 new Designer(count++,"史玉柱",27,7800,new NoteBook("惠普m6",5800),1500)
            System.out.println("`当前雇员职位分配为:设计师`");
            System.out.println("请输入当前员工的姓名");
            String name = TSUtility.readKeyBoard(6, 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();
            Designer designer = new Designer(++count, name, age, salary, noteBook, bonus);
            empoyees.add(designer);
            System.out.println("员工添加成功!");
            TSUtility.readReturn();
        } else {
            //架构师 new Architect(count++,"杨元庆",35,6500,new Printer("针式","爱普生20k"),15500,1200)
            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);
            empoyees.add(architect);
            System.out.println("员工添加成功!");
            TSUtility.readReturn();
        }
    }

    public void delEmployee(int id) {
        boolean flag = false;
        for (int i = 0; i < empoyees.size(); i++) {
            Empoyee employee = empoyees.get(i);
            if (employee.getId() == id) {
                empoyees.remove(employee);
                for (int j = i; j < empoyees.size(); j++) {
                    empoyees.get(j).setId(empoyees.get(j).getId() - 1);
                }
                flag = true;
                count--;
                break;
            }
        }
        if (flag) {
            System.out.println("修改成功!");
        } else {
            try {
                throw new TeamException("您所查找的员工不存在!");
            } catch (TeamException e) {
                System.out.println(e.getMessage());
            }
        }
    }

    public void displayList() throws InterruptedException {
        //开发人员管理
        TSUtility.loadSpecialEffects();
        System.out.println("ID\t 姓名\t年龄\t\t 工资\t 职位\t 状态\t 奖金\t 股票\t 领用设备");
        for (int i = 0; i < empoyees.size(); i++) {
            System.out.println("" + empoyees.get(i));
        }
    }

    public void modifyEmployee(int id) {//删除员工
        boolean flag = false;
        for (int i = 0; i < empoyees.size(); i++) {
            Empoyee empoyee = empoyees.get(i);
            if (empoyee.getId() == id) {
                System.out.println("姓名(" + empoyee.getName() + "):");
                empoyee.setName(TSUtility.readString(5, empoyee.getName()));
                System.out.println("年龄(" + empoyee.getAge() + "):");
                empoyee.setAge(Integer.parseInt(TSUtility.readString(2, String.valueOf(empoyee.getAge()))));
                System.out.println("工资(" + empoyee.getSalary() + "):");
                empoyee.setSalary(Double.parseDouble(TSUtility.readString(6, String.valueOf(empoyee.getSalary()))));
                flag = true;
            }
        }
        if (flag) {
            System.out.println("修改成功");
        } else {
            try {
                throw new TeamException("您所查找的员工不存在!");
            } catch (TeamException e) {
                e.printStackTrace();
            }
        }
    }
}

ProjectService类

实现项目的相关操作

package service;

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

import java.util.ArrayList;

public class ProjectService {
    private ArrayList<Project> pro = new ArrayList<>();// 用来存已经添加的项目
    private int count = 1;
    private ArrayList<Integer> ranNumList = new ArrayList<>();
    private ArrayList<Character> alreadyAddPro = new ArrayList<>();

    //添加新的项目
    public void addProject() throws InterruptedException {
        PrintUtility.printProjectRefer();
        char ch = TSUtility.readMenuSelection();
        if (alreadyAddPro.contains(ch)) {
            System.out.println("本项目已经添加过了");
            return;
        }
        Project p = new Project();
        switch (ch) {
            case '1'://小米官网项目
                p.setProId(count++);
                p.setProjectName("小米官网");
                p.setDesName("开发完成类似于小米官网的web项目");
                pro.add(p);
                alreadyAddPro.add('1');
                break;
            case '2'://工艺在线商城项目
                p.setProId(count++);
                p.setProjectName("公益在线商城");
                p.setDesName("猫宁Morning公益商城是中国公益性在线电子商城");
                pro.add(p);
                alreadyAddPro.add('2');
                break;
            case '3'://博客系统
                p.setProId(count++);
                p.setProjectName("博客系统");
                p.setDesName("Java博客系统,让每一个有故事的人更好的表达想法");
                pro.add(p);
                alreadyAddPro.add('3');
                break;
            case '4'://在线协作文档编辑系统
                p.setProId(count++);
                p.setProjectName("在线协作文档编辑系统");
                p.setDesName("一个很常用的功能,适合小组内的文档编辑");
                pro.add(p);
                alreadyAddPro.add('4');
                break;
        }
        TSUtility.loadSpecialEffects();
        System.out.println("已添加项目:" + p.getProjectName());
    }

    //项目分配团队开发
    public void dealingPro(ArrayList<TeamService> listTeamSvc) {
        if (listTeamSvc.size() == 0) {
            System.out.println("当前没有团队");
            return;
        }
        if (pro.size() == 0) {
            System.out.println("当前没有添加项目!");
            return;
        }
        for (int i = 0; i < listTeamSvc.size(); i++) {
            System.out.println("当前团队有人员:");
            TeamService teamService = listTeamSvc.get(i);
            Programmer[] team = teamService.getTeam();
            for (Programmer p : team) {
                System.out.println(p);
            }
            System.out.println("请为当前团队创建一个团队名称:");
            String teamName = TSUtility.readKeyBoard(10, false);
            do {
                int ranNum = (int) (Math.random() * pro.size());
                if (!pro.get(ranNum).isStatus()) {
                    ranNumList.add(ranNum);//存放已经添加过的项目
                    pro.get(ranNum).setStatus(true);
                    pro.get(ranNum).setTeam(team);
                    pro.get(ranNum).setTeamName(teamName);
                    break;
                } else if (ranNumList.size() == pro.size()) {
                    break;
                }
            } while (true);
        }
    }

    //查看项目当前状态
    public void showPro() throws InterruptedException {
        TSUtility.loadSpecialEffects();
        if (pro.size() == 0) {
            System.out.println("当前没有添加项目!");
            return;
        }
        for (int i = 0; i < pro.size(); i++) {
            System.out.println(pro.get(i));
        }
    }

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

TeamException类

自定义错误类

package service;

public class TeamException extends Exception{
    public TeamException() {
    }

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

TeamService类

实现从团队中增加,删除成员,以及展示的功能

package service;

import domain.Architect;
import domain.Designer;
import domain.Empoyee;
import domain.Programmer;

public class TeamService {
    private static int counter = 1;//用来为开发团队新增成员自动生成团队中的唯一ID,即memberId。
    private final int MAX_MEMBER = 5;//表示开发团队最大成员数
    private int teamId;
    private Programmer[] team = new Programmer[MAX_MEMBER];//用来保存当前团队中的各成员对象 
    private int total = 0;//:记录团队成员的实际人数

    public TeamService() {
        teamId = counter++;
    }

    //功能:返回当前团队的所有对象。返回:包含所有成员对象的数组,数组大小与成员人数一致
    public Programmer[] getTeam() {
        Programmer[] team = new Programmer[total];
        for (int i = 0; i < total; i++) {
            team[i] = this.team[i];
        }
        return team;
    }

    //功能:向团队中添加成员。参数:待添加成员的对象,异常:添加失败, TeamException中包含了失败原因
    public void addMember(Empoyee e) throws TeamException {
        if (total >= MAX_MEMBER) {
            throw new TeamException("成员已满,无法添加");
        }
        if (!(e instanceof Programmer)) {
            throw new TeamException("该成员不是开发人员,无法添加");
        }
        if (isExist(e)) {
            throw new TeamException("添加失败,该员工已在本团队中");
        } else if (!((Programmer) e).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++;
            }
        }

        if (e instanceof Architect) {
            if (numOfArch >= 1) {
                throw new TeamException("团队中最多只能有一名架构师");
            }
        } else if (e instanceof Designer) {
            if (numOfDsgn >= 2) {
                throw new TeamException("团队中最多只能有两名设计师");
            }
        } else if (e instanceof Programmer) {
            if (numOfPrg >= 3) {
                throw new TeamException("团队中最多只能有三名程序员");
            }
        }

        ((Programmer) e).setStatus(false);
        System.out.println("添加成功!");
        team[total++] = (Programmer) e;
    }

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

    //功能:从团队中删除成员。参数:待删除成员的memberId。异常:找不到指定memberId的员工,删除失败.
    public void removeMember(int memberId) throws TeamException {
        if (memberId > total || memberId < 0){
            throw new TeamException("找不到该员工,删除失败");
        }
        team[memberId].setStatus(true);
        for (int i = memberId;i<total-1;i++){
            team[i+1].setMemberId(team[i+1].getMemberId()-1);
            team[i] = team[i+1];
        }
        team[total] = null;
        total--;
    }

}

view包下

IndexView类

将几个模块组合在一起

package view;

import service.*;

public class IndexView {
    private NameListService nameListService = new NameListService();
    private TeamService teamService = new TeamService();
    private TeamView teamView = new TeamView(nameListService);
    private ProjectService projectService = new ProjectService();
    private LoginView loginView = new LoginView();

    public static void main(String[] args) throws InterruptedException, TeamException {
        new IndexView().mainMenu();//主菜单
    }

    public void mainMenu() throws InterruptedException, TeamException {
        loginView.loginOptions();//登录选项,即登入或者注册
        boolean loopFlag = true;
        do {
            PrintUtility.printMainMenu();
            switch (TSUtility.readMenuSelectionPro()) {
                case '1':
                    //修改用户信息或修改密码
                    changePassword();//修改密码
                    loginView.signIn();//登录
                    break;
                case '2':
                    nameListService.displayList();//展示人员列表
                    devMemMan();//开发人员管理界面逻辑处理
                    break;
                case '3':
                    teamView.enterMainMenu();//开发团队调度管理界面
                    break;
                case '4':
                    projectManMenu();
                    //开发项目管理
                    break;
                case '5':
                    //退出软件
                    System.out.print("确认是否退出(Y/N):");
                    char yn = TSUtility.readConfirmSelection();
                    if (yn == 'Y') {
                        System.out.println("欢迎你的下一次使用,再见");
                        System.exit(0);
                    }
            }
        } while (loopFlag);
    }

    //开发人员管理界面
    private void devMemMan() throws InterruptedException {
        while (true) {
            PrintUtility.printDevManMenu();
            int id;
            switch (TSUtility.readMenuSelectionPro()) {
                case '1':
                    //添加开发人员
                    nameListService.addEmployee();
                    break;
                case '2':
                    //查看当前团队的开发人员
                    nameListService.displayList();
                    break;
                case '3':
                    //修改开发人员
                    System.out.println("不想修改的信息直接回车即可!!!");
                    System.out.println("请输入需要修改的员工id:");
                    id = TSUtility.readInt();
                    nameListService.modifyEmployee(id);
                    break;
                case '4':
                    //删除开发人员
                    System.out.println("请输入删除员工的id");
                    id = TSUtility.readInt();
                    nameListService.delEmployee(id);
                    break;
                case '5':
                    //退出当前菜单
                    System.out.println("确认是否退出(Y/N)");
                    if (TSUtility.readConfirmSelection() == 'Y') {
                        return;
                    }
                    break;
            }
        }
    }

    //项目管理主菜单
    public void projectManMenu() throws InterruptedException {
        TSUtility.loadSpecialEffects();
        boolean loop = true;
        do {
            PrintUtility.printProjectManMenu();
            switch (TSUtility.readMenuSelectionPro()) {
                case '1':
                    //项目添加
                    projectService.addProject();
                    break;
                case '2':
                    //项目分配开发团队
                    projectService.dealingPro(teamView.getListTeamSvc());
                    break;
                case '3':
                    //项目查看
                    projectService.showPro();
                    break;
                case '4':
                    //项目的删除
                    System.out.println("请输入需要删除的项目id:");
                    projectService.delPro(TSUtility.readInt());
                    break;
                case '5':
                    //退出当前菜单
                    System.out.print("确认是否退出(Y/N):");
                    char yn = TSUtility.readConfirmSelection();
                    if (yn == 'Y') {
                        loop = false;
                    }
                    break;
            }
        } while (loop);
    }

    //修改密码
    public void changePassword() throws InterruptedException {
        TSUtility.loadSpecialEffects();
        PrintUtility.printChangePW();
        System.out.print("您原来的用户名是(" + AccountInfo.userName + "),你想要修改为:");
        String userName = TSUtility.readString(5, AccountInfo.userName);
        System.out.print("您原来的密码是(" + AccountInfo.password + "),你想要修改为:");
        String password = TSUtility.readString(15, AccountInfo.password);
        AccountInfo.userName = userName;
        AccountInfo.password = password;
        System.out.println("修改成功!请稍等");
        TSUtility.loadSpecialEffects();
        System.out.println("密码已修改,请重新登录:");
    }
}

LoginView类

实现注册方法
实现登录功能
实现修改用户密码功能

package view;

import service.AccountInfo;

public class LoginView {
    public  void loginOptions() throws InterruptedException {
        while (true) {
            PrintUtility.printWelcome();
            String s2 = "登录\t请选择1\n注册\t请选择2";
            PrintUtility.printWithColor("蓝色", s2);
            System.out.println("请输入选择");
            String choose = TSUtility.readKeyBoard(1, false);
            if (choose.equals("1")) {
                if (signIn()) {
                    break;
                }
            } else if (choose.equals("2")) {
                register();
                System.out.println("正在进入登录界面");
                TSUtility.loadSpecialEffects();
                if (signIn()) {
                    break;
                } else {
                    System.out.println("输入错误");
                }
            }
        }


    }

    //登录
    public boolean signIn() throws InterruptedException {
        PrintUtility.printSignIn();
        int count = 0;
        do {
            PrintUtility.printWithColor("黑色", "请输入用户名:");
            String userName = TSUtility.readKeyBoard(5, false);
            PrintUtility.printWithColor("黑色", "请输入密码:");
            String password = TSUtility.readKeyBoard(15, false);
            if (AccountInfo.userName.equals(userName)) {
                if (AccountInfo.password.equals(password)) {
                    TSUtility.loadSpecialEffects();
                    System.out.println("登录成功!欢迎您" + userName);
                    break;
                } else {
                    System.out.println("密码输入错误!请重新输入");
                    count++;
                    System.out.println("您还有" + (5 - count) + "次机会");
                }
            } else {
                System.out.println("用户名不存在");
                count++;
                System.out.println("您还有" + (5 - count) + "次机会");
            }
            System.out.println("是否退出登录界面(y)?返回上级菜单");
            if (TSUtility.readConfirmSelection() == 'Y') {
                return false;
            }
        } while (count < 5);
        if (count == 5) {
            PrintUtility.printWithColor("红色", "您的账号被锁定");
            System.exit(0);
        }
        return true;
    }

    //注册
    public void register() {
        PrintUtility.printRegister();
        while (true) {
            System.out.println("请输入用户名");
            String userName = TSUtility.readKeyBoard(5, false);
            System.out.println("请输入密码");
            String password1 = TSUtility.readKeyBoard(15, false);
            System.out.println("请再次输入密码");
            String password2 = TSUtility.readKeyBoard(15, false);

            if (password1.equals(password2)) {
                AccountInfo.userName=userName;
                AccountInfo.password=password1;
                System.out.println("注册成功");
                break;
            } else {
                System.out.println("注册失败,两次密码不一致");
            }
        }
    }
}

PrintUtility类

用于打印各个界面

package view;

import java.util.HashMap;
import java.util.Map;

public class PrintUtility {
    public PrintUtility() {
    }

    //带颜色的打印content内容
    public static void printWithColor(String color, String content) {
        Map<String, String> map = new HashMap<>();
        map.put("黑色", "30");
        map.put("红色", "31");
        map.put("绿色", "32");
        map.put("黄色", "33");
        map.put("蓝色", "34");
        map.put("紫红色", "35");
        map.put("青蓝色", "36");
        map.put("白色", "37");
        System.out.println("\033[1;" + map.get(color) + "m" + content + "\033[0m ");
    }

    //打印欢迎界面
    public static void printWelcome() {
        printWithColor("蓝色", "\t\tWelcome to My program");
        String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
                "☏                                ☏\n" +
                "☏ 欢迎来到项目开发团队分配管理软件 ☏\n" +
                "☏                                ☏\n" +
                "♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n" +
                "🐻------<请您选择登录or注册>-------🐻";
        printWithColor("蓝色", s1);
    }

    //打印登入界面
    public static void printSignIn() {
        String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
                "☏                                ☏\n" +
                "☏            <登录界面>          ☏\n" +
                "☏                                ☏\n" +
                "♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n";
        printWithColor("白色", s1);
    }

    //打印注册界面
    public static void printRegister() {
        String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
                "☏                                ☏\n" +
                "☏            <注册界面>          ☏\n" +
                "☏                                ☏\n" +
                "♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n";
        printWithColor("黑色", s1);
    }

    public static void printChangePW() {
        String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
                "☏                                ☏\n" +
                "☏            <修改密码>          ☏\n" +
                "☏                                ☏\n" +
                "♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n";
        printWithColor("红色", s1);
        printWithColor("红色", "不想修改的信息直接按回车即可");
    }

    public static void printMainMenu() {
        String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
                "☏                                ☏\n" +
                "☏           <软件主菜单>          ☏\n" +
                "☏                                ☏\n" +
                "♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n" +
                "🐻1. <用户信息修改>                 *\n" +
                "🐘2. <开发人员管理>                 *\n" +
                "🦁3. <开发团队调度管理>             *\n" +
                "🐻4. <开发项目管理>                 *\n" +
                "🦊5. <退出软件>                     *\n" +
                "请选择";

        printWithColor("绿色", s1);
    }

    public static void printDevManMenu() {
        String s1 = "🐻         ~开发人员管理主菜单~          🐻\n" +
                "🐻          1. <开发人员的添加>          🐻\n" +
                "🐻          2. <开发人员的查看>          🐻\n" +
                "🐻          3. <开发人员的修改>          🐻\n" +
                "🐻          4. <开发人员的删除>          🐻\n" +
                "🐻          5. <退出当前菜单>            🐻\n" +
                "请选择:";
        printWithColor("黑色", s1);
    }

    public static void printAddEmp() {
        String s1 = "请选择需要添加的雇员的职业:\n" +
                "1(无职位)\n" +
                "2(程序员)\n" +
                "3(设计师)\n" +
                "4(架构师)\n" +
                "请选择:";
        printWithColor("黄色", s1);
    }

    public static void printTeamMan() {
        String s1 = "□■△▽⊿▲▼◣◤◢◥□■△▽□■\n" +
                "□■△▽⊿▲▼◣◤◢◥□■△▽□■\n" +
                "□■      团队调度界面       □■\n" +
                "□■△▽⊿▲▼◣◤◢◥□■△▽□■\n" +
                "□■△▽⊿▲▼◣◤◢◥□■△▽□■\n\n" +
                "1-添加团队 2-查看团队 3-删除团队 4-退出\n" +
                "请选择(1-4)";
        printWithColor("紫红色", s1);
    }

    public static void printProjectManMenu() {
        String s1 = "🐻         ~开发项目管理主菜单~      🐻\n" +
                "🐻          1. <项目的添加>          🐻\n" +
                "🐻          2. <项目分配开发团队>    🐻\n" +
                "🐻          3. <项目的查看>          🐻\n" +
                "🐻          4. <项目的删除>          🐻\n" +
                "🐻          5. <退出当前菜单>        🐻\n" +
                "请选择:";
        printWithColor("青蓝色", s1);
    }

    public static void printProjectRefer() {
        String s = "项目参考:--------------------------------------------------\n" +
                "1.小米官网:开发完成类似于小米官网的web项目.\n" +
                "2.公益在线商城:猫宁Morning公益商城是中国公益性在线电子商城.\n" +
                "3.博客系统:Java博客系统,让每一个有故事的人更好的表达想法!*\n" +
                "4.在线协作文档编辑系统:一个很常用的功能,适合小组内的文档编辑。\n" +
                "------------------------------------------------------------\n";
        printWithColor("青蓝色", s);
    }
}

TeamView类

package view;

import domain.Empoyee;
import domain.Programmer;
import service.NameListService;
import service.TeamException;
import service.TeamService;

import java.util.ArrayList;

public class TeamView {
    private NameListService listSvc = new NameListService();
    private ArrayList<TeamService> listTeamSvc = new ArrayList<>();
    
    public TeamView(NameListService listSvc) {
        this.listSvc = listSvc;
    }

    public static void main(String[] args) throws TeamException, InterruptedException {
        new TeamView(new NameListService()).enterMainMenu();
    }

    public void enterMainMenu() throws InterruptedException, TeamException {
        TSUtility.loadSpecialEffects();
        boolean loop = true;
        do {
            PrintUtility.printTeamMan();
            switch (TSUtility.readMenuSelection()) {
                case '1'://添加团队
                    addTeam();
                    break;
                case '2'://查看团队
                    displayAllTeamList();
                    break;
                case '3'://删除团队
                    deleteTeam();
                    break;
                case '4'://退出
                    System.out.print("请输入是否退出”开发团队调度管理“页面(Y/N):");
                    if (TSUtility.readConfirmSelection() == 'Y') loop = false;
                    break;
            }
        } while (loop);
    }

    private void displayAllTeamList() {
        System.out.println("--------所有团队列表-------");
        for (int i = 0; i < listTeamSvc.size(); i++) {
            TeamService teamService = listTeamSvc.get(i);
            Programmer[] team = teamService.getTeam();
            for (int j = 0; j < team.length; j++) {
                System.out.println(team[j]);
            }
            System.out.println("--------------------");
        }
    }

    public void addTeam() throws InterruptedException {
        TeamService teamService = new TeamService();
        listTeamSvc.add(teamService);
        while (true) {
            listAllEmployees();
            System.out.print("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出");
            System.out.print("\t请选择(1-4):\n");
            Empoyee empoyee = null;
            switch (TSUtility.readMenuSelection()) {
                case '1':
                    //打印团队列表
                    getTeam(teamService);
                    break;
                case '2':
                    //添加团队成员
                    System.out.println("---------------添加团队成员--------------");
                    System.out.print("请输入要添加的员工ID:");
                    int id = TSUtility.readInt();
                    try {
                        empoyee = listSvc.getEmployee(id);
                        if (empoyee == null) {
                            System.out.println("添加失败!没有找到该员工");
                        } else {
                            try {
                                teamService.addMember(empoyee);
                            } catch (TeamException e) {
                                System.out.println(e.getMessage());
                            }
                        }
                    } catch (TeamException e) {
                        System.out.println(e.getMessage());
                    }
                    TSUtility.readReturn();
                    break;
                case '3':
                    //删除团队成员
                    System.out.println("请输入待删除的成员的团队id号");
                    id = TSUtility.readInt();
                    try {
                        teamService.removeMember(id - 1);
                    } catch (TeamException e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                case '4':
                    System.out.print("确认是否退出(Y/N):");
                    if (TSUtility.readConfirmSelection() == 'Y') {
                        return;
                    } else {
                        break;
                    }
            }
        }
    }

    //列出公司所有成员
    public void listAllEmployees() throws InterruptedException {
        System.out.println("-------------------开发团队调度软件-------------------");
        listSvc.displayList();
        System.out.println("-----------------------------------------------------");
    }

    //显示团队成员列表操作
    public void getTeam(TeamService teamService) {
        System.out.println("---------------查看当前团队成员--------------");
        System.out.println("TID/ID\t 姓名\t年龄\t\t 工资\t 职位\t 奖金\t 股票");
        Programmer[] team = teamService.getTeam();
        for (int i = 0; i < team.length; i++) {
            team[i].setMemberId(i + 1);
            System.out.println(team[i].getDetailsForTeam());//获取详细信息团队
        }
        System.out.println("---------------------------------------------");
        System.out.println();
    }

    //实现删除团队操作
    public void deleteTeam() {
        System.out.println("输入想要删除的队伍是第几个");
        while (true) {
            int i = TSUtility.readInt();
            if (i < 0 || i > listTeamSvc.size()) {
                System.out.println("输入错误请重新输入:");
            } else {
                for (int j = 0; j < listTeamSvc.get(i - 1).getTeam().length; j++) {
                    listTeamSvc.get(i - 1).getTeam()[j].setStatus(true);
                }
                listTeamSvc.remove(i - 1);
                System.out.println("删除成功!");
                break;
            }
        }
    }

    public ArrayList<TeamService> getListTeamSvc() {
        return listTeamSvc;
    }
}

TSUtility类

package view;

import java.util.Random;
import java.util.Scanner;

public class TSUtility {
    private static Scanner scanner = new Scanner(System.in);

    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;
    }
    public static char readMenuSelectionPro() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' &&
                    c != '3' && c != '4' && c != '5') {
                System.out.print("选择错误,请重新输入:");
            } else break;
        }
        return c;
    }


    public static void readReturn() {
        System.out.print("按回车键继续...");
        readKeyBoard(100, true);
    }

    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;
    }
    public static int readstock() {
        int n;
        for (; ; ) {
            String str = readKeyBoard(6, false);
            try {
                n = Integer.parseInt(str);
                break;
            } catch (NumberFormatException e) {
                System.out.print("数字输入错误,请重新输入:");
            }
        }
        return n;
    }
    public static Double readDouble() {
        Double n;
        for (; ; ) {
            String str = readKeyBoard(6, false);
            try {
                n = Double.parseDouble(str);
                break;
            } catch (NumberFormatException e) {
                System.out.print("数字输入错误,请重新输入:");
            }
        }
        return n;
    }

    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;
    }
    public static String readString(int limit, String defaultValue) {
        String str = readKeyBoard(limit, true);
        return str.equals("")? defaultValue : str;
    }

    public 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;
    }
    public static void loadSpecialEffects() throws InterruptedException {
        System.out.println("请稍等:");
        for (int i1 = 1; i1 <= 100; i1++) {
            System.out.print("加载中:" + i1 + "%");
            Thread.sleep(new Random().nextInt(25) + 1);
            if (i1 == 100) {
                Thread.sleep(50);
            }
            System.out.print("\r");
        }
    }
}
rmatException e) {
                System.out.print("数字输入错误,请重新输入:");
            }
        }
        return n;
    }

    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;
    }
    public static String readString(int limit, String defaultValue) {
        String str = readKeyBoard(limit, true);
        return str.equals("")? defaultValue : str;
    }

    public 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;
    }
    public static void loadSpecialEffects() throws InterruptedException {
        System.out.println("请稍等:");
        for (int i1 = 1; i1 <= 100; i1++) {
            System.out.print("加载中:" + i1 + "%");
            Thread.sleep(new Random().nextInt(25) + 1);
            if (i1 == 100) {
                Thread.sleep(50);
            }
            System.out.print("\r");
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值