qq_34791054 2016-04-30 17:30 采纳率: 0%
浏览 1309

Java初学一枚 一个小程序 求有人帮我看看

package malnAV;

public class Work3_3 {
public static void main(String[] args) { //???
//方法 main 不能声明为“静态”;只能在静态类型或顶级类型中才能声明静态方法
Emp e1=new Emp(001,"张三");
Emp e2=new Emp(002,"李四");
Emp e3=new Emp(003,"王五");
Doc d1=new Doc(001,"会计");
e1.setMino(e3);
e2.setMino(e3);//e3为e1,e2的领导
e1.setDoc(d1);
e2.setDoc(d1);
e3.setDoc(d1);//e1,e2,e3同属d1部门
d1.setEmp(new Emp[]{e1,e2,e3});
System.out.println(e1.tell());
System.out.println(e2.tell());
System.out.println(e3.tell());
}
}
class Emp{//雇员
private int no ;
private String name;
private Emp mgr;
private Doc doc;
public Emp(){

}
public Emp(int no,String name){
    this.no=no;
    this.name=name;
}
public int getNo() {
    return no;
}
public void setNo(int no) {
    this.no = no;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public Emp getMino() {
    return mgr;
}
public void setMino(Emp mino) {
    this.mgr = mino;
}
public Doc getDoc() {
    return doc;
}
public void setDoc(Doc doc) {
    this.doc = doc;
}
public String tell(){
    if(this.mgr.getName()!=null){
        return "雇员编号:"+this.no+",姓名:"+this.name+",领导:"
        +this.mgr.getName()+",部门:"+this.doc.getName();
}
    else{
        return "雇员编号:"+this.no+",姓名:"+this.name+",部门:"+this.doc.getName();
    }

}

class Doc{//部门
private int no;
private String name;
private Emp []emp;
public Doc(){

}
public Doc(int no,String name){
    this.no=no;
    this.name=name;
}
public int getNo() {
    return no;
}
public void setNo(int no) {
    this.no = no;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public Emp[] getEmp() {
    return emp;
}
public void setEmp(Emp[] emp) {
    this.emp = emp;
}
public String tell(){
    return this.no+"部门"+this.name+"部";
}

}

  • 写回答

5条回答

  • weixin_34847036 2016-04-30 18:20
    关注

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作