Results 1 to 2 of 2
  1. #1
    Wpbops is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default Returning get() method in put() method in a Hash Map

    Hi, I'm new to the site and just have a quick question about a project I'm working on.
    I'm making a Library catalogue program, and working on the checkoutItem() method. It's a method that checks out an item if not already checked out. If the book is not checked out, get() should return null.

    Java Code:
    /**
         * Return who has given book 
         * Null if not checked out.
         */
        public Patron whoHas(Item i)
        {
         return checkoutsMap.get(i);
        }
    
    /**
        *Uses WhoHas() method for this
    public boolean checkOutItem(Item i, Patron p)
        {
            if(whoHas(i))
                {
                    return null;
                }
            checkoutsMap.put(i, p);  //Assign item variable to patron variable in the Hash Map
        
             
            
            
        }
    Could anyone lend a hand?

    -Wpbops
    Last edited by Eranga; 12-15-2011 at 04:18 AM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Returning get() method in put() method in a Hash Map

    Java Code:
    if(whoHas(i)) {
    What does the compiler have to say about this line?

Similar Threads

  1. My method keeps returning 0
    By ToolJob in forum New To Java
    Replies: 11
    Last Post: 03-27-2011, 06:22 PM
  2. Returning Value from a method
    By Mirix in forum New To Java
    Replies: 12
    Last Post: 06-01-2010, 10:48 PM
  3. Inherited method returning bad value
    By viking90 in forum New To Java
    Replies: 11
    Last Post: 04-07-2010, 04:53 PM
  4. returning an object from a method
    By bigj in forum New To Java
    Replies: 7
    Last Post: 01-08-2010, 01:39 PM
  5. Need help. Method won't returning proper value..
    By zlwilly in forum New To Java
    Replies: 2
    Last Post: 12-02-2008, 10:44 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
  •