Last active
August 29, 2015 14:22
-
-
Save rplugge/0db22aa3948288fb3a77 to your computer and use it in GitHub Desktop.
Random Help - 06-04
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 | |
#writing a getter method | |
attr_reader :meal_cost, :tip_percentage, :number_of_people | |
def initialize(meal_cost, tip_percentage, number_of_people) | |
@meal_cost = meal_cost.to_f | |
@tip_percentage = tip_percentage.to_f | |
@number_of_people = number_of_people.to_i | |
end | |
#figures out tip amount, also converts tip % to decimal. | |
def tip | |
meal_cost * (tip_percentage / 100.0) | |
end | |
#adds tip amount to meal_cost | |
def total_cost | |
meal_cost + tip | |
end | |
#total amount per person after split | |
def total_split | |
total_cost / number_of_people | |
end | |
end | |
class Dinnerclub | |
attr_reader :member | |
#Turns input member array into hash with value of 0 | |
def initialize(member_array) | |
@member = {} | |
member_array.each do |a| | |
member[a] = [] | |
end | |
end | |
#Method for going out to eat | |
# First creates a new checksplitter with the information provided | |
# Finds the total_split per person | |
# Adds the total_split to the hash | |
def going_out(meal_cost, tip_percentage, attendees) | |
dinner = Checksplitter.new(meal_cost, tip_percentage, attendees.length) | |
@split_attendees = attendees | |
@total_split = dinner.total_split | |
@one_person = dinner.total_cost | |
end | |
# - My problem here is that when I run this method multiple times, it overwrixtes the previous one. | |
# | |
# | |
def event(name_of_place, attendees, cost) | |
@name_of_place = name_of_place | |
@attendees = attendees | |
@cost = @total_split | |
attendees.each do |a| | |
member[a].push({@name_of_place => @total_split}) | |
end | |
end | |
end | |
my_group = ["Rob", "Amber", "Zach"] | |
day1 = ["Rob", "Amber"] | |
day2 = ["Rob", "Zach"] | |
my_club = Dinnerclub.new(my_group) | |
my_club.going_out(20, 20, day1) | |
my_club.event("McDonalds", day1, 20) | |
my_club.event("Wendy's", day2, 30) | |
p my_club.member | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment