项目三:开发团队调度软件
知识点:
类的继承和多态
对象的值传递、接口
static 和 final 修饰符
特殊类的使用:包装类、抽象类、内部类
异常处理
service层
Date
package project3. 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 ;
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" }
} ;
public static final String[ ] [ ] EQIPMENTS = {
{
} ,
{
"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" }
} ;
}
NameListService
package project3. service;
import project3. domain. *;
import static project3. service. Data. *;
public class NameListService {
private Employee[ ] employees;
public NameListService ( ) {
employees= new Employee [ EMPLOYEES. length] ;
for ( int i = 0 ; i < employees. length ; i++ ) {
Equipment equipment;
int type = Integer. parseInt ( EMPLOYEES[ i] [ 0 ] ) ;
int id = Integer. parseInt ( EMPLOYEES[ i] [ 1 ] ) ;
String name= EMPLOYEES[ i] [ 2 ] ;
int age = Integer. parseInt ( EMPLOYEES[ i] [ 3 ] ) ;
double salary = Double. parseDouble ( EMPLOYEES[ i] [ 4 ] ) ;
switch ( type) {
case EMPLOYEE:
employees[ i] = new Employee ( id, name, age, salary) ;
break ;
case PROGRAMMER:
equipment= craetEquipment ( i) ;
employees[ i] = new Programmer ( id, name, age, salary, equipment) ;
break ;
case DESIGNER:
equipment= craetEquipment ( i) ;
double bonus = Double. parseDouble ( EMPLOYEES[ i] [ 5 ] ) ;
employees[ i] = new Designer ( id, name, age, salary, equipment, bonus) ;
break ;
case ARCHITECT:
equipment= craetEquipment ( i) ;
double bonus2 = Double. parseDouble ( EMPLOYEES[ i] [ 5 ] ) ;
int stock= Integer. parseInt ( EMPLOYEES[ i] [ 6 ] ) ;
employees[ i] = new Architect ( id, name, age, salary, equipment, bonus2, stock) ;
break ;
}
}
}
private Equipment craetEquipment ( int index) {
int type = Integer. parseInt ( EQIPMENTS[ index] [ 0 ] ) ;
String model = EQIPMENTS[ index] [ 1 ] ;
String display = EQIPMENTS[ index] [ 2 ] ;
switch ( type) {
case PC:
return new PC ( model, display) ;
case NOTEBOOK:
double price = Double. parseDouble ( EQIPMENTS[ index] [ 2 ] ) ;
return new NoteBook ( model