Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Search A Vector

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating a Hotel Booking System.

On my Assignment sheet on the Button Events part it says.

" If the source of a button event is 'BOOK SINGLE ROOM' or 'BOOK DOUBLE ROOM' the Vector of Rooms should be searched, over the range for bedrooms, to ensure that there is a vacant room of the requested type: otherwise a suitable message is displayed stating that there are no rooms available."

" If there is a vacant room (ie the getCustomer() method returns null) then the user is requested to input the name of the customer, and the room is booked using the bookRoom(String) method. The JLabel associated with the room is to show the text 'OCCUPIED'"

My question is how do I search a vector to see if there is a vacant room?

The code I have for the Hotel GUI class where I have created the Vector and added the Bedroom & MeetingRooms to it is


And the code that I have for the Room & Bedroom class's is


[edit]Please avoid very long lines; they make the code hard to read. I have split the longest line, and you can see how it ought to be done. CR[/edit]
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you can use a "for" loop to visit each room in the Vector "hotel", and call getCustomer() on it to see if it returns null.
 
Ross McManus
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

So that would go in the mouse clicked event?


 
Marshal
Posts: 75702
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you have panels called bedroom101, bedroom102, etc (or similar). Why can't you write a loop which will initialise them, and associate them with a Bedroom object? You can even set up a Map<Bedroom, Panel> which will allow you to find the panel from the associated Bedroom.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ross McManus wrote:Thanks.

So that would go in the mouse clicked event?



Yes. Personally, I'd put the code that actually looped over the rooms into a separate method, and call it from the event handler -- but you could put it all in the event handler if you like.
 
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ross,

You have probably got the answer from the replies posted.

I have an alternative way of doing this.

You could maintain 2 additional separate vectors one for Bedrooms and one for the Meeting rooms and populate them with vacant Bedroom numbers and Meeting room numbers respectively.

So if the vector size is 0 you dont have anything vacant. Else, you have vacant Bedrooms or Meeting rooms.

This could solve you problem.
These vectors should be in sync with your original vector.
Hope this helps.

 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic