2019-07-29

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

public class Emploree {
    private String id;
    private String name;
    private double salary;
    private String 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=new Emploree[5];
    private int count;
    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 void updateEmploree(Emploree e){
        
    }
    public Emploree[] getAllMessage(){
        return null;
    }

}

代码块


import com.foreknow.test.exam1;

public class Test {
    public static void main(String[] args) {
        Mannger mannger=new Mannger();
        Emploree e1=new Emploree();
        e1.setId("1");
        e1.setName("lisa");
        e1.setSalary(1000.0);
        e1.setDepartment("ren");
        
        Emploree e2=new Emploree();
        e2.setId("2");
        e2.setName("lisa");
        e2.setSalary(1000.0);
        e2.setDepartment("ren");
        
        Emploree e3=new Emploree();
        e3.setId("3");
        e3.setName("lisa");
        e3.setSalary(1000.0);
        e3.setDepartment("ren");
        
        Emploree e4=new Emploree();
        e4.setId("4");
        e4.setName("lisa");
        e4.setSalary(1000.0);
        e4.setDepartment("ren");
        
        Emploree e5=new Emploree();
        e5.setId("5");
        e5.setName("lisa");
        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());
    }
    

}


你可能感兴趣的:(2019-07-29)