员工表及员工部门表的简单java类
今天课上学习了简单java类的学习
现将自己练习的员工表及员工部门表的简单java类整理如下
员工类
public class Semp {
    //定义私有属性
	private int sid;
    private String firstname;
    private String title;
    private Dept   deptid;
    private double salary;
    //无参构造
    public Semp(){
    	
    }
    public Semp(int sid,String firstname,String title,double salary){
    	this.sid=sid;
    	this.firstname=firstname;
    	this.title=title;
    	this.salary=salary;
    }
    //设置setter getter方法
    public void setSid(int sid){
    	this.sid=sid;
    }
    public int getSid(){
    	return this.sid;
    }
    public void setFirstname(String firstname){
    	this.firstname=firstname;
    }
    public String getFirstname(){
    	return this.firstname;
    }
    public void setTitle(String title){
    	this.title=title;
    }
    public String getTitle(){
    	return this.title;
    }
    public void setDeptid(Dept deptid){
    	this.deptid=deptid;
    }
    public Dept getDeptid(){
    	return this.deptid;
    }
    public void setSalary(double salary){
    	this.salary=salary;
    }
    public double getSalary(){
    	return this.salary;
    }
    //获得所有属性的方法
    public String getInfo(){
    	return "员工编号"+this.sid+",姓氏"+this.firstname+",职位"+this.title+",工资"+this.salary;
    }
}
部门类
class Dept{
	private Semp[] id;
	private String deptname;
	private int rid;
	public Dept(){
		
	}
	public Dept(String deptname,int rid){
		this.deptname=deptname;
		this.rid=rid;
	}
	public void setId(Semp[] id){
		this.id=id;
	}
	public Semp[] getId(){
		return this.id;
	}
	public String getDeptname(){
		return this.deptname;
	}
	public int getRid(){
		return this.rid;
	}
    public boolean Compare(Dept dept){
    	if(dept==null){
    		return false;
    	}
    	if(this==dept){
    		return true;
    	}
    	if(this.rid==dept.rid && this.getDeptname().equals(dept.getDeptname())){
    		return true;
    	}
    	return false;
    }
	public String getInfo(){
		return "部门名称"+deptname+",部门地址编号"+rid;
	}
}
测试主类
public class Test {
 public static void main(String[] args) {
        Semp semp1 = new Semp(1001,"张三","销售员",2500);
        Semp semp2 = new Semp(1002,"李四","运营助理",4000);
        Semp semp3 = new Semp(1003,"王五","销售员",3000);
        Dept dept1 = new Dept("销售部",01);
        Dept dept2 = new Dept("运营部",02);
        semp1.setDeptid(dept1);
        semp2.setDeptid(dept2);
        semp3.setDeptid(dept1);
        dept1.setId(new Semp[]{semp1,semp3});
        dept2.setId(new Semp[]{semp2});
        System.out.println(dept1.getInfo());
        System.out.println(semp2.getDeptid().getInfo());
        for(int i=0;i<dept1.getId().length;i++){
        	System.out.println(dept1.getId()[i].getInfo());
        }
        boolean b = dept1.Compare(dept2);
        System.out.println(b);
        
        
        
	}
}
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号