Java开发团队人员调度软件项目实现

                                  

                 开发团队调度软件            

图书管理项目文档设计

1.项目介绍:

2.项目功能:

3.项目知识点:

4.项目实现思路(脑图):

5.项目具体实现

Employee类

Programmer类

Designer类

Architect类

Equipment接口

PC类

NoteBook类

Printer类

Data类

Status类

TeamException类(自定义异常类)

NameListService类

TeamService类

TSUtility类

 TeamView类


 

1.项目介绍:

实现公司项目开发的成员调动

2.项目功能:

在公司成员的员工列表调动人员组成开发团队,可增加删除成员。

3.项目知识点:

类的继承性和多态性

对象的值传递、接口

static和final修饰符

特殊类的使用:包装类、抽象类、内部类

异常处理

4.项目实现思路(脑图):

5.项目具体实现

代码使用mvc设计模式

domain包(Employee,Programmer,Desginer,Architect,Equipment,PC,NoteBook,Printer几个类和接口)(controller)

view包(Data,Status,TeamExcept,NameListService,TeamService)(view)

service(TeamView,TSUtility)(model)

Employee类

package com.team.domain;

public class Employee {
    private String name;
    private int id;
    private int age;
    private double salary;

    public Employee() {
    }

    public Employee(String name, int id, int age, double salary) {
        this.name = name;
        this.id = id;
        this.age = age;
        this.salary = salary;
    }
    //获取姓名,id,年龄,工资
    public String getDetails(){
        return id+"\t"+name+"\t"+age+"\t"+salary;
    }
    //重写toString方法
    @Override
    public String toString(){
        return getDetails();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

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

Programmer类

package com.team.domain;

import com.team.service.Status;

public class Programmer extends Employee{
    private int memberId;//开发团队中的id
    private Status status=Status.FREE;//员工状态
    private Equipment equipment;//员工设备

    public Programmer() {

    }

    public Programmer(String name, int id, int age, double salary, Equipment equipment) {
        super(name, id, age, salary);
        this.equipment = equipment;
    }
    //重写toString方法
    @Override
    public String toString(){
        return super.getDetails()+"\t程序员\t"+status+"\t\t\t\t\t"+equipment.getDescription();
    }


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

Designer类

package com.team.domain;

public class Designer extends Programmer {
    private double bonus;

    public Designer() {

    }

    public Designer(String name, int id, int age, double salary, Equipment equipment, double bonus) {
        super(name, id, age, salary, equipment);
        this.bonus = bonus;
    }
    //重写toString方法
    @Override
    public String toString(){
        return super.getDetails()+"\t设计师\t"+getStatus()+"\t"+bonus+"\t\t\t"+getEquipment().getDescription();
    }

    public double getBonus() {
        return bonus;
    }

    public void setBonus(double bonus) {
        this.bonus = bonus;
    }
}

Architect类

package com.team.domain;

public class Architect extends Designer{
    private int stock;

    public Architect() {
    }

    public Architect(String name, int id, int age, double salary, Equipment equipment, double bonus,int stock) {
        super(name, id, age, salary, equipment, bonus);
        this.stock=stock;
    }
    //重写toString方法
    @Override
    public String toString(){
        return super.getDetails()+"\t构架师\t"+getStatus()+"\t"+getBonus()+"\t"+stock+"\t"+getEquipment().getDescription();
    }


    public int getStock() {
        return stock;
    }

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

Equipment接口

package com.team.domain;

public interface Equipment {
 public abstract String getDescription();
}

PC类

package com.team.domain;

public class PC implements Equipment{
    private String model;//机器型号
    private String display;//显示器名称

    public PC() {
        super();
    }

    public PC(String model, String display) {
        super();
        this.model = model;
        this.display = display;
    }

    @Override
    public String getDescription() {
        return model+'('+display+')';
    }

    public String getModel() {
        return model;
    }

    public String getDisplay() {
        return display;
    }
}

NoteBook类

package com.team.domain;

public class NoteBook implements Equipment{
    private String model;//机器型号
    private double price;//价格

    public NoteBook() {
        super();
    }

    public NoteBook(String model, double price) {
        super();
        this.model = model;
        this.price = price;
    }

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

    public String getModel() {
        return model;
    }

    public double getPrice() {
        return price;
    }
}

Printer类

package com.team.domain;

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

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

    public String getName() {
        return name;
    }

    public String getType() {
        return type;
    }
}

Data类

package com.team.service;


public class Data {
    public static final int EMPLOYEE = 10;
    public static final int PROGRAMMER = 11;
    public static final int DESIGNER = 12;
    public static final int ARCHITECT = 13;

    public static final int PC = 21;
    public static final int NOTEBOOK = 22;
    public static final int PRINTER = 23;

    //Employee  :  10, id, name, age, salary
    //Programmer:  11, id, name, age, salary
    //Designer  :  12, id, name, age, salary, bonus
    //Architect :  13, id, name, age, salary, bonus, stock
    public static final String[][] EMPLOYEES = {
        {"10", "1", "马云 ", "22", "3000"},
        {"13", "2", "马化腾", "32", "18000", "15000", "2000"},
        {"11", "3", "李彦宏", "23", "7000"},
        {"11", "4", "刘强东", "24", "7300"},
        {"12", "5", "雷军 ", "28", "10000", "5000"},
        {"11", "6", "任志强", "22", "6800"},
        {"12", "7", "柳传志", "29", "10800","5200"},
        {"13", "8", "杨元庆", "30", "19800", "15000", "2500"},
        {"12", "9", "史玉柱", "26", "9800", "5500"},
        {"11", "10", "丁磊 ", "21", "6600"},
        {"11", "11", "张朝阳", "25", "7100"},
        {"12", "12", "杨致远", "27", "9600", "4800"}
    };
    
    //如下的EQUIPMENTS数组与上面的EMPLOYEES数组元素一一对应
    //PC      :21, model, display
    //NoteBook:22, model, price
    //Printer :23, name, type 
    public static final String[][] EQUIPMENTS = {
        {},
        {"22", "联想T4", "6000"},
        {"21", "戴尔", "NEC17寸"},
        {"21", "戴尔", "三星 17寸"},
        {"23", "佳能 2900", "激光"},
        {"21", "华硕", "三星 17寸"},
        {"21", "华硕", "三星 17寸"},
        {"23", "爱普生20K", "针式"},
        {"22", "惠普m6", "5800"},
        {"21", "戴尔", "NEC 17寸"},
        {"21", "华硕","三星 17寸"},
        {"22", "惠普m6", "5800"}
    };
}

Status类

package com.team.service;

public class Status {
    private final String NAME;
    public Status(String NAME) {
        this.NAME = NAME;
    }
    public static final Status FREE=new Status("FREE");
    public static final Status BUSY=new Status("BUSY");
    public static final Status VOCATION=new Status("VOCATION");

    public String getNAME() {
        return NAME;
    }
    @Override
    public String toString(){
        return NAME;
    }
}

TeamException类(自定义异常类)

package com.team.service;
/**
 * @Auther: tdongmu
 * @Date: ${DATE} ${TIME}
 * @Description:自定义异常类
 */

public class TeamException extends Exception{
    static final long serialVersionUID = -3387514229948L;

    public TeamException() {
        super();
    }

    public TeamException(String message) {

        super(message);
    }
}

NameListService类

package com.team.service;

import com.team.domain.*;

import static com.team.service.Data.*;

public class NameListService {
    private Employee[] employees;

    public NameListService() {
        employees=new Employee[EMPLOYEES.length];
        for(int i=0;i<employees.length;i++){
            int tamp=Integer.parseInt(EMPLOYEES[i][0]);
            String name=EMPLOYEES[i][2];
            int id=Integer.parseInt(EMPLOYEES[i][1]);
            int age=Integer.parseInt(EMPLOYEES[i][3]);
            double salary=Double.parseDouble(EMPLOYEES[i][4]);
            if(tamp==10){
                employees[i]=new Employee(name, id, age, salary);
            }
            if(tamp==11){
                Equipment equipment=createEquipment(i);//在设备组查询并创造相应设备对象
                employees[i]=new Programmer(name, id, age, salary,equipment);
            }
            if(tamp==12){
                double bonus=Double.parseDouble(EMPLOYEES[i][5]);
                Equipment equipment=createEquipment(i);//在设备组查询并创造相应设备对象
                employees[i]=new Designer(name, id, age, salary,equipment,bonus);
            }
            if(tamp==13){
                int stock=Integer.parseInt(EMPLOYEES[i][6]);
                double bonus=Double.parseDouble(EMPLOYEES[i][5]);
                Equipment equipment=createEquipment(i);//在设备组查询并创造相应设备对象
                employees[i]=new Architect(name, id, age, salary,equipment,bonus,stock);
            }
        }
    }
//创建设备对象
    private Equipment createEquipment(int i) {
        int tamp2=Integer.parseInt(EQUIPMENTS[i][0]);
        Equipment equipment=null;
        String modle=EQUIPMENTS[i][1];
        switch (tamp2){
            case PC:
                String display=EQUIPMENTS[i][2];
                 equipment=new PC(modle,display);
                break;
            case NOTEBOOK:
                Double price=Double.parseDouble(EQUIPMENTS[i][2]);
                 equipment=new NoteBook(modle,price);
                break;
            case PRINTER:
                String type=EQUIPMENTS[i][2];
                 equipment=new Printer(modle,type);
        }
        return equipment;
    }
     //获取当前所有员工
    public Employee[] getAllEmployees() {
        return employees;
    }
    //获取指定id员工
    public Employee getEmployees(int id) throws TeamException {

        for(int i=0;i<employees.length;i++){
            if(employees[i].getId()==id){
                return employees[i];
            }
        }
        throw new TeamException("找不到该员工");

    }
}

TeamService类

package com.team.service;

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

public class TeamService {
    private static int counter=1;
    public static  final int MAX_MEMBER=5;
    private Programmer[] team;
    private int count;

    public TeamService() {
        team=new Programmer[MAX_MEMBER];
    }
    //添加团队成员
    public void addMember(NameListService nameListService,int id) throws TeamException{
        if(count>=MAX_MEMBER){
            throw new TeamException("团队人员已满,添加失败");
        }
       Employee p = nameListService.getEmployees(id);
       //不是开发人员,无法添加
       if(!(p instanceof Programmer)){
           throw new TeamException("成员非开发人员,无法添加");
       }
       //成员已经在团队中
       if(isExist(id)){
           throw new TeamException("成员已经在团队中");
       }
       //成员正在休假或者已在别的团队中
            Programmer e = (Programmer) nameListService.getEmployees(id);
       if(( e).getStatus().getNAME().equals("BUSY")){
           throw new TeamException("已在别的团队中");
       }else if("VOCATION".equals(( e).getStatus().getNAME())){
           throw new TeamException("成员正在休假");
       }
       //团队中只能存在一名构架师,2名设计师,3名程序员
       if (getNumber("Architect")>=1&&getNumber("Designer")>=2&&getNumber("Programmer")>=3){
           throw new TeamException("团队中不能超过1名架构师,2名设计师,3名程序员");
       }
       //添加成员到团队中
        e.setMemberId(counter++);
        //改变员工状态
        e.setStatus(Status.BUSY);
        team[count++]= e;
    }
    //查询队伍中构架师,设计师,程序员数量
    public int getNumber(String profession){
        int numOfArchitect=0,numOfDesigner=0,numOfEmployee=0;
        for(int i=0;i<team.length;i++){
            if(team[i]instanceof Architect){
               numOfArchitect++;
            }else if(team[i] instanceof Designer){
                numOfDesigner++;
            }else {
                numOfEmployee++;
            }
        }
        //获得团队中三种员工数量
        if("Architect".equalsIgnoreCase(profession)){
            return numOfArchitect;
        }else if("Designer".equalsIgnoreCase(profession)){
            return numOfDesigner;
        }
        return numOfEmployee;
    }
    //查询团队中是否有该成员
    public boolean isExist(int id){
        for(int i=0;i<count;i++){
            if(team[i].getId()==id){
                return true;
            }
        }return false;
    }
    //删除团队成员
    public boolean removeMember(int TID)throws TeamException{
        int i=0;
        boolean flag=false;
        for(;i<count;i++){
            if(team[i].getMemberId()==TID){
                team[i].setStatus(Status.FREE);
                count--;
                flag=true;
                break;
            }
        }
        for(int j=i;j<count;j++){
            team[j]=team[j+1];
        }
        team[count]=null;
        if(flag){
            return true;
        }else {
        throw new TeamException("团队未找到该成员,删除失败");
        }
    }
    //获取TID团队成员
    public Programmer getTeam(int TID)throws TeamException {
        for(int i=0;i<team.length;i++){
            if(team[i].getMemberId()==TID){
                return team[i];
            }
        }
       throw new TeamException("未在团队中找到该成员");
    }
    //获取团队所有成员
    public Programmer[] getAllTeam(){
        Programmer team[]=new Programmer[count];
        for(int i=0;i<team.length;i++){
            team[i]=this.team[i];
        }
        return team;
    }
}

TSUtility类

package com.team.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;
    }
}

 TeamView类

package com.team.view;

import com.team.domain.Employee;
import com.team.domain.Programmer;
import com.team.service.NameListService;
import com.team.service.TeamException;
import com.team.service.TeamService;
import java.util.Scanner;

/**
 * @Auther: tdongmu
 * @Date: 2020/11/17 16:58
 * @Description:用户使用展示类
 */

public class TeamView {
    private NameListService nameListService=new NameListService();
    private TeamService teamService=new TeamService();
    //进入主页面
    public void enterMenu(){
        listAllEmployee();
        char menu=0;
        boolean flag=true;
        while (flag) {
            if(menu!='1'){
                listAllEmployee();
                getTeam();
            }
            System.out.println("1.团队列表 2.添加团队成员 3.删除团队成员 4.退出");
            menu=TSUtility.readMenuSelection();
            switch (menu) {
                case '1':
                    getTeam();
                    break;
                case '2':
                    addMember();
                    break;
                case '3':
                    deleteMember();
                    break;
                case '4':
                    System.out.println("是否选择退出(Y/N)");
                    char a=TSUtility.readConfirmSelection();
                    if(a=='Y'){
                        flag=false;
                    }

            }
        }

    }
    //全体员工列表
    public void listAllEmployee(){
        System.out.println("----------------------------------开发调度成员----------------------------------------");
        System.out.println("id\t姓名\t\t年龄\t工资\t\t职位\t\t状态\t\t奖金\t\t股票\t\t领用设备");
        Employee employees[]= nameListService.getAllEmployees();
        for(int i=0;i<employees.length;i++){
            System.out.println(employees[i].toString());
        }
        System.out.println("------------------------------------------------------------------------------------");

    }
    //团队成员列表
    public void getTeam(){
        System.out.println("展示团队成员");
        System.out.println("TID\tid\t姓名\t\t年龄\t工资\t\t职位\t\t状态\t\t奖金\t\t股票\t\t领用设备2");
        Programmer programmers[]=teamService.getAllTeam();
        if(programmers.length==0){
            System.out.println("没有团队成员。。。。。");
        }
        //遍历打印
        for(int i=0;i<programmers.length;i++){
            System.out.println(programmers[i].getMemberId()+"\t"+programmers[i].toString());
        }
    }
    //添加团队成员
    public void addMember() {
        System.out.println("增加团队成员");
        System.out.println("请输入要添加员工id");
        int id=TSUtility.readInt();
        try {
            teamService.addMember(nameListService,id);
            System.out.println("添加成功");
            //按回车键继续
            TSUtility.readReturn();
        } catch (TeamException e) {//异常块
           System.out.println("添加失败,原因:"+e.getMessage());
           TSUtility.readReturn();
        }

    }
    public void deleteMember(){
        System.out.println("删除团队成员");
        System.out.println("请输入要删除员工的TID");
        int TID=TSUtility.readInt();
        try {
            teamService.removeMember(TID);
            System.out.println("删除成功");
            TSUtility.readReturn();
        } catch (TeamException e) {
           System.out.println("删除失败,"+e.getMessage());
            TSUtility.readReturn();
        }

    }
    public static void main (String[] agrs){
        TeamView teamView=new TeamView();
        teamView.enterMenu();

    }
}

6.项目获取途径

此项目实在尚硅谷Java基础教学宋红康老师的网课项目中获取。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值