java面向对象员工管理系统

员工管理系统面向对象--基本类

public class Emp {
        //员工基本属性
	private int no;//工号
	private String name;//姓名
	private String sex;//性别
	private String major;//职位
	private double salary;//薪水
	//默认构造器
	public Emp() {
		
	}
	
	//含有参数的构造器
	public Emp(int no, String name, String sex, String major, double salary) {
		super();
		this.no = no;
		this.name = name;
		this.sex = sex;
		this.major = major;
		this.salary = salary;
	}

        //员工属性方法
	public int getNo() {
		return no;
	}
	public void setNo(int no) {
		this.no = no;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getMajor() {
		return major;
	}
	public void setMajor(String major) {
		this.major = major;
	}
	public double getSalary() {
		return salary;
	}
	public void setSalary(double salary) {
		this.salary = salary;
	}
	
        //重写toString方法,输出员工信息
	public  void showinfor(){
		System.out.println(no + "----" + name + "----" + sex + "----" + major + "----" + salary);
	}
	
}

 员工管理系统--管理类

import java.util.ArrayList;
/**
 *  构造方法实现管理系统的功能
 *
 */
public class EmpManager {
	//声明用于存储员工信息的容器,并初始化该容器
	ArrayList<Emp> db = new ArrayList<Emp>();
	//添加员工
	public void add(Emp e){
		db.add(e);
	}
	//修改指定员工薪资
	public void change(int no,double salary){
		for (Emp e:db) {
			if (e.getNo() == no) {
				e.setSalary(salary);
				break;
			}
		}
	}
	//查询所有员工
	public void chack(){
		for(Emp e:db){
			e.showinfor();
		}
	}
        //根据工号查询一位员工
	public void findNo(int no){
		for(Emp e:db){
			if (e.getNo() == no) {
				e.showinfor();
				break;
			}
		}
	}
        //删除一位员工
	public void delete(int no){
		int target = -1;
		for (int i = 0; i < db.size(); i++) {
			if (db.get(i).getNo() == no) {
				target = i;
				break;
			}
		}
		if (target != -1) {
			db.remove(target);
		}
	}
	//一个月应该发的总工资
	public void sumSal(){
		double sum = 0;
		for (Emp e:db) {
			sum += e.getSalary();
		}
		System.out.println("当月应发总工资:" + sum);
	}
	
	
}

员工管理系统--实现 

import java.util.Scanner;
/**
 *
 *  构造界面,实现功能
 *
 */
public class EmpTest {

	EmpManager es = new EmpManager();
	
	public void menu(){
		p("------员工管理系统-----");
		p("【1】员工入职");
		p("【2】员工薪资调整");
		p("【3】员工详细资料");
		p("【4】查询员工信息");
		p("【5】删除员工");
		p("【6】一个月发放总工资");
		command();
	}
	public void p(String s){
		System.out.println(s);
	}
	
	public void command(){
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		switch (i) {
		case 1:
			addEmp();
			break;
		case 2:
			changeEmp();
			break;
		case 3:
			checkAll();
			break;
		case 4:
			findEmp();
			break;
		case 5:
			deleteNo();
			break;
		case 6:
			es.sumSal();
			break;
		
		default:
			break;
		}
	}
	private void deleteNo() {
		p("要删除的员工号是:");
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		p("已删除员工" + n);
		es.delete(n);
		menu();
	}
	private void findEmp() {
		p("请输入查询员工号:");
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		p("查询完成:");
		es.findNo(n);
		menu();
	}
	private void addEmp() {
		p("==入职员工 ==\n员工号是: ");
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();
		p("姓名:");
		String name = sc.next();
		p("性别是:");
		String sex = sc.next();
		p("职位是:");
		String major = sc.next();
		p("月薪是:");
		double salary = sc.nextInt();
		
		Emp e = new Emp(no,name,sex,major,salary);
		es.add(e);
		p("添加完成!");
		menu();
	}
	
	private void changeEmp() {
		p("请输入改月薪员工的员工号:");
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();
		p("请输入调整后的月薪:");
		double salary = sc.nextInt();
		es.change(no, salary);
		p("调整成功!调整后" + no + "的月薪是:" + salary);
		menu();
		
	}

	private void checkAll() {
		es.chack();
		menu();
	}
	public static void main(String[] args) {
		
		new EmpTest().menu();

	}

}

 

  • 7
    点赞
  • 66
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值