简单类(进阶)

package javac;
class Dept{
    private String name;
    private String num;
    private Emp[] emps;
    private Emp mgr;
    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return name;
    }
    public Dept(String name,String num){
        this.name=name;
        this.num=num;

    }
    public String getDeptInfo(){
        return this.name+this.num;
    }
    public Emp[] getEmps() {
        return emps;
    }
    public void setEmps(Emp []emps) {
        this.emps = emps;
    }
    public Emp getMgr() {
        return mgr;
    }
    public void setMgr(Emp mgr) {
        this.mgr = mgr;
    }
}
class Emp{
    private int id;
    private String name;
    private int age;
    private String post;
    private Dept dept;
    private Emp mgr;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public Emp(String name,int id,int age,String post){
        this.name=name;
        this.age=age;
        this.id=id;
        this.post=post;

    }
    public String getEmpInfo(){
        return name+id+age+post;
    }
    public Dept getDept() {
        return dept;
    }
    public void setDept(Dept dept) {
        this.dept = dept;
    }
    public Emp getMgr() {
        return mgr;
    }
    public void setMgr(Emp mgr) {
        this.mgr = mgr;
    }
    public String getPost() {
        return post;
    }
    public void setPost(String post) {
        this.post = post;
    }
}
public class biao {
    public static void main(String args[]){
        Emp ea=new Emp("zhangsan",001,10,"员工");
        Emp eb=new Emp("lisi",002,10,"经理");
        Dept dept=new Dept("bmw","001");
        ea.setDept(dept);
        eb.setDept(dept);
        ea.setMgr(eb);
        dept.setMgr(eb);
        dept.setEmps(new Emp[]{
                ea,eb
        });
        System.out.println(dept.getDeptInfo());
        for(int x=0;x<dept.getEmps().length;x++){
        {



        System.out.println("\t"+dept.getEmps()[x].getEmpInfo());
        if(dept.getEmps()[x].getMgr()!=null)
        System.out.println("\t\t"+dept.getEmps()[x].getMgr().getEmpInfo());

    }
        }
        System.out.println("*****************************");
        System.out.println(dept.getMgr().getEmpInfo());

        System.out.println("*****************************");
        System.out.println(ea.getDept().getDeptInfo());
        System.out.println(ea.getMgr().getEmpInfo());


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值