Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ Remember: Your job is to only build the classes that store information and handl
#### User Stories

- As a user of the hotel system...
- I can access the list of all of the rooms in the hotel
- I can access the list of all of the rooms in the hotel
GIVEN the user is a front desk hotel worker
THEN create a method that allows them to get a list of all rooms in the hotel
- I can make a reservation of a room for a given date range
- I can access the list of reservations for a specific date, so that I can track reservations by date
- I can get the total cost for a given reservation
Expand Down
93 changes: 93 additions & 0 deletions design-activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

-What classes does each implementation include? Are the lists the same?

Each implementation has the exact same classes and the lists are exactly the same, but each one uses the classes completely differently.

-Write down a sentence to describe each class?

Implementation A:

Class CartEntry: Allows you to set and get each cart entry price and entry quantity with an accessor method.

Class ShoppingCart: Lets you get and set shopping cart list into an array.

Class Order: It calculates total price of shopping cart by creating a Shopping Cart object and setting it to @cart instance variable.

Implementation B:

Class CartEntry: It initializes passed in unit price and quantity and then has a method to calculate the price for that cart entry.

Class ShoppingCart: It initializes a shopping cart with an array of entries and has a method to calculate total cost for the shopping cart by calling on price method for each entry from class CartEntry.

Class Order: Initializes @cart with a ShoppingCart object with has total price for shopping and adds in sales tax with the total price method.

-How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper.

Implementation A:

In this implementation class Order depends on ShoppingCart Class to retrieve an array of product entries. Upon initialization Class Order instantiates a Shopping Cart object to get the shopping cart and stores them in @cart. To calculate total price it loops through ShoppingCart array and calls on each entries for it's price and quantity which is available for each cart entry from Class CartEntry.

Implementation B:

Unlike the first implementation each cart entries price is calculated in Class CartEntry. Then ShoppingCart class holds an array of entries and calculates price for the entire Shopping cart. Lastly, order creates an instance of ShoppingCart class and calculates the total price by adding on tax.

-What data does each class store? How (if at all) does this differ between the two implementations?

Implementation A:

class CartEntry: It stores unit price and quantity of an entry.

class ShoppingCart: Stores and array of entries.

Class Order: calculates total price and includes taxes, but doesn't store anything.

Implementation B:

Class CartEntry: It stores unit_price and quantity for each entry.

Class ShoppingCart: It stores and array of entries.

Class Order: it doesn't store anything it calculates total price to include sales tax.

Comparing both:
They don't differ in their storage of data. They pretty much store the same type of information in each class.They differ in the way they depend on each-other for different things.

-Consider the Order#total_price method. In each implementation: Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order?

Implementation A: It is retained in Order. In this implementation the total_price method does everything.

Implementation B: In this implementation is delated to lower classes and it just calculates the sales Tax in the method.

-Does total_price directly manipulate the instance variables of other classes?

In implementation A it does manipulate the instance variables of other classes because it goes through each and every since entry and calls for the unit price and quantity and multiplies them together. In implementation B it simply calls on Shopping cart for the price and adds on the sales Tax. It never touches any of the other classes instance variables.

-If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify?

You would have to change the class CartEntry to include this feature, but it would be really hard to change it in Implementation A because you would have to also change the order Class and not just CartEntry Class.

-Which implementation better adheres to the single responsibility principle?

Implementation B, better adheres the single responsibility principle because each class is responsible for exactly one thing.

-Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?


Hotel Project:
For each class in your program, ask yourself the following questions:

What is this class's responsibility?
You should be able to describe it in a single sentence.
Is this class responsible for exactly one thing?
Does this class take on any responsibility that should be delegated to "lower level" classes?
Is there code in other classes that directly manipulates this class's instance variables?



DateRange: creates a date range given a start date and end-date and validates it, it also checks for overlap, and calculates total number of nights stayed.

Reservation: using DateRange object it tally's the cost for a particular room.

Concierge: Is in charge of making reservations for the first available given DateRange.


38 changes: 38 additions & 0 deletions design-scaffolding-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Hotel Design Scaffolding

## Purpose

This scaffolding is intended for students who are feeling overwhelmed by the open-ended nature of the Hotel project. Its goal is to answer some of the initial questions about how project files should be laid out, so that students can focus on designing the object interactions and complex Ruby logic that are the core learning goals of the project. The hope is to do so without removing too much of the interesting design work.

This document and the associated code is intended to be student-facing - if you have a student you think would benefit from this, send them a link!

### What it includes

- Three class stubs, `HotelController`, `Reservation` and `DateRange`
- Stubs for public methods of each class from waves 1 and 2, as described in the user stories
- "Interface" tests for each class method that invoke it with the right parameters and verify the return type
- Full test stubs for the `DateRange` class

### What it does not include

- Opinions about how classes should interact or data should be stored
- Opinions about whether there should be a `Room` class, or whether it should know about `Reservation`s
- Private helper methods to keep code organized

Students should feel free to modify any code as they see fit, including changing method signatures, adding new classes and methods, reordering things, not looking at the `DateRange` tests because they want to give it a shot on their own, etc.

## How to use this code

Design scaffolding code lives on the `design-scaffolding` branch.

You can use this code either as inspiration, or as a starting point. If using it as an inspiration, it follows our standard project layout, with product code under `lib/` and tests under `spec/`.

If you choose to use the code on this branch as a starting point, follow these steps to start your project:

```
$ git clone <paste forked repo URL>
$ cd hotel
$ git merge origin/design-scaffolding
```

You can try to merge in the design scaffolding after you've started, but you'll probably end up with merge conflicts. See an instructor if you're not able to resolve them yourself.
54 changes: 54 additions & 0 deletions lib/concierge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Hotel
class Concierge
attr_reader :rooms, :reservations

# Wave 1
def initialize(rooms = (1..20).to_a)
@rooms = rooms
@reservations = []
end

def reserve_room(start_date, end_date)
rooms = available_rooms(start_date, end_date)
if rooms.empty?
raise StandardError.new "No rooms available #{start_date} through #{end_date} "
end
res = Reservation.new(start_date, end_date, rooms.first)
# if res.start_date.instance_of?(Date) false && res.end_date.instance_of?(Date) false
# raise StandardError.new "Invalid date"
# end
@reservations << res
# start_date and end_date should be instances of Date
return res
end

def find_reservations(date)
specific_date_reservations = []
@reservations.each do |reservation|
if reservation.date_range.include?(date)
specific_date_reservations << reservation
end
end
return specific_date_reservations
end

# Wave 2
def available_rooms(start_date, end_date)
conflicting = []
@reservations.each do |reservation|
if reservation.date_range.overlap?(DateRange.new(start_date, end_date))
conflicting << reservation.room
end
end
open_rooms = []
rooms.each do |room|
unless conflicting.include?(room)
open_rooms << room
end
end
return open_rooms
end
end
end


40 changes: 40 additions & 0 deletions lib/date_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Hotel
class DateRange
attr_accessor :start_date, :end_date

def initialize(start_date, end_date)
self.class.validate_date(start_date, end_date)
@start_date = start_date
@end_date = end_date
end

def self.validate_date(start_date, end_date)
number_of_days = (end_date - start_date).to_i
puts number_of_days

if start_date.nil? || end_date.nil?
raise ArgumentError.new('Invalid no Start and/or End Date given')
elsif start_date == end_date
raise ArgumentError.new('Invalid Start and/or End Date')
elsif number_of_days < 0
raise ArgumentError.new('Invalid, end date cant be before start date')
end
end

#finish this:
def overlap?(other_range)
if self.start_date == other_range.start_date && self.end_date == other_range.end_date
return true
elsif other_range.start_date >= self.start_date && other_range.end_date >= end_date
return true
else
return false
end
end

def nights
total_nights = (end_date - start_date).to_i
return total_nights
end
end
end
17 changes: 17 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Hotel
class Reservation
attr_reader :date_range, :room

#I don't need to have start and end date in initialize becuase that would be bad design.
#start and end dates are already saved in date-range.
def initialize(start_date, end_date, room)
@date_range = DateRange.new(start_date, end_date)
@room = room
end

def cost
total_cost = date_range.nights * 200
return total_cost
end
end
end
46 changes: 46 additions & 0 deletions test/concierge_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require_relative "test_helper"

describe Hotel::Concierge do
#What does @concierge do in this test at beginning? I don't understand is it creating a new
#Concierge obj
before do
@concierge = Hotel::Concierge.new
@date = Date.parse("2020-08-04")
end
describe "Wave 1" do
describe "rooms" do
it "returns a list of rooms" do
rooms = @concierge.rooms
expect(rooms).must_be_kind_of Array
end
end
describe "reserve_room" do
it "takes two Date objects and returns a Reservation" do
start_date = @date
end_date = start_date + 3
@reservation = @concierge.reserve_room(start_date, end_date)
expect(@reservation).must_be_kind_of Hotel::Reservation
end
end
describe "find_reservations" do
it "takes a Date and returns a list of Reservations" do
reservation_list = @concierge.find_reservations(@date)

expect(reservation_list).must_be_kind_of Array
reservation_list.each do |res|
res.must_be_kind_of Reservation
end
end
end
end
describe "Wave 2" do
describe "available_rooms" do
it "takes two dates and returns a list" do
start_date = @date
end_date = start_date + 3
room_list = @concierge.available_rooms(start_date, end_date)
expect(room_list).must_be_kind_of Array
end
end
end
end
Loading