Last active
March 12, 2016 19:15
-
-
Save ryaan-anthony/3b44e81d6c7c4573568e to your computer and use it in GitHub Desktop.
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 Booking | |
attr_reader :nights, :minibar_items, :room | |
def initialize nights, minibar_items, room | |
@nights = nights | |
@minibar_items = minibar_items | |
@room = room | |
end | |
def calculate_total_cost | |
"$#{calculate_room_charge + calculate_minibar_charges + calculate_parking_charges}" | |
end | |
def calculate_room_charge | |
nights * room.room_charge | |
end | |
def calculate_minibar_charges | |
minibar_items * room.minibar_charges | |
end | |
def calculate_parking_charges | |
nights * room.parking_charges | |
end | |
end | |
class Room | |
def room_charge | |
# handle error | |
end | |
def minibar_charges | |
# handle error | |
end | |
def parking_charges | |
# handle error | |
end | |
end | |
class NormalRoom < Room | |
def room_charge | |
50 | |
end | |
def minibar_charges | |
5 | |
end | |
def parking_charges | |
5 | |
end | |
end | |
class SuiteRoom < Room | |
def room_charge | |
90 | |
end | |
def minibar_charges | |
3 | |
end | |
def parking_charges | |
2 | |
end | |
end | |
room = NormalRoom.new | |
puts Booking.new(3, 2, room).calculate_total_cost | |
room = SuiteRoom.new | |
puts Booking.new(3, 2, room).calculate_total_cost |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment