I'm making a DnD program to essentially just keep track of everything. I have three classes relevant to this problem, my main (which is just a hub to execute everything else), an Item class which holds all the properties of various individual items, and an InventoryList class which basically just defines an unholy load of items(this is a separate class because of the sheer number of items in 4e DnD). I had decided on making an Array of these Items, and calling that the users inventory; first off, is there a better way to do that -- i.e. using a HashMap or ArrayList? Second, I'm getting a classic "error, cannot find symbol" compiler error in the following code (shortened to relevance):
Main Method:
public class DnD {
public static void main (String[] args) throws FileNotFoundException, IOException {
. . .
Item[] myInventory = {Candle}; //error: symbol cannot be found
} //main()
} //DnD
Item Method:
public class Item {
. . .
public static Item Candle = new Item("Candle", 1, "Provides dim light for 2 squares, and lasts for 1 hour.");
public Item(String _name, double _price, String _desc) {
name = _name;
price = priceConverter(_price);
description = _desc;
} //Item()
} //Item
InventoryList Method:
public class InventoryList {
. . .
public InventoryList() {
// I have no idea where to proceed with this.
// Is there a way for me to use this to initialize ...
// ... an Array of Items in this method, to use in the main?
// The Item object stores name, price, and a description; ...
// ... is there a way to create an Array or similar to ...
// ... display all that information at once and hold it together?
}
}
I seem to be unable to summon Items in the main from the Item class. My Inventory (Item[]) is not working because of this.