emploree

代码块
```package com.fornknow.employee;

public class Emploree {
    private String id;
    private String name;
    private double salary;
    private String department;
    
    public Emploree(String id,String name,double salary,String department){
        this.id=id;
        this.name=name;
        this.salary=salary;
        this.department=department;
    }
    
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getSalary() {
        return salary;
    }
    public void setSalary(double salary) {
        this.salary = salary;
    }
    public String getDepartment() {
        return department;
    }
    public void setDepartment(String department) {
        this.department = department;
    }

}

代码块

/**
 * 添加员工信息
 * @author Administrator
 *
 */
/**
 * 根据ID查询员工信息
 * 据ID删除员工信息
 * 修改员工信息
 * 查询所有员工的信息
 * @author Administrator
 *
 */
public class Mannger {
    //初始化一个数组
    private Emploree[] emplorees;
    private int count;
    public Mannger(){
        this.count=count;
        this.emplorees=new Emploree[5];
    }
    public void add(Emploree emp){
        //通过此方法向emploree数组中添加员工信息(对象)
        if (count<5){
            emplorees[count]=emp;
            count++;
            System.out.println("a添加成功。。。");
        }else{
            System.out.println("添加失败。。。。");
        }
        
        
    }
    public Emploree getbyID(String id){
        Emploree emploree=null;
        //遍历数组
        //判断数组中的对象的属性ID是否与参数的ID一
        for (int i = 0; i < emplorees.length; i++) {
            //将数组中的变量赋值给emploree
            if (emplorees[i].getId().equals(id)) {
                emploree=emplorees[i];
                break;
                
            }
        }
        return emploree;
    }
    //修改员工信息
    public Emploree updateEmploree(Emploree e){
         
        return null;
    }
    public Emploree[] getAllMessage(){
        //创建一个新数组
        Emploree[] emps=new Emploree[5];
        //对原数组进行遍历
        for (int i = 0; i < emplorees.length; i++) {
            emps[i]=emplorees[i];
        }
        return emps;
    }

}

代码块


import com.foreknow.test.exam1;
import com.fornknow.oop.muting;

public class Test {
    public static void main(String[] args) {
        Mannger mannger=new Mannger();
        Emploree e1=new Emploree("1","lisa",1000.0,"ren");
//      e1.setId("1");
//      e1.setName("lisa");
//      e1.setSalary(1000.0);
//      e1.setDepartment("ren");
        
        Emploree e2=new Emploree("1","lisa",1000.0,"ren");
//      e2.setId("2");
//      e2.setName("IU");
//      e2.setSalary(1000.0);
//      e2.setDepartment("ren");
//      
        Emploree e3=new Emploree("1","lisa",1000.0,"ren");
//      e3.setId("3");
//      e3.setName("Rose");
//      e3.setSalary(1000.0);
//      e3.setDepartment("ren");
//      
        Emploree e4=new Emploree("1","lisa",1000.0,"ren");
//      e4.setId("4");
//      e4.setName("jisoo");
//      e4.setSalary(1000.0);
//      e4.setDepartment("ren");
        
        Emploree e5=new Emploree("1","lisa",1000.0,"ren");
//      e5.setId("5");
//      e5.setName("jiniee");
//      e5.setSalary(1000.0);
//      e5.setDepartment("ren");
        
        mannger.add(e1);
        mannger.add(e2);
        mannger.add(e3);
        mannger.add(e4);
        mannger.add(e5);
        
        System.out.println("-------------");
        Emploree emploree=mannger.getbyID("1");
        System.out.println(emploree.getId()+"-----"+emploree.getName()+"-----"+emploree.getSalary());
    //查询所有员工信息的方法
        System.out.println("---------------");
         Emploree[] empss=mannger.getAllMessage();
         for (int i = 0; i < empss.length; i++) {
             Emploree e=empss[i];
             System.out.println(e.getId()+"--"+e.getName()+"--"+e.getDepartment());
        }
         
    }
       

}

你可能感兴趣的:(emploree)