前言:我是看了老师敲了一边后再自己敲的
一、domain包
1.1、Programmer类中的犯错
注:以下是正确的代码
public String getTeamBaseDetails(){
return memberId+"/"+getId()+"\t\t"+getName()+"\t"+getAge()+"\t\t"+getSalary();
}
作用:用于设计师类、架构师等各类中改写团队列表的print输出的
错误原因:(1)这个方法我一开始是认为是应该放在Employee类,结果就getmemberId()就开始报错,看报错是Employee中无法使用Programmer类中方法,原架构中方法不是静态的,只有new对象才能使用Programmer中的方法,但你重新new一个Programmer类会发现这个对象是空的
因为这是在单例模式下再new对象是不会有信息的
解决方法:在Programmer中写方法,Programmer继承Employee中的get方法,memberId可以写
Id,age等可以用get方法。
1.2、Status包
1.2.1 第一种偏差
注:以下是正确的代码
@Override
public String toString() {
return NAME ;
}
偏差原因:老师的包放在Service,我的包放在了domain
偏差解决:status包放错地方就可以用以上代码弥补。
二、Service包
2.1、Data包
注:这个包是自己打的童鞋注意了
package 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"}
};
}
(1)尽量上网找粘贴,不要当练习敲代码自己打,我当初自己打的时候就少打一个空集{},导致许多bug产生。
2.2、NameListService包
2.2.1、第一种偏差
注:以下是正确的代码,自己的代码与老师的代码的偏差
import static service.Data.*;
偏差原因:(1)虽然和老师的代码不相同,但是只要用Data.方法、Data.属性的方式也能使用,虽然我的方式也能用,但是老师的方法更简洁。
总结:这种方法值得学习。
2.2.2、第二种偏差
注:接下来的代码虽然有偏差,但是全部是正确的
老师的代码:
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("找不到指定的员工");
}
我的代码:
public Employee getEmployees(int id)throws TeamException {
Employee employee=null;
for (int i=0;i<employees.length;i++){
int ID=Integer.parseInt(EMPLOYEES[i][1]);
if (ID==id){
employee=employees[id-1];
}
}
if (employee==null){
throw new TeamException("数字过大或过小(1~12)");
}
return employee;
}
2.2.3 第一个bug
https://blog.csdn.net/p183173/article/details/128882048?spm=1001.2014.3001.5501
以上是全部主要的偏差和bug