Skip to content

Instantly share code, notes, and snippets.

@natepisarski
Created November 18, 2016 00:24

Revisions

  1. natepisarski created this gist Nov 18, 2016.
    1 change: 1 addition & 0 deletions treasurechest.java
    Original 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();    }}