Skip to content

Instantly share code, notes, and snippets.

@natepisarski
Created November 18, 2016 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natepisarski/e23a871363d340b5a5f38e1226ffeac0 to your computer and use it in GitHub Desktop.
Save natepisarski/e23a871363d340b5a5f38e1226ffeac0 to your computer and use it in GitHub Desktop.
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();    }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment