Results 1 to 2 of 2
  1. #1
    susan is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default Help with method getRoom()

    I have a bunch of room objects. I need a method to return a certain room object based on a String input.

    Java Code:
    public Room getRoom(String roomName){
         //code to return the room object with the name roomName
         return room;
    I also need a way to randomly return a room object.
    A room object:
    public Room(String name, String description) {
   = name;
            this.description = description;
            visits = 0;

  2. #2
    cachi is offline Member
    Join Date
    Jul 2007
    Rep Power


    I think in your case, you'd be better off using a HashMap, for problem A anyway. That way you wont have to do an interactive search, and you can mention why you used a hashmap and its advantages over other collections for this particular problem.
    Also think about applying generics if you are using Java 5.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 06:12 PM
  2. Method Help
    By pringle in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 01:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts