学校のプロジェクト用に独自のレジストリを作成する必要があります。
私はを頂きたい
1
room, room
2
room, room
hall, hall
3
room, room
hall, hall
dorm, dorm
しかし、私が得ているのは
1
room,room
2
room,hall
hall,hall
3
room,dorm
hall,dorm
dorm,dorm
どういうわけか、施設の参照がどこかで変更されましたが、これを修正する方法がわかりません。誰でも助けることができますか?
これらは私のコードです。
public class registry {
static List<registryRecord> register = new ArrayList<registryRecord>();
public static boolean bind(String name, facility ref){
for(registryRecord r:register){
if(r.name.equals(name)) //check if the name is already binded
return false;
}
registryRecord newRecord = new registryRecord(name, ref);
register.add(newRecord);
for (registryRecord r:register){
System.out.println(r.name +","+ r.ref.name);
}
return true;
}
public class registryRecord {
String name;
facility ref;
public registryRecord(String name, facility ref){
this.name = name;
this.ref = ref;
}
public class server {
public static void main(String args[]) throws Exception{
facility room = new facility("room");
System.out.println(1);
boolean test = registry.bind("room", room);
facility hall = new facility("hall");
System.out.println(2);
boolean test2 = registry.bind("hall", hall);
facility dorm = new facility("dorm");
System.out.println(3);
registry.bind("dorm", dorm);
}
public class facility {
public static String name;
static List<booking> bookings;
public facility(String name){
this.name=name;
this.bookings = new ArrayList<booking>();
}
}