Skip to content

Instantly share code, notes, and snippets.

@rplugge
Created June 2, 2015 19:37
Show Gist options
  • Save rplugge/e048340d07a0e30c1d90 to your computer and use it in GitHub Desktop.
Save rplugge/e048340d07a0e30c1d90 to your computer and use it in GitHub Desktop.
Day 2
class Checksplitter
def initialize(total_cost, people_number, tip_percent)
@total_cost = total_cost.to_f
@people_number = people_number.to_i
@tip_percent = tip_percent.to_f
end
def people_number
@people_number
end
def total_cost
@total_cost
end
def tip
total_cost * @tip_percent
end
def before_split
total_cost + tip
end
def cost_person
before_split / people_number
end
def output
puts "Dinner is $#{cost_person.round(2)} per person."
end
end
class Dinnerclub
def initialize(names)
@name_array = names
@name_and_paid = Hash.new(0)
names.each do |name|
@name_and_paid[name] = 0
end
end
def name_and_paid
@name_and_paid
end
def name_array
@name_array
end
def cost_per_person
Checksplitter.cost_person
end
def total
name_and_paid.each do |x, y|
y += cost_per_person
end
end
end
people_array = ["Rob", "Amber", "Chris"]
my_club = Dinnerclub.new(people_array)
dinner = Checksplitter.new(20, 4, 0.85)
puts my_club.name_and_paid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment