Last active
August 29, 2015 14:22
-
-
Save rplugge/79530435e2b58144fe13 to your computer and use it in GitHub Desktop.
Day 3- Stretches
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 = {} | |
@history_hash = {} | |
member_array.each do |a| | |
member[a] = 0 | |
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) | |
total_split = dinner.total_split | |
one_person = dinner.total_cost | |
#Checking to see if one person is playing. | |
puts "Will one person be footing the entire bill?" | |
answer = gets.chomp.capitalize | |
if answer != "Yes" | |
attendees.each do |a| | |
member[a] = member[a] + total_split | |
end | |
else | |
puts "Who is paying?" | |
unlucky_person = gets.chomp | |
member[unlucky_person] += one_person | |
end | |
@member | |
end | |
#Need to store information. Maybe a hash (Key = resturaunt_name, value = who_went) | |
#Set's the key equal to the array of people who went. | |
def history(resturant_name, attendees) | |
@history_hash[resturant_name] = attendees | |
end | |
#Display history_hash | |
def history_hash_display | |
@history_hash | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment