Created
June 2, 2015 19:37
-
-
Save rplugge/e048340d07a0e30c1d90 to your computer and use it in GitHub Desktop.
Day 2
This file contains 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
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