. Develop a simple Hotel program. We will have two classes, a
Hotel class representing an
individual hotel and a Room class. The Hotel class will contain
several Room objects
and will have several operations. We will also have a driver
program to test the Hotel
class.
2. Build a Hotel class that will store information about a Hotel.
It will include a name and
location. It should also include an Array of instances of class
Room to hold information
about each room. It will also have an int called numOfRooms that
keeps track of how
many rooms are in the hotel. This is a partially filled array
value.
3. The program must use a standard Java Array. Set the Array to
hold 10 Room objects.
4. Build a HotelTest class to test your application. Your test
class should not require any
interaction with the user. It should verify the correct operation
of the constructor and all
public methods in the Hotel class. Create at least 5 rooms.
NOTE: NO USER INPUT. TEST THE PROGRAM WITH VARIABLES AND LITERALS
TO
OBTAIN FIELD VALUES.
Specific Requirements for the Hotel Class:
1. Instance Variables
1. theRooms: An Array of Room Objects
2. name: String - hotel name
3. location: String - hotel location
4. numOfRooms: int number of rooms in the hotel.
2. Constructors
1. Should use mutator methods to set all instance variable.
2. A default constructor that sets the Array to a size of 10 and
all instance fields to a
default value.
3. Parameterized constructor
1. Takes in parameters for name and location and sets those
instance
variables to the parameter values.
2. Assigns numOfRooms to zero. numOfRooms indicates how many
rooms
are in the hotel. It will create a 10-element array.
4. Methods
1. isFull() – returns a boolean that is true if all the rooms in
the hotel are
occupied.
2. isEmpty() – returns a boolean that is true if all the rooms in
the hotel are
unoccupied.
3. addRoom
1. Take in 3 parameters: the room number, bed type, rate(see
UML
below for details)
2. Creates a Room object from the parameters list.
3. Adds the Room object to the Array.
4. Increments numOfRooms (indicates how many actual rooms are
in
the hotel)
4. addReservation
1. Takes in parameters: the occupant’s name and the requested
bed
type.
2. Searches the array of rooms for one that matches the bed
type.
(Remember to use the partially filled array value numOfRooms
in
your search loop).
3. If an unoccupied room with the correct attributes is found,
the
renter's name will be set and the occupied attribute will be set
to
true. In either case a message will be printed that will state
whether
or not the reservation was made.
5. cancelReservation
1. Takes in a string representing the name of a visitor.
2. If it is found, the occupied attribute will be set to
false.
3. In either case a message will state whether or not the
reservation
was cancelled.
4. The method calls the private utility method
findReservation()to
scan the list of rooms looking for a guest by name.
5. The findReservation method will return the index of the room
in
the Array of rooms or NOT_FOUND if the room is not found,
which will be declared as:
private static final int NOT_FOUND = -1;
6. findReservation
1. Private method – only accessible from other method in the
class.
2. Takes in a String representing the occupant’s name
3. Searches the occupied rooms for a reservation with that
person’s
name.
4. Returns the index of the room or NOT_FOUND if not found
7. toString
1. Returns a nicely formatted string giving hotel and room
details
2. Calls the Room class’s toString
3. Uses the accessor methods to get the hotel name and
location
4. Example:
Hotel Name: Beach Marriot
Location: Pensacola
Number of Rooms : 5
Room Details are:
Room Number: 101
Occupant name: Not Occupied
Bed Type: queen
Rate: 100.0
Room Number: 102
Occupant name: Coffey
Bed Type: king
Rate: 110.0
Room Number: 103
Occupant name: Wilson
Bed Type: king
Rate: 88.0
Room Number: 104
Occupant name: Not Occupied
Bed Type: twin
Rate: 100.0
Room Number: 105
Occupant name: Not Occupied
Bed Type: queen
Rate: 99.0
3. The UML class diagram for the Hotel class will look like
this:
Hotel
theRooms: Array Room[]
name: String
location: String
numOfRooms: int
Hotel()
Hotel(String, String)
isFull(): boolean
isEmpty() : boolean
addRoom(int,String,double)
addReservation(String, String,String)
cancelReservation(String)
findReservation(String): int
toString(): String
Accessor and mutator methods for name and location.
Specification for the Room Class
13. Instance Variables
1. roomNum: int- number of the room
2. bedType: String- type of bed (i.e. king, queen etc.)
3. rate: double- cost of the room
4. occupantName: String – name of occupant
5. occupied: boolean – true if occupied.
14. Constructors
1. Should use mutator methods to set all instance variable.
2. Default constructor sets all instance variables to a default
value
3. Parameterized Constructor
1. Takes in room number, bed type, and room rate, as parameters and
sets the
appropriate instance variable to those values
2. Sets the occupants name to the empty String (“Not
Occupied”);
3. Sets occupied to false.
15. Methods
1. isOccupied - method returns true if the room is occupied, false
otherwise.
2. toString
1. Provides all the details of a room - room number, name of
guest(if
occupied) , bed type, rental rate in a nicely formatted
nicely
2. One attribute on each line using the '\n' escape character. See
example
above.
3. Uses the accessor methods to get the instance variables values
to use in the
String.
3. Accessor and mutator methods for the Room class’s instance
variables.
Room
roomNum: int
bedType: String
rate: double
occupantName: String
occupied: boolean
Room()
Room(int, String, double)
getBedType(): String
getRoomNum(): int
getRoomRate(): double
getOccupant(): String
setOccupied(boolean)
setOccupant(String)
setRoomNum(int)
setBedType(String)
setRate(double)
isOccupied(): boolean
toString(): String
Specification for the HotelTester
16. No user input, use variables and literals to obtain field
values.
17. Create an object of the Hotel Class.
18. Add at least 5 rooms with different room numbers, bed types and
rates.
19. Make several reservation including options where no room exists
or the matching room is
occupied.
20. Test all the methods in both the Hotel and Room class. Remember
the accessor and
mutator are tested if used in the constructors and toString as
specified above.
21. Use the Hotel toString to print out the hotel information prior
to exiting.
15. Methods
1. isOccupied - method returns true if the room is occupied, false
otherwise.
2. toString
1. Provides all the details of a room - room number, name of
guest(if
occupied) , bed type, rental rate in a nicely formatted
nicely
2. One attribute on each line using the '\n' escape character. See
example
above.
3. Uses the accessor methods to get the instance variables values
to use in the
String.
3. Accessor and mutator methods for the Room class’s instance
variables.
Room
roomNum: int
bedType: String
rate: double
occupantName: String
occupied: boolean
Room()
Room(int, String, double)
getBedType(): String
getRoomNum(): int
getRoomRate(): double
getOccupant(): String
setOccupied(boolean)
setOccupant(String)
setRoomNum(int)
. Develop a simple Hotel program. We will have two classes, a Hotel class representing an individual hotel and a Room cl
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am