Guest User

Untitled

a guest
Aug 22nd, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.51 KB | None | 0 0
  1. class ShoppingCart
  2.     attr_accessor :id, :contents, :total
  3.     def initialize
  4.         @id = 0
  5.         @contents = []
  6.         @total = 0
  7.     end
  8.  
  9.     def add_item(item)
  10.         @contents.push(item)
  11.  
  12.     end
  13.  
  14.     def calculate_total
  15.         for item in @contents
  16.             @total += item.price
  17.         end
  18.         @total
  19.     end
  20.  
  21. end
  22.  
  23. class Item
  24.     attr_accessor :id, :name, :price
  25.     def initialize(id, name, price)
  26.         @id = id
  27.         @name = name
  28.         @price = price
  29.     end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment