我无法弄清楚getExits()需要什么才能获得问题请求的输出。
//构造函数
public class Room {
private String name;
private String description;
private Room north;
private Room east;
private Room south;
private Room west;
public Room (String name, String description){
this.name = name;
this.description = description;
}
public Room getEast(){
return this.east;
}
public String getExits (){
//
}
public String getName(){
return this.name;
}
public Room getNorth(){
return this.north;
}
public Room getWest(){
return this.west;
}
public Room getSouth(){
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;
}
public String toString(){
return String.format("%s\n%s\n%s", this.name, this.description,getExits());
}
}
//主要方法
public class Tester{
public static void main(String []args){
Room hall = new Room ("Hall", "It's Dark");
Room bed = new Room ("Bed", "Tiny Room");
Room bath = new Room ("Bath", "Toilets here");
Room dine = new Room ("Dine", "Table and chairs");
hall.setExits(bed, bath, dine, null);
System.out.println(hall);
}
}
预期输出:
Hall
It's Dark
North: Dine
East: Bath
West: Dining
繁花不似锦
ITMISS
冉冉说
相关分类