0
点赞
收藏
分享

微信扫一扫

开发团队调度软件

hoohack 2022-02-25 阅读 64
java

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
下面是自己写的,基本功能可以实现,但代码冗长杂乱,逻辑不够清晰,暂且放在这里,以后深入学习之后,再回过头看
在这里插入图片描述

package com.project3.team.Domain;

//员工
public class Employee {

	protected int id;
	protected String name;
	protected int age;
	protected double salary;
	protected String job;
	protected String status;
	protected double bonus;
	protected int stock;
	protected String equipment;
	
	public Employee(int id, String name, int age, double salary, String job, double bonus, int stock) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
		this.salary = salary;
		this.job = job;
		this.bonus = bonus;
		this.stock = stock;
	}

	public Employee(int id, String name, int age, double salary, String job, String status, double bonus, int stock,
			String equipment) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
		this.salary = salary;
		this.job = job;
		this.status = status;
		this.bonus = bonus;
		this.stock = stock;
		this.equipment = equipment;
	}
	
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public String toString() {
		
		if(job == null) {
			return id + "\t" + name + "\t" + age + "\t" + salary;
		}
		if(bonus == 0) {
			return id + "\t" + name + "\t" + age + "\t" + salary + "\t" + job
					+ "\t" + status + "\t" + "\t" + "\t" + equipment;
		}
		if(stock == 0) {
			
			return id + "\t" + name + "\t" + age + "\t" + salary + "\t" + job
					+ "\t" + status + "\t" + bonus + "\t" + "\t" + equipment;
		}
		return id + "\t" + name + "\t" + age + "\t" + salary + "\t" + job
				+ "\t" + status + "\t" + bonus + "\t" + stock + "\t" + equipment;
	}
	
}

```java
package com.project3.team.Domain;


//团队成员
public class Teamer extends Employee{

	int TID;
	public Teamer(int TID,int id, String name, int age, double salary, String job, double bonus, int stock) {
		super(id, name, age, salary, job, bonus, stock);
		this.TID = TID;
	}


	@Override
	public String toString() {
		if(bonus == 0) {
			return TID + "/" + id + "\t" + name + "\t" + age + "\t" + salary + "\t" + job
					+ "\t" + "\t" + stock;
		}
		return TID + "/" + id + "\t" + name + "\t" + age + "\t" + salary + "\t" + job
				+ "\t" + bonus + "\t" + stock;
		
	}
}


```java
package com.project3.team.Domain;

import com.project3.team.Service.TeamException;
import com.project3.team.Service.Utility;

public class TeamerService {
	Teamer[] team = new Teamer[12];
	Employee[] p1;
	int num = 0;
	int architect = 0;//架构师数量
	int stylist = 0;//设计师数量
	int programmer = 0;//程序员数量
	public TeamerService(Employee[] p12) {
		p1 = p12;
	}
	public void showTeam() {
		if(num == 0) {
			System.out.println("目前团队中没有成员");
		}else {
			System.out.println("----------------------------开发团队----------------------------");
			System.out.println("TID" + "/ID" + "\t姓名" + "\t年龄" + "\t工资" + "\t职位" + "\t奖金" + "\t股票");
			for(int i = 0;i < num;i++) {
				if(team[i].TID == 0) {
					continue;
				}
				System.out.println(team[i]);
			}
			
		}
	}
	//添加完成后,员工状态由Free变为Busy
	public void addTeam(int i) {
			if(i > p1.length) {
				throw new TeamException("添加失败。原因:该成员不存在");
			}
			if(p1[i-1].status == null) {
				throw new TeamException("该成员不是开发人员");
			}
			if(p1[i-1].status == "Busy") {
				throw new TeamException("该成员已在团队中");
			}
			if(p1[i-1].job == "架构师") {
				architect += 1;
			}
			if(p1[i-1].job == "设计师") {
				stylist += 1;
			}
			if(p1[i-1].job == "程序员") {
				programmer += 1;
			}
			if(architect < 2) {
				team[num] = new Teamer(num + 1, p1[i-1].id, p1[i-1].name, p1[i-1].age, p1[i-1].salary, p1[i-1].job, p1[i-1].bonus, p1[i-1].stock);
				p1[i-1].status = "Busy";
			}else {
				throw new TeamException("至多有一名架构师");
			}
			if(stylist < 3) {
				team[num] = new Teamer(num + 1, p1[i-1].id, p1[i-1].name, p1[i-1].age, p1[i-1].salary, p1[i-1].job, p1[i-1].bonus, p1[i-1].stock);
				p1[i-1].status = "Busy";
			}else {
				throw new TeamException("至多有两名设计师");
			}
			if(programmer < 4) {
				team[num] = new Teamer(num + 1, p1[i-1].id, p1[i-1].name, p1[i-1].age, p1[i-1].salary, p1[i-1].job, p1[i-1].bonus, p1[i-1].stock);
				p1[i-1].status = "Busy";
			}else {
				throw new TeamException("至多有三名程序员");
			}
			
			team[num] = new Teamer(num + 1, p1[i-1].id, p1[i-1].name, p1[i-1].age, p1[i-1].salary, p1[i-1].job, p1[i-1].bonus, p1[i-1].stock);
			System.out.println("添加成功");
			num++;
		
	}
	public void delTeam(int index) {
		boolean yn = false;
		System.out.println("是否退出(Y/N):");
		char isExit = Utility.readChar();
		if(isExit == 'Y') {
			yn = true;
		}
		while(yn) {
			if(index - 1 < num) {
				team[index-1].TID = 0;
				System.out.println("删除成功");
				p1[team[index-1].id-1].status = "Free";
				yn = false;
			}else {
				throw new TeamException("该成员不存在");
			}
		}
	}
	
}

package com.project3.team.Service;

public class TeamException extends RuntimeException{

	static final long serialVersionUID = -703489745766939L;
	
	public TeamException() {
		
	}
	public TeamException(String msg) {
		super(msg);
	}
}

package com.project3.team.Service;

import java.util.Scanner;

public class Utility {

	//菜单选择
	private static Scanner scanner = new Scanner(System.in);
	public static char menuSeclect() {
			char c;
			for(; ; ){
				String str = readKeyBoard(1,false);//返回长度为1的字符串
				c = str.charAt(0);//返回0位置的字符
				if(c!='1'&&c!='2'&&c!='3'&&c!='4'){
					System.out.print("选择错误,请重新输入:");
				}else break;
			}
			return c;
	}

	//员工ID、TID选择
	public static int IDSeclect() {
		int n;
		for(; ; ){
			String str = readKeyBoard(2,false);//返回长度在1-2的字符串
		try{
			n = Integer.parseInt(str);//将整型数据Integer转换为基本数据类型int(整数 / 整型数,与小数 / 浮点数相对)
			break;
		}catch(NumberFormatException e){
			System.out.print("输入错误,请重新输入:");//数型转换异常
		}	
	}
	return n;
	}
	//回车下一步,其他显示输入错误
	public static void readChar2() {
		boolean isflag = true;
		while(isflag) {
			String str = readKeyBoard(1,true);//返回长度为1的字符,或者空字符
			if(str.length() == 0) {
				isflag = false;
			}else {
				System.out.println("输入错误");
			}
		}
	}
	//退出选择
	public static char readChar() {
		String str = readKeyBoard(1,false);//返回长度为1的字符
		return str.charAt(0);
	}
	
		
	private static String readKeyBoard(int limit,boolean blankReturn) {
		
		String line="";
		
		while(scanner.hasNextLine()) {//如果此扫描器的输入中还有另一行,则java.util.Scanner类的hasNextLine()方法将返回true。等待输入时,此方法可能会阻塞。扫描仪不会越过任何输入。
			line=scanner.nextLine();//nextLine()方法是读取一整行,以一个回车符作为结束标记停止扫描
			if(line.length() == 0) {
				if(blankReturn)return line;//blankReturn=false时,只能输入字符,=true时,返回回车或者字符
				else continue;
			}
			if(line.length()<1||line.length()>limit) {
				System.out.print("输入长度(不大于"+limit+")");//即长度要求在1和limit之间,不在时有此提示
				continue;
			}
			else break;//在要求范围内,则跳出循环,返回line。
		}
		return line;
	}
}

package com.project3.team.View;

import com.project3.team.Domain.Employee;
import com.project3.team.Domain.TeamerService;
import com.project3.team.Service.TeamException;
import com.project3.team.Service.Utility;
//菜单显示,处理用户操作
public class TeamView {

	public static void main(String[] args) {
		Employee[] p1 = new Employee[12];
		p1[0] = new Employee(1, "马云", 22, 3000.0, null, null, 0, 0, null);
		p1[1] = new Employee(2, "马化腾", 32, 18000.0, "架构师", "Free", 15000.0, 2000, "联想T4(6000.0)");
		p1[2] = new Employee(3, "李彦宏", 23, 7000.0, "程序员", "Free", 0, 0, "戴尔(NEC17寸)");
		p1[3] = new Employee(4, "刘强东", 24, 7300.0, "程序员", "Free", 0, 0, "戴尔(三星17寸)");
		p1[4] = new Employee(5, "雷军", 28, 10000.0, "设计师", "Free", 5000.0, 0, "激光");
		p1[5] = new Employee(6, "任志强", 22, 6800.0, "程序员", "Free", 0, 0, "华硕");
		p1[6] = new Employee(7, "柳传志", 29, 10800.0, "设计师", "Free", 5200.0, 0, "华硕");
		p1[7] = new Employee(8, "杨元庆", 30, 19800.0, "架构师", "Free", 15000.0, 2500, "针式");
		p1[8] = new Employee(9, "史玉柱", 26, 9800.0, "设计师", "Free", 5500.0, 0, "惠普");
		p1[9] = new Employee(10, "丁磊", 21, 6600.0, "程序员", "Free", 0, 0, "戴尔");
		p1[10] = new Employee(11, "张朝阳", 25, 7100.0, "程序员", "Free", 0, 0, "华硕");
		p1[11] = new Employee(12, "杨志远", 27, 9600.0, "设计师", "Free", 4800.0, 0, "惠普");
		
		TeamerService te = new TeamerService(p1);
		boolean isFlag = true;
		while(isFlag) {
			//菜单展示
			display(p1);
			//菜单选择
			char sec = Utility.menuSeclect();
			//匹配
			switch(sec) {
			case'1':
				te.showTeam();
				System.out.println("回车键继续");
				Utility.readChar2();
				break;
			case'2':
				System.out.println("请输添加成员的ID");
				try {
					te.addTeam(Utility.IDSeclect());
				} catch (TeamException e) {
					System.out.println(e.getMessage());
				}
				System.out.println("回车键继续");
				Utility.readChar2();
				break;
			case'3':
				System.out.println("请输入要删除成员的TID");
				try {
					te.delTeam(Utility.IDSeclect());
				} catch (TeamException e) {
					System.out.println(e.getMessage());
				}
				System.out.println("回车键继续");
				Utility.readChar2();
				break;
			case'4':
				System.out.println("是否退出(Y/N):");
				char isExit = Utility.readChar();
				if(isExit == 'Y') {
					isFlag = false;
				}
			}
		}
	}
	
	public static void display(Employee[] p) {
		System.out.println("----------------------------开发团队调度软件----------------------------");
		System.out.println("ID" + "\t姓名" + "\t年龄" + "\t工资" + "\t职位" + "\t状态" + "\t奖金" + "\t股票" + "\t领用设备");
		for(int i = 0;i < p.length;i++) {
			System.out.println(p[i]);
		}
		System.out.println("----------------------------------------------------------------------");
		System.out.println("1-团队列表   2-添加团队成员   3-删除团队成员    4-退出    请选择(1-4):");
		
	}
}

输出
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

举报

相关推荐

0 条评论