Hello once again. This week I'm working with objects. I have a hotel program, which is supposed to have five different rooms.
My code is here:
There is more to the program, but as most of it is currently blank and of no bearing to the problem at hand, I decided to keep it out of the code you see here.
I suppose what I need to know is: Am I on the right track? Is this how one would go about assigning these numbers to each room object, or am I completely off track? All my books don't really cover the matter of multiple objects in detail.
It seems like you have got confused between Hotel and Room classes. How about working on one at a time, since hotel needs Room lets work on Room first. What variables and methods do you think belong to Room? Can you post the updated Room class? Also remember to add a constructor to Room.
The code in your constructor is pointless; you declare some local variables, then assign them values. Those variables vanish as soon as the call to the constructor is complete. Perhaps those variables should be instance variables of the class.
am also new to java ... but am confused to see how you have assigned the values to Room variables
here you are setting the valuses of all variables which were passed to you in the function addRoom
and when you return the roomNumber in the end it send you the value 556 , because its the last value that you set for roomNumber.
make a separate class Room with constructor for setting the values
you can either create such an constructor or else create a function in Room class for assigning the values to a particular room
i cant even understand what is use of this code
here you need to check the occupied status of all the Room those has been created
In addition to the useful advice already given, I would suggest also using an array for your collection of rooms. In fact a collection class such as ArrayList would be even better. That way you can deal with any number of rooms instead of a fixed number of 5. I'm not sure how far along the Java "learning curve" you are, so if you have yet to learn about these data structures, then continue along the line you are currently on in conjunction with the advice already provided.