Created
November 18, 2013 19:32
-
-
Save justuseapen/7533888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
class Product | |
@@all = [] | |
def initialize (item, price) | |
@item = item | |
@price = price | |
end | |
def price | |
@price | |
end | |
def name | |
@item | |
end | |
def self.create(name, price) | |
product = Product.new(name, price) | |
@@all << product | |
product | |
end | |
def self.all | |
@@all | |
end | |
end | |
def inventory | |
name = "go" | |
while name != "" do | |
puts "Enter product name (leave blank to continue):" | |
name = gets.chomp | |
if name != "" | |
puts "Enter product price:" | |
price = gets.chomp | |
Product.create(name, price) | |
end | |
end | |
total | |
end | |
$amount_due = 0.0 | |
def total | |
Product.all.each do |product| | |
puts "How many #{product.name}s would the customer like?" | |
quantity = gets.chomp.to_f | |
item_total = quantity * product.price.to_f | |
$amount_due = $amount_due + item_total | |
end | |
end | |
def transaction | |
puts "The customer owes you $#{"%.2f" % $amount_due}." | |
puts "How much money did the customer give you?" | |
tendered = gets.chomp.to_f | |
if tendered >= $amount_due | |
change = tendered-$amount_due | |
change = change.to_f | |
puts "Please return $#{"%.2f" % change} in change to the customer." | |
else | |
"The customer did not give you enough cash." | |
end | |
end | |
inventory | |
transaction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment