需求说明
软件结构设计
代码实现
将员工的基本信息类,data放置在service包中
package myproject03.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 = {
//通过switch-case的方式取值,不会出现数组角标越界的危险
{
"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"}
};
}
工具类TSUtility放置在view包中
package myproject03.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.