Hey guys :)
I'm making a code and testing it in drjava but at this stage there is just one function I am having trouble with. Here is my code so far
import java.util.ArrayList;
class Player
{
//instance fields, a name, a place, and an inventory
String name;
LocationID place;
ArrayList<ItemID> inventory;
//constructor function for creating a new player
//sets a name and a default location
Player(String playername)
{
name = playername;
place = LocationID.BEDROOM;
}
//an accessor method to return the location
LocationID location()
{
return place;
}
//another accessor method to return inventory
ArrayList<ItemID> tools()
{
return inventory;
}
//a mutator method to add an item to the inventory
void addItem(ItemID item)
{
inventory.add(item);
}
//location and item data types
enum LocationID { PATH, PORCH, LIVING, BEDROOM}
enum ItemID { KNIFE, ROPE, LANTARN, AMULET}
}
here is the output of what happens when i, create a new player, test out the accessor functions and the problem happens when i try and use the mutator...
> Player j = new Player ("Jonathan")
> j.location()
BEDROOM
> j.tools()
null
> j.addItem(ROPE)
Static Error: Undefined name 'ROPE'
>
I'm sorry if this is a stupid question I'm still learning the very basics unfortunately