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
    关注

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮