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
~ 3 ~
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.