Complicated problem between classes
I have a Room class as follows:
Code:
[SIZE="1"]
import java.util.*;
import java.util.Set;
public class Room
{
private String description;
private HashMap<String, Room> exits;
private ArrayList<Item> items;
private HashMap<String,items> rItem;
public Room (String description)
{
this.description=description;
exits=new HashMap<String, Room>();
items=new ArrayList<Item>();
rItem=new Hashmap<String,items>();
}
public void setExits(Room north, Room east, Room south, Room west)
{
if (north!=null)
exits.put("north", north);
if(east !=null)
exits.put("east",east);
if(south!=null)
exits.put("south",south);
if(west!=null)
exits.put("west",west);
}
public Room getExit(String direction)
{
return exits.get(direction);
}
public void setExit(String direction, Room neighbor){
exits.put(direction, neighbor);
}
public String getDescription()
{
return description;
}
public String getExitString(){
Set<String>keys=exits.keySet();
String r="";
for (String key: keys){
String rt=exits.get(key).getDescription();
r+= " " + rt;
}
return r;
}
public String gld(){
return ("" + description.toString() + getExitString());
}
}
public class Item
{
private int weight;
private String desc;
public Item()
{
weight=0;
desc="";
}
public int getWeight()
{
// put your code here
return weight;
}
public String desc(){
return desc;
}
}
[/SIZE]
The task is to be able to add items to each room. ie
Create an Item class
Add several items to each room
Unlimited number of items is said to be addable to each Room
Item type must be uncoupled from room so two rooms can have the same item if needed
Exercise suggests that I used a collection in the room class, I was thinking hashmap(String,items) where items is an ArrayList of Item
Here is the code but I get compile time error:
"Cannot find symbol class items"