Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2007, 12:01 PM
Member
 
Join Date: Nov 2007
Posts: 33
dirtycash is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-21-2007, 04:53 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
I'm making a few assumptions before doing this. They are:
1. The rooms are stored in an array.
2. The rooms are stored as Room objects.
3. getOccupier returns a String


Code:
public int findVacantRoom(){
for(int i = 0; i < rooms.length; i++){
if (rooms[i].getOccupier() == null){ return i; }
}
return -1; }
Essentially what this does is checks all of the rooms in the room array starting at zero. When a vacant room is encountered, the array index of that room is returned. (You might have to return something like rooms[i].roomNumber if the room numbers do not correspond to the array index.) If the for loop completes without finding a vacant room, -1 is returned.

Again, if my assumptions aren't true than this might not work. Regardless of how the data is stored, the idea is the same though.

Good luck.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-21-2007, 06:17 PM
Member
 
Join Date: Nov 2007
Posts: 33
dirtycash is on a distinguished road
it says it cannot find variable length?



thanks for the reply

Last edited by dirtycash : 11-21-2007 at 07:18 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-21-2007, 08:13 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
That was written assuming that the rooms were going to be stored in an array. If they are stored another way, (vector, ArrayList...) you will have to modify the code.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-21-2007, 08:29 PM
Member
 
Join Date: Nov 2007
Posts: 33
dirtycash is on a distinguished road
ive fixed it now thanks for your help

Last edited by dirtycash : 11-21-2007 at 09:18 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
why we use public access modifier? vichet New To Java 1 04-04-2008 08:04 AM
public declaration ('undeclaring') Jadellll New To Java 2 03-17-2008 09:50 PM
Public Holidays (Australia) oranjeBoven Advanced Java 0 02-13-2008 09:14 AM
Public class variable Java Tip Java Tips 0 12-03-2007 10:58 AM
Class is public, should be declared in a file goldhouse New To Java 1 08-09-2007 07:36 PM


All times are GMT +3. The time now is 12:26 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org