java 部门列表_员工表及员工部门表的简单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

System.out.println(dept1.getId()[i].getInfo());

}

boolean b = dept1.Compare(dept2);

System.out.println(b);

}

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值