I have an assignment which can be found at http://www.cems.uwe.ac.uk/~lrlang/java_html/assignment2.html

i have coded all the required classes apart from Hotel and HotelGui classes

my problem is with the Hotel class

the assignment says
"The methods that you are required to implement are as follows:

* public Hotel ()
The constructor for this class. It initialises all the attributes, part of which involves creating an array of Booking objects containing at least 100 entries."

but i dont understand how to do this can someone please explain how, i dont want the code but an explaination of what is meant to be going on as i would like to work out the code for my self.

Thank you

hi,
"public Hotel ()" is your default constructor, and in here must initialize objects. you need an array of Booking objects, or an ArrayList can be used. with ArrayList you can its size...
any other properties of Hotel Class also need to be initialize to its default value, for example if your hotel has a name, then (in your constructor)

name = "Default Name";

hope that answered your question,

thanks for the help, but i still dont understand how to initialize the booking array within the constructor as it needs a GuestData object and a Room object to initialize. Also the Room class is an abstract class with the two subclasses SingleRoom and DoubleRoom and so i can't initialize a Room object with the code:

Room newRoom = new Room (parameters);

so how do initialize a Room object if i dont know if it will be a single or double room ?

thank you

you don't need to know. what you need to know is SingleRoom and DoubleRoom are also a Room. so you can create an array of Room, then store SingleRoom and DoubleRoom in it, because they are Room. you simply typecast Room to Single(or Double)Room, when you are retriving from the array, an example

Room = new Room[100];

Room[5] = new SingleRoom();
Room[7] = new DoubleRoom();

((SingleRoom)Room[5]).someMethod();
((DoubleRoom)Room[7]).someMethod();

there is also another way with generics but i don't think i can you an example about it, because i'm new to them. :)

This article has been dead for over six months. Start a new discussion instead.