Java简单项目:公司人员管理系统

简单开个坑

初步完成Model设计和部分Controller设计,手有点冷,脑子有点蒙,明天再补剩下的

1.1.父类Employee

package project3.domain;

public class Employee {
	private int id;
	private String name;
	private int age;
	private double salary;
	
	public Employee(int id, String name, int age, double salary) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
		this.salary = 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;
	}
	
}

1.2.子类Programer

package project3.domain;

import project3.service.Status;

public class Programmer extends Employee{
	private int memberId;
	private Status status;// = FREE
	private Equipment equipment;
	
	public Programmer(int id, String name, int age, double salary,int memberId, Status status, Equipment equipment) {
		super(id,name,age,salary);
		this.memberId = memberId;
		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;
	}
	
	
}

1.3.子类Designer

package project3.domain;

import project3.service.Status;

public class Designer extends Programmer{
	
	public Designer(int id, String name, int age, double salary, int memberId, Status status, Equipment equipment,double bonus) {
		super(id, name, age, salary, memberId, status, equipment);
		// TODO Auto-generated constructor stub
		this.bonus = bonus;
	}

	private double bonus;//奖金
	


	public double getBonus() {
		return bonus;
	}

	public void setBonus(double bonus) {
		this.bonus = bonus;
	}
	
}

1.4.子类Architect

package project3.domain;

import project3.service.Status;

public class Architect extends Designer{

	private int stock;//干股分红
	
	public Architect(int id, String name, int age, double salary, int memberId, Status status, Equipment equipment,
			double bonus,int stock) {
		super(id, name, age, salary, memberId, status, equipment, bonus);
		// TODO Auto-generated constructor stub
		this.stock = stock;
	}

	public int getStock() {
		return stock;
	}

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

1.5. 接口Equipment

package project3.domain;

public interface Equipment {
	
	public abstract String getDescription(Equipment e);

}

1.6.Equipment实现类1:PC

package project3.domain;

public class PC implements Equipment {
	private String model;
	private String display;
	@Override
	public String getDescription(Equipment e) {
		if(e instanceof PC) {
			PC p =(PC) e;
			return "PC [model=" + p.model + ", display=" + p.display + "]";
		}
		else {
			return "类型错误";
		}
	}
	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;
	}
	
	public PC() {
		
	}
}

1.7.Equipment实现类2:NoteBook

package project3.domain;

public class NoteBook implements Equipment {
	private String model;
	private double price;
	@Override
	public String getDescription(Equipment e) {
		if(e instanceof NoteBook) {
			NoteBook n = (NoteBook) e;
			return "NoteBook [model=" + n.model + ", price=" + n.price + "]";
		}else {
			return "类型错误";
		}
	}
	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() {
		
	}
}

1.8.Equipment实现类3:Printer

package project3.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() {
		
	}


	@Override
	public String getDescription(Equipment e) {
		if(e instanceof Printer) {
			Printer p = (Printer) e;
			return "Printer [name=" + p.name + ", type=" + p.type + "]";
			
		}else {
			return "类型错误!";
		}
	}

}

2.1.TeamException

package project3.service;

public class TeamException extends RuntimeException{
	static final long serialVersionUID = -7034897190745766939L;
	
	public TeamException() {
		
	}
	
	public TeamException(String msg) {
		super(msg);
	}
	
}

2.2.Data初始文件

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;

    //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"}
    };
    
    //如下的EQIPMENTS数组与上面的EMPLOYEES数组元素一一对应
    //PC      :21, model, display
    //NoteBook:22, model, price
    //Printer :23, type, name
    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"}
    };
}

2.3.Status

package project3.service;

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 VOCATION = new Status("VOCATION");
    public static final Status BUSY = new Status("BUSY");
    public String getNAME() {
        return NAME;
    }
    @Override
    public String toString() {
        return NAME;
    }
} 

2.4.(部分完成)NameListService

package project3.service;

import java.util.jar.Attributes.Name;

import project3.domain.Employee;

/**
 * 
 * @Description
 * 在NameListService类中临时添加一个main方法中,作为单元测试方法。
 * 在方法中创建NameListService对象,然后分别用模拟数据调用该对象的各个方法,以测试是否正确。
 * 注:测试应细化到包含了所有非正常的情况,以确保方法完全正确。
 * @author Dionysus_xu Email:2405483019@qq.com
 * @version
 * @Date 2022年2月16日下午1:51:39
 *
 */
public class NameListService {
	private Employee[] employees;
	
	public NameListService() {
		for(int i = 0 ;i <Data.EMPLOYEE;i++) {
			employees[i].setId(Integer.parseInt(Data.EMPLOYEES[i][1])); 
			employees[i].setName(Data.EMPLOYEES[i][2]); 
			employees[i].setAge(Integer.parseInt(Data.EMPLOYEES[i][3])); 
			employees[i].setSalary(Double.parseDouble(Data.EMPLOYEES[i][4])); 
			employees[i].setId(Integer.parseInt(Data.EMPLOYEES[i][5])); 
			employees[i].setId(Integer.parseInt(Data.EMPLOYEES[i][6])); 
			
		}
	}
	
	public Employee[] getAllEmployees() {
		return employees;
	}
	
	public Employee getEmployee(int id) throws TeamException{
		//version1:
		//一共5员工的话,length = 5,id 也到5,取的就是下标4的
		if(id>employees.length) {
			System.out.println("还没有这个员工哦");
			return null;
		}else {
			return employees[id-1];
		}
		//version2:
//		Employee e = null;
//		try {
//			e =employees[id-1];
//		} catch (Exception ee) {
//			ee.printStackTrace();
//		}
//		return e;
	}
	
	public static void main(String[] args) {
		NameListService namelists = new NameListService();
	}
}

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值