如何连接这两个课程?

时间:2019-11-17 16:24:03

标签: java

如何将这两个课程与其他课程联系起来,以便在课程1出现“ 17-0.10”?

第1类:

    public class Main { 
        public static int String(int room){

     }

    public static void main(String[] args) {
        Room office = new Room(17, 0, 10);
        Room lecture = new Room(2, 0, 10);
        Room lab = new Room(18, 1, 1);

        System.out.println(office);  // => "17-0.10"
        System.out.println(lecture); // => " 2-0.10"
        System.out.println(lab);     // => "18-1.01"
    }
}

第2类:

public class Room {
    public int gebaeude;
    public int etage;
    public int raumnummer;

public Room(int gb, int eg, int rn) {
    this.gebaeude = gb;
    this.etage = eg;
    this.raumnummer = rn;
    }

public String toString() {
    return this.gebaeude + "-" + this.etage + "." + this.raumnummer;
}
}

如果您要问,我写了Class 2和“ public static int String(int room)”,这是Java的新手,我首先尝试的只是System.out.println(Room);

1 个答案:

答案 0 :(得分:0)

在您的代码中,只需删除Main类中的String()方法。其他一切都很好。