Created
November 18, 2016 00:24
Revisions
-
natepisarski created this gist
Nov 18, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ public class TreasureChest{ private ArrayList<Bag> myChest; //An arraylist, representing many objects of Bag public TreasureChest(Bag .. bags) //Take multivariate bag arguments { myChest = new ArrayList<>(); bags.forEach(x -> myChest.add(x)); } public int getTotal() { myChest.map(x -> x.getValue()).reduce(0, (x, y) -> x + y); } public boolean hasType(String type) //Searches each bag for a specific substring, a part of the String { for(Bag bag : myChest) if(bag.getDescription().contains(type)) return true; return false; } public int getNumBags(String description) //Searches for specific bags, counts how many there are { return myChest.filter(x -> x.getDescription().equals(description)).length() } public int getSpecialItems(String description) //Looks for item within Bag { return myChest.filter(x -> x.getDescription().contains(description)).length(); }}