CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Feb 2019
    Posts
    1

    Does any one can Help improve the methods above

    i was told to make an Books Library . i end up with that Code lines . i hope some one could help me to make it better then it is right now , this is mine Code lines of 2 method that i need to improve :



    Code:
    HashMap<Long,Book> books = new HashMap<>();
    
    
    
    
    @Override
    public BooksReturnCode addBookItem(Book book) {
        if(book.getPickPeriod()<3)
            return BooksReturnCode.PICK_PERIOD_LESS_MIN;
        if(book.getPickPeriod()>30)
            return BooksReturnCode.PICK_PERIOD_GREATER_MAX;
        return books.putIfAbsent(book.getIsbn(), book)==null?
                BooksReturnCode.OK:BooksReturnCode.BOOK_ITEM_EXIST;
    }
    
    
    
    
    
    @Override
    public BooksReturnCode addBookExemplars(long isbn, int amount) {
    
    
    
        if(books.containsKey(isbn)) {
                amount++;
                return BooksReturnCode.OK;
            }
        return BooksReturnCode.NO_BOOK_ITEM;
    }

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Does any one can Help improve the methods above

    Does the code compile without errors?
    Does the code do what is expected when it executes?
    Norm

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured