import java.util.*; // for ArrayList public class Treasure { private ArrayList list; public Treasure() // no-arg constructor { list=new ArrayList<>(); } public Treasure(ArrayList l) { list=l; } // accessor public ArrayList getTreasure() { return list; } public void addTreasure(ArrayList list2) // Fighter obtains another Fighter's Treasure to add { System.out.println("Taking " + list2); list.addAll(list2); } // determines if Fighter's Treasure contains a potion and if so, removes it from the list for use by the Fighter public boolean usePotion() { boolean temp=list.contains("potion"); if(temp) list.remove("potion"); return temp; } // determines if Fighter's Treasure contains a scroll and if so, removes it from the list for use by the Fighter public boolean useScroll() { boolean temp=list.contains("scroll"); if(temp) list.remove("scroll"); return temp; } // return the contents of the Treasure list by calling computeWorth public String toString() { return computeWorth(); } // Lists the contents of the Treasure as a total of each type public String computeWorth() { int gold=0, silver=0, potions=0, scrolls=0; for(String temp:list) { if(temp.equals("gold")) gold++; if(temp.equals("silver")) silver++; if(temp.equals("potion")) potions++; if(temp.equals("scroll")) scrolls++; } return "Treasure contains: " + gold + " gold pieces\t" + silver + " silver pieces\t" + potions + " potions\t" + scrolls + " scrolls"; } }