This file defines a class of Room objects. The objects have the following instance variables:
number of beds in the room, of type integer;
guest?s name, of type String;
booking status of a room ? if the room has been booked, the status is 'true', otherwise it is
room tariff, i.e. cost of using the room for one night, of type double;
The methods of class Room should include:
· A default constructor which does not accept any arguments. This constructor should
initialise a Room object with the number of beds as two, the guest's name as "Nobody",
the booking status as false, and the room cost to 100.00. This is the default state of a
· A writer method for the number of beds. This method accepts one argument which is used
to set the number of beds. It must ensure that the number of beds stored in the Room
object remains in the range 1..4 inclusive.
· A writer method for the room tariff. This method accepts one argument representing a
new tariff value and must ensure that the tariff is never negative.
· A method called book which accepts a String argument representing a guest?s name. It
sets the booking state to true and assigns the parametric string to the guest's name
· A method called unbook which sets the booking state to false and sets the guest's name
variable back to "Nobody".
· A reader method for each of the number of beds, the tariff and the guest's name - these
return the appropriate value.
A boolean method called isBooked which returns the booking status.
A 'toString' method which return a single String containing the details of a room with
format as described below:
Room with <numOfBeds> beds, tariff <roomTariff>, and guest
Room with <numOfBeds> beds, tariff <roomTariff>, and is
Room with 2 beds, tariff 100.00, and guest named James Bond.
Room with 2 beds, tariff 100.00, and is vacant.
It is recommended that once you have written the Room class, you create a tiny program to
test it. The testing program should be placed in the same working directory as the Room class
and be used to create one or two Room objects and call some of the Room methods. Compile
the Room class and compile and run the test program to check your work.
This file declares a class of object which maintains a collection of Room objects. It will
contain methods which enable the collection to show the appropriate behaviours as required
by the menu. This file should be saved into the same working directory as Room.java.
The Hotel class should declare only an array of Room objects, no additional attribute is
The Hotel class must also contain some methods which allow the collection of rooms to be
managed. These methods should include:
· A constructor which accepts an integer which is used to set the size of the Room array. If
the integer value passed in is invalid, then an array of Room objects of size 50 is to be
created. If the parametric integer is valid, that is between 20 and 100, inclusive, then a
Room array of the specific parametric value will be created. Next you need to perform
some initialisation tasks for the rooms as described below. Each task can be defined as
private method, and the constructor will then invoke these methods to complete the task:
First task is to traverse the array and instantiates a default Room object referenced by
each array cell. After each Room has been instantiated, we will assume that the array
index will represent the room number in the hotel. For example room numbered 2 will
be in array cell with index 2, room numbered 5 will be in array cell with index 5, etc.
Second task is to traverse the array and set the room tariff of all the even numbered
rooms to $150.00, except room numbered 0, which is set to $1500.00 as it is the
Third task is to set the number of beds to 1 for the last 5 rooms, and set the number of
beds to 4 for rooms 1 though 5 inclusive.
· A method named getRoom which accepts an integer parameter representing a room
number and returns a reference to the Room object in that cell of the array. If the
parametric integer is illegal, a null reference should be returned.
· A method named numOfBookedRooms which does not accept any parameter, and returns
the number of rooms which are booked.
· A method named numOfVacantRooms which does not accept any parameter, and returns
the number of rooms which are not booked.
· A method named totalTariff which does not accept any parameter, and returns the total
value of all the tariffs of all the booked rooms. This simulates one day's income for the
· A method named getAvailableRooms which accepts an integer representing a number of
guests which need a room. This method should return a String in which there is a list of
all the unbooked rooms which have enough beds for the prospective guests.
· A method named findGuestRoomNumber which accepts a String representing a guest's
name and searches through all the rooms looking for the first guest whose name is the
same as the parametric name. The method should return the number of the room when a
match is found. If the name cannot be found, the method should return -1.
When you have written the Hotel class - test it by creating a Hotel object and invoking the
methods from a small Java program.
The aim of this class is to provide a user-interface for a modest application which uses a
Hotel container class and should be saved in the same working directory as the previous
files. It is recommended that this user-interface be written as a 'console' application using the
normal screen and keyboard to interact with a user via a simple text-based menu.
The user-interface should create a single Hotel object and provide a menu of choices to the
user with the following choices:
1 See available rooms for 'n' guests
~ 4 ~
The operator enters the number of guests needing accommodation. This value should then be
passed to the getAvailableRooms method of the Hotel object, the returned String captured
and displayed. This tells the operator which rooms can be booked.
2 Book a room
The operator enters name of the guest, then fetches the Room object of an appropriate empty
room (using the 'getRoom' method) and books it with the guest's name.
3 Unbook a room
The operator enters the number of the room to be unbooked, the Room object with that
number is obtained using 'getRoom' and unbooked. If the room is not booked, display an
4 Find which room a guest is in.
The operator enters a guest's name and this is passed to the 'findGuestRoomNumber' method
and the room number is displayed. If no such guest is found, display an appropriate message.
5 Print a report
· the number of booked rooms
· the number of empty rooms
· the total tariff of all booked rooms
6 Other options
You may add any other options you like to this list and you will be given credit for those
which are implemented correctly.
7 Quit the program.
Each time the user selects one of the previous options, and the program does that task,