栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java实现团队信息调度软件

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java实现团队信息调度软件

目录

一、主要涉及以下知识点

二、需求说明

三、软件结构设计

四、具体实现

1. 创建项目基本组件

2. 实现service包中的类

3. 实现view包中类


资源分享:

尚硅谷:

链接:https://pan.baidu.com/s/1BimdaZGrlChLs6iQaCidPw 
提取码:y8j5 
--来自百度网盘超级会员V6的分享

「Project3(开发团队人员调度软件)」https://www.aliyundrive.com/s/F3Ep6PbaMqg 提取码: c6x9 点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线查看,视频原画倍速播放。

我实现的:

「myproject3」https://www.aliyundrive.com/s/iG9nnuAjBUr 提取码: c6x9 点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线查看,视频原画倍速播放。

一、主要涉及以下知识点

类的继承性和多态性

对象的值传递、接口

static和final修饰符

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

异常处理

二、需求说明

该软件实现以下功能:

软件启动时,根据给定的数据创建公司部分成员列表(数组)

根据菜单提示,基于现有的公司成员,组建一个开发团队以开发一个新的项目 组建过程包括将成员插入到团队中,或从团队中删除某成员,还可以列出团队中现有成员的列表

开发团队成员包括架构师、设计师和程序员

三、软件结构设计

 

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

team.service模块为实体对象(Employee及其子类如程序员等)的管理模块, NameListService和TeamService类分别用各自的数组来管理公司员工和开发团队成员对象

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

四、具体实现

项目结构图:

junit包中的类是自定义的用来测试的类,完成一部分的代码之后可以在这里测试一下。

1. 创建项目基本组件

1. 完成以下工作:

        1.1 创建TeamSchedule项目

        1.2 按照设计要求,创建所有包

        1.3 将项目提供的几个类复制到相应的包中(view包中TSUtility.java;  service包中:Data.java)

2 按照设计要求,在team.domain包中,创建Equipment接口及其各实现子类代码

3. 按照设计要求,在team.domain包中,创建Employee类及其各子类代码

4. 检验代码的正确性

 

Equipment接口: 

package team.domain;


public interface Equipment {
    String getDescription();
}

Notebook: 

package team.domain;


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

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public NoteBook() {
    }

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

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

PC:

package team.domain;


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

Printer:

package team.domain;


public class Printer implements Equipment {
    private String name;//机器型号
    private String 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(){
        super();
    }
    public Printer(String name,String type){
        super();
        this.name = name;
        this.type = type;
    }

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

Status枚举类位于com.atguigu.team.service包中,封装员工的状态。代码如下

package team.service;

import javax.print.attribute.standard.MediaSize;


public class Status {
    private final String NAME;

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

    public String getNAME() {
        return NAME;
    }

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

Employee表示所有员工的父类,他有三个子类,programmer,designer,architect。

 具体关系为:Programmer是Employee的子类,Designer是programmer的子类,Architect是designer的子类。

 

Employee:

package team.domain;


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

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

    public String getName() {
        return name;
    }

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

    public int getAge() {
        return age;
    }

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

    public double getSalary() {
        return salary;
    }

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

    public Employee(int id, String name, int age, double salary) {
        super();
        this.id = id;
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String GetDetials(){
        return id + "t" + name + "t" + age + "t" + salary;
    }
    @Override
    public String toString() {
        return GetDetials();
    }
}

 Programmer:

package team.domain;

import team.service.Status;


public class Programmer extends Employee{
    private int memberId;//开发团队的ID
    private Status status = Status.FREE;
    private Equipment equipment;

    public Programmer() {
        super();
    }

    public Programmer(int id, String name, int age, double salary,Equipment equipment) {
        super(id, name, age, salary);
//        this.status = status;
        this.equipment = equipment;
    }

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

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

    public String getTeamBaseDetails(){
        return memberId + "/" + getId() + "t" + getName() + "t" + getAge() + "t" + getSalary();
    }
    public String getDetailsForTeam() {
        return getTeamBaseDetails() + "t程序员";
    }
}

Designer:

package team.domain;


public class Designer extends Programmer {
    private double bonus;

    public Designer() {
        super();
    }

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

    @Override
    public String toString() {
        return GetDetials() + "t设计师t" + getStatus() + "t" + bonus + "tt" + getEquipment().getDescription();
    }

    public String getDetailsForTeam(){
        return getTeamBaseDetails() + "t设计师" + getBonus();

    }
}

Architect:

package team.domain;


public class Architect extends Designer {
    private double stock;

    public Architect() {
        super();
    }

    public Architect(int id, String name, int age, double salary, Equipment equipment, double bonus, double stock) {
        super(id, name, age, salary, equipment, bonus);
        this.stock = stock;
    }

    public double getStock() {
        return stock;
    }

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

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

    public String getDetailsForTeam(){
        return getTeamBaseDetails() + "t架构师" + getBonus() + "t" + getStock();

    }
}

2.实现service包中的类

 

自定义异常类:TeamException

package team.service;


public class TeamException extends Exception {
    static final long serialVersionUID = -3387514229948L;//随便选,别和系统自带的重合就行

    public TeamException() {
        super();
    }

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

NameListService:

package team.service;

import team.domain.*;

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


public class NameListService {

    private Employee[] employees;

    
    public NameListService(){
        employees = new Employee[Data.EMPLOYEES.length];

        for (int i=0;i 

 

 

TeamService:

package team.service;

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


public class TeamService {
    //定义属性
    private static int counter = 1;//给memberID赋值使用
    private final int MAX_MEMBER = 5;//限制开发团队的人数最多为5个
    private Programmer[] team = new Programmer[MAX_MEMBER];
    private int total;//记录开发团队的实际的人数

    public TeamService(){
        super();
    }

    //定义方法
    
    public Programmer[] getTeam(){
        Programmer[] team = new Programmer[total];
        for (int i=0;i= MAX_MEMBER){
            throw new TeamException("成员已满,无法添加!");
        }
        //该成员不是开发成员,无法添加
        if (!(e instanceof Programmer)){
            throw new TeamException("该成员不是开发成员,无法添加");
        }
        //该员工已经在开发团队当中
        if (isExist(e)){
            throw new TeamException("该员工已经在开发团队当中");
        }
        //该员工已经是某团队的成员了
        //该成员正在休假,无法添加
        Programmer p = (Programmer)e;//一定不会出现ClassCastException
        if ("BUSY".equalsIgnoreCase(p.getStatus().getNAME())){
            //比 p.getStatus().getNAME().equals"BUSY 这样更好,避免出现空指针
            throw new TeamException("该员工已经是某团队的成员了!");
        }else if ("VOCATION".equalsIgnoreCase(p.getStatus().getNAME())){
            throw new TeamException("该成员正在休假,无法添加了!");
        }
        //团队中至多只能有一名架构师
        //团队中至多只能有两名设计师
        //团队中至多只能有三名程序员
        //获取团队当中已有成员的架构师,设计师,程序员的人数
        int numOfPro = 0,numOfDes = 0,numOfArch = 0;
        for(int i = 0;i < total;i++){
            if(team[i] instanceof Architect){
                numOfArch++;
            }else if(team[i] instanceof Designer){
                numOfDes++;
            }else if(team[i] instanceof Programmer){
                numOfPro++;
            }
        }
        if (p instanceof Architect){
            if (numOfArch >= 1){
                throw new TeamException("团队中至多只能有一名架构师,无法添加了!");
            }else if (numOfDes >=2){
                throw new TeamException("团队中至多只能有两名设计师,无法添加了!");
            }else if (numOfPro>=3){
                throw new TeamException("团队中至多只能有三名程序员,无法添加了!");
            }
        }

        //这种方法是不行的
        //例如,有两名设计师,再添加一名架构师,会报"团队中至多只能有两名设计师"的异常
//        if(p instanceof Architect && numOfArch >= 1){
//            throw new TeamException("团队中至多只能有一名架构师");
//        }else if(p instanceof Designer && numOfDes >= 2){
//            throw new TeamException("团队中至多只能有两名设计师");
//        }else if(p instanceof Programmer && numOfPro >= 3){
//            throw new TeamException("团队中至多只能有三名程序员");
//        }

        
        team[total++] = p;
        //p的属性赋值
        p.setStatus(Status.BUSY);
        p.setMemberId(counter++);

    }
    
    private boolean isExist(Employee e) {
        for (int i=0;i 

 3.实现view包中类

 

 

 TimeView:

package team.view;

import team.domain.Employee;
import team.domain.Programmer;
import team.service.NameListService;
import team.service.TeamException;
import team.service.TeamService;


public class TeamView {
    private NameListService listSvc = new NameListService();
    private TeamService teamSvc = new TeamService();

    public void enterMainMenu(){
        boolean isFlag = true;
        char menu = 0;
        while (isFlag){

            if (menu != '1'){
                listAllEmployees();
            }

            System.out.print("1-团队列表  2-添加团队成员  3-删除团队成员 4-退出   请选择(1-4):");
            menu = TSUtility.readMenuSelection();
            switch (menu) {
                case '1':
                    getTeam();
                    break;
                case '2':
                    addMember();
                    break;
                case '3':
                    deleteMember();
                    break;
                case '4':
                    System.out.print("确认是否退出(Y/N):");
                    char isExit = TSUtility.readConfirmSelection();
                    if(isExit == 'Y'){
                        isFlag = false;
                    }
                    break;
            }
        }

    }
    
    public void listAllEmployees(){
        System.out.println("-------------------------------开发团队调度软件--------------------------------n");

        Employee[] employees = listSvc.getAllEMployees();
        if(employees == null || employees.length == 0){
            System.out.println("员工列表为空");
            System.out.println("--------------------------------------------------------------");
        }else{
            System.out.println("IDt姓名t年龄t工资t职位t状态t奖金t股票t领用设备");

            //方法一
            for (int i=0;i

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/827006.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号