class Cart
  attr_reader :purchases
  attr_reader :price

  def initialize
     @purchases = []
     @price = 0.0
  end

  def clear
     @purchases = []
     @price = 0.0
  end

  def add_purchase(item)
    appendFlag = true
    for purchase in @purchases
      if (item.id == purchase.item.id)
        appendFlag = false
        purchase.quantity += 1
      end
    end

    if(appendFlag)
      @purchases << Purchase.create_from(item)
    end

    @price += item.price
  end

end
