Я пытаюсь создать объект Room, который использует методы getter и setter.Для каждой комнаты есть либо комната, либо комната (NULL) для N, E, W или S.
1) Каждый объект Room содержит ссылки на до четырех других объектов Room (N, E,W или S)
2) Метод toString () должен включать имя комнаты, описание комнаты и метод getExits ()
public class Room {
private String name;
private String description;
private Room north;
private Room east;
private Room west;
private Room south;
public Room(String name, String description) {
this.name = name;
this.description = description;
} //end Room constructor class
public String getName() {
this.name = name;
return this.name;
}
// public String getExits() {
// if()
// }
public Room getEast() {
if (this.east == null) {
return null;
}
return this.east;
}
public Room getNorth() {
if (this.north == null) {
return null;
}
return this.north;
}
public Room getWest() {
if (this.west == null) {
return null;
}
return this.west;
}
public Room getSouth() {
if (this.south == null) {
return null;
}
return this.south;
}
public void setExits(Room n, Room e, Room w, Room s) {
this.north = n;
this.east = e;
this.west = w;
this.south = s;
} //end setExits
public String toString() {
String nm;
nm = "["+name+"]"+"\n" +
description + "\n" +
getExits(); //need this method
return nm;
}
} // конец класса DungeonCrawl
#this is what I wan't my output to look like#
[Hall]
Its Dark.
[N]orth: Bed
[E]ast : Bath
[W]est : Dining