forked from ACSmithinNC/Inventory-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory_application.rb
More file actions
38 lines (30 loc) · 886 Bytes
/
inventory_application.rb
File metadata and controls
38 lines (30 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Inventory_item = {
"Asparagus" => 3.29,
"Carrots" => 2.99,
"Squash" => 2.59
}
Inventory_item.each do |name, price|
puts "#{name}: $#{price}"
end
# class Inventory_item
# attr_accessor :name
# attr_accessor :price
# attr_accessor :quantity
# def initialize(name, price, quantity)
# @name = name
# @price = price
# @quantity = quantity
# end
# end
# def to_s
# result = sprintf("%s: $%.2f (%d)", @name, @price, @quantity)
# return result
# end
# asparagus = Inventory_item.new("Asparagus", 3.29, 100)
# carrots = Inventory_item.new("Carrots", 2.99, 50)
# squash = Inventory_item.new("Squash", 2.59, 60)
# total_value = asparagus.price * asparagus.quantity +
# carrots.price * carrots.quantity +
# squash.price * squash.quantity
# printf("The inventory has a total value of $%.2f\n",
# total_value)