![]() |
public method
how would i go about answering the following question -
1. findVacantRoom has no parameters and returns an integer value representing the room number of a vacant room. Remember that the getOccupier method of a Room will return null when a room is vacant. Room zero will be occupied first, then room 1, then room 2 and so on. This method will return the first vacant room, so if rooms 0, 1, 2 and 4 are occupied, findVacantRoom will return 3 which is the number of the first vacant room. The method must return -1 if the hotel is full and there are no vacant rooms. is it asking for a conditional statement? |
Re: public method
Why don't you consider this as a problem-solving exercise, and not as a programming exercise. That way you can design your solution, then implement it.
It's pretty clear. You have a list of rooms. These rooms are given from the beginning (lowest numbered room first). They may be vacated in any order. Each time you need a vacant room, you begin with the first room and go up the list until you find a vacant room. Obviously, there are conditionals involved. IF a room is not vacant, you can't give it out. If the hotel is full, you can't give out a room. Isn't that easy, if you just think about it and don't get dranoed because it's a "programming" assignment? Hint: when it comes to the code, think array or list. |
Re: public method
Here's something I scratched up:
:
import java.util.List; |
Re: public method
Don't know if you're still working on this or not...but you might want to look into ArrayList, which would be another alternative.
Logic would just be having a class with an ArrayList containing all classes that are Rooms, and have a boolean in the room classes which would determine if it had been used or not. In your findVacantRoom method you would simply check the rooms in the ArrayList to see if their boolean is true or false, and go from there. Very simple, ArrayList is amazing :) |
| All times are GMT -5. The time now is 11:13 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC