fork download
  1. public class Item
  2. {
  3. /** Name is the first part of the item. Ex. Long Bow */
  4. private String name;
  5. private String type;
  6.  
  7. /**
  8.   * Defines what an item object is.
  9.   * @param name of item.
  10.   */
  11. public Item(String name, String type)
  12. {
  13. this.name = name;
  14. this.type = type;
  15. }
  16.  
  17. public int getItemSize()
  18. {
  19. switch(type)
  20. {
  21. case "Ring": return 1;
  22. case "Amulet": return 1;
  23. case "Helm": return 4;
  24. case "Body Armor": return 6;
  25. case "Boots": return 4;
  26. case "Belt": return 2;
  27. case "Gloves": return 4;
  28. default: Other.myHashTable.get(name);
  29. }
  30. }
  31.  
  32. public String getName()
  33. {
  34. return name;
  35. }
  36. }
  37.  
  38. public class other
  39. {
  40. public static HashTable<String, Integer> myHashTable = new HashTable<>();
  41.  
  42. public static void main(String[] args)
  43. {
  44. // Add all the data into the HashTable.
  45.  
  46. Item bigSword = new Item("Big Sword", "Weapon");
  47.  
  48. System.out.println("The size of this weapon is: " + bigSword.getItemSize());
  49. }
  50. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class Item is public, should be declared in a file named Item.java
public class Item
       ^
Main.java:38: error: class other is public, should be declared in a file named other.java
public class other
       ^
Main.java:40: error: cannot find symbol
	public static HashTable<String, Integer> myHashTable = new HashTable<>();
	              ^
  symbol:   class HashTable
  location: class other
Main.java:28: error: package Other does not exist
        	default: Other.myHashTable.get(name);
        	              ^
Main.java:40: error: cannot find symbol
	public static HashTable<String, Integer> myHashTable = new HashTable<>();
	                                                           ^
  symbol:   class HashTable
  location: class other
5 errors
stdout
Standard output is empty