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 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝