$40
HOMEWORK TERM PROJECT
OBJECTIVE: Get some experience working with several design patterns at once.
INTRODUCTION: Please remember the coding standards here.
Quite often you will need to use more than one design pattern in the same
application. For this assignment you will build an application that simulates a
sleazy establishment called the Roach Motel. The design patterns that you will
use are:
• Singleton
• Decorator
• Factory
• Observer
• Strategy
• Visitor
The requirements are:
• There will only be one roach motel. When you create the motel, you
specify the capacity which is the number of rooms and the name of the
motel.
• When the motel is full, turn on the “No Vacancy” sign. Otherwise, the
“Vacancy” sign should be shown.
• Each of the rooms start out at a base rate, but when the customer checks
in, they can opt for various amenities.
o A food bar – add $10 per night
o A spa – add $20 per night
o Auto refill of the food bar – add $5 per night
o Spray resistant shower – add $25 per night.
▪ The spray resistant shower comes in handy when an
exterminator comes through.
• Each customer is an entire roach colony. The colony has:
o A name
o An initial population (how many roaches in the colony)
o The growth rate
• Roaches are fond of throwing parties. Every time they throw a party, the
number of occupants in the room increases by the growth rate.
o Whenever the roaches throw a party, management responds by
spraying the room.
▪ If the room has a spray resistant shower, the roach
population only loses 25% of its members.
▪ If the room does not have the spray resistant shower, the
roach population loses fully 50% of its members.
• If a Customer (roach colony) tries to check in and the hotel is full, the
Customer gets waitlisted.
CECS 277 Homework Term Project.docx 12/1/2019 6:15:00 PM 2
CECS 277 HOMEWORK TERM PROJECT
• When the Customer checks out, they get charged the room rate
(including all of the amenities) times the number of days that they stayed.
The room then becomes available.
o Any Customers who are on the waitlist get notified that there is
a vacancy.
• When the colony receives the notification, they display a message that
they received the notification and the name of the Roach Motel that sent
it.
• When a colony checks out of the motel, they will either use RoachPal or
their MasterRoach credit card to pay the bill. Roach Pay requires the
name and email of the colony paying the bill. The MasterRoach credit
card requires a name, a security code, a card number and an expiration
date.
• All payments made will be written to a transaction log. This log will
contain the name of the colony, the type of payment made and the
amount.
• You will need a method to display the contents of the transaction log
before you exit the program.
• The motel is very concerned with cleanliness. Every day the maid staff
cleans each of the rooms. The different types of rooms are cleaned
differently:
o All rooms have their linens changed on every bed.
o For the basic room, only towels that are on the floor are replaced.
o For the deluxe room, all towels are changed.
o For the suite, all towels are changed and there is a hamburger
placed on each pillow.
• However, if the room has put out the "Do Not Disturb" sign, the room will
not be cleaned.
PROCEDURE:
1. Look through the description and figure out what design pattern seems to fit the circumstances
best.
a. Singleton supports a single instance of a class. In the above description the roach motel
fits that requirement.
b. The challenge with the pricing here is that the price is impacted by all of the amenities
that the roach colony opts to include. That should remind you of Starbuzz coffee and the
different toppings that you can order for your coffee.
c. Remember that we talked about the Abstract Factory pattern as a two-step process:
create an instance of the FactoryProvider, then use the factory that it provides you to
create object. In our case it was Geometric Objects that came in those two different
families of object. In this case, we’re going to use a dumbed down version of that, and
just create an instance of Room, based on the room type, sort of like the Factory Provider,
except there is no intermediate factory involved.
CECS 277 Homework Term Project.docx 12/1/2019 6:15:00 PM 3
CECS 277 HOMEWORK TERM PROJECT
d. The Observer Pattern allows the Observers to subscribe to any number of Subjects, and
the Subjects to have any number of Subscribers. I admit, this is a little strained here, but
the Roach Motel itself is the Subject, and our waitlisted Roach Colonies are the Observers.
e. The Strategy Pattern allows you to change the behavior of an object based on a supplied
object. The payment strategy will fit nicely into that pattern.
f. And, of course, by now it should be clear who/what visits the rooms as a use of the Visitor
design pattern.
2. I would resign myself to writing several driver programs as you add one design pattern after
another to the mix. Each time you add a new pattern, write a fresh driver that will exercise all of
the functionality of the application as it exists by that point in your development process.
3. Oddly enough, it will help you if you do the UML class model before you start coding. I know that
we’ve been doing it the other way around all semester, but this is the time to actually do some
design work before you settle down to your coding.
SAMPLE OUTPUT:
motel: {}available: [101, 102, 103, 104, 105]
available Rooms: [101, 102, 103, 104, 105]
in set amenities: [foodbar, spa, refillbar, shower]
Suite, FoodBar, Spa, RefillBar, Shower 160.0
first colony 100
motel: {Suite, FoodBar, Spa, RefillBar, Shower 160.0=first colony 100}available:
[102, 103, 104, 105]
available Rooms: [102, 103, 104, 105]
in set amenities: [foodbar]
DeluxeRoom, FoodBar 85.0
Second colony 1000
motel: {Suite, FoodBar, Spa, RefillBar, Shower 160.0=first colony 100, DeluxeRoom,
FoodBar 85.0=Second colony 1000}available: [103, 104, 105]
amenities: [foodbar]
Second colony 600
available Rooms: [103, 104, 105]
255.0 paid with credit/debit card
room number is: 102
cost:255.0
motel: {Suite, FoodBar, Spa, RefillBar, Shower 160.0=first colony 100}available:
[103, 104, 105, 102]
available Rooms: [103, 104, 105, 102]
in set amenities: [foodbar]
BasicRoom, FoodBar 60.0
available Rooms: [104, 105, 102]
in set amenities: [foodbar]
BasicRoom, FoodBar 60.0
Time to clean the rooms today motel: {BasicRoom, FoodBar 60.0=third colony 300,
Suite, FoodBar, Spa, RefillBar, Shower 160.0=first colony 100, BasicRoom, FoodBar
60.0=fourth colony 400}available: [105, 102]
room number is: 103
Cleaning room: 103
room number is: 101
Cleaning room: 101
room number is: 104
CECS 277 Homework Term Project.docx 12/1/2019 6:15:00 PM 4
CECS 277 HOMEWORK TERM PROJECT
Cleaning room: 104
Linens Changed
the floor towels have been replaced.
available Rooms: [105, 102]
in set amenities: [foodbar]
DeluxeRoom, FoodBar 85.0
available Rooms: [102]
in set amenities: [foodbar]
DeluxeRoom, FoodBar 85.0
available Rooms: []
observers: [Seventh colony 700]
available Rooms: []
observers: [Seventh colony 700, eigth colony 800]
Time to clean the rooms todaymotel: {BasicRoom, FoodBar 60.0=third colony 300,
DeluxeRoom, FoodBar 85.0=sixth colony 600, Suite, FoodBar, Spa, RefillBar, Shower
160.0=first colony 100, BasicRoom, FoodBar 60.0=fourth colony 400, DeluxeRoom,
FoodBar 85.0=fifth colony 500}available: []
room number is: 103
Cleaning room: 103
room number is: 102
Cleaning room: 102
Linens Changed
all towels have been changed.
room number is: 101
Cleaning room: 101
Linens Changed
all towels have been changed.
Hamburger on the pillow.
room number is: 104
Cleaning room: 104
Linens Changed
the floor towels have been replaced.
room number is: 105
Cleaning room: 105
Linens Changed
all towels have been changed.
available Rooms: []
Email: myemail@example.com Payment: 180.0 completed.
The Seventh colony colony received the notification from The only motel in town
The eigth colony colony received the notification from The only motel in town
room number is: 103
cost:180.0
available Rooms: [103]
in set amenities: [foodbar]
BasicRoom, FoodBar 60.0
room number is: 102
Cleaning room: 102
Linens Changed
all towels have been changed.
room number is: 103
Cleaning room: 103
Linens Changed
the floor towels have been replaced.
room number is: 101
CECS 277 Homework Term Project.docx 12/1/2019 6:15:00 PM 5
CECS 277 HOMEWORK TERM PROJECT
Cleaning room: 101
Linens Changed
all towels have been changed.
Hamburger on the pillow.
room number is: 104
Cleaning room: 104
Linens Changed
the floor towels have been replaced.
room number is: 105
Cleaning room: 105
Linens Changed
all towels have been changed.
WHAT TO TURN IN:
• Each of the class files that you created for the project.
• Your console output, named console.txt