#16
  1. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,722
    Rep Power
    348
    Then a variable of that type is what should be to the left of the = not a String.
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Then a variable of that type is what should be to the left of the = not a String.
    Ahh thanks man!

    PHP Code:
        public boolean getBorrower(String libraryNumber)
        {
            
    int index 0;
            
    boolean found false;
            while(
    index borrowers.size() && !found)
            {
                
    Borrower borrower borrowers.get(index);
                if(
    borrower.equals(libraryNumber))
                {
                    
    found true;
                }
                else
                    
    index++;
            }

            if(
    found)
                return 
    index;
            else
                return -
    1;
        } 
    But now when it get's to

    PHP Code:
                return index
    I get the incompatible types error D;
  4. #18
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,722
    Rep Power
    348
    incompatible types error
    What do steps 3) and 4) say the method is supposed to return?

    You need to read the steps that the method should take as you write the code.
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    What do steps 3) and 4) say the method is supposed to return?

    You need to read the steps that the method should take as you write the code.
    Ahh i've got it! Thanks so much!



    Now all I need to do is the BorrowerTUI stuff with the scanner,

    So erm

    for the adding a Borrower object I tried:

    PHP Code:
        private void addBorrower()
        {   
            
    System.out.print("Enter brrower: ");
            
    borrowerList.addBorrower() = myScanner.nextLine();
        } 
    But that wouldn't work, how would I go about adding a borrower?
  8. #20
  9. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,722
    Rep Power
    348
    Create an instance of a Borrower object using the new statement and use the ArrayList class's add() method.
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Create an instance of a Borrower object using the new statement and use the ArrayList class's add() method.
    Sorry if I'm annoying you haha, but I really do appreciate this help

    Closest I can get to thinking of a solution is:

    PHP Code:
        private void addBorrower()
        {   
            
    System.out.print("Enter Borrower: ");
            
    Borrower borrower myScanner.nextLine();
            
    borrowerList.add(new Borrower(borrower));
        } 
  12. #22
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,722
    Rep Power
    348
    The nextLine() method does NOT return a Borrower object. Read the API doc for the Scanner class to see what it returns.
    You should read the tutorial for details on how to create an instance of a class:
    http://docs.oracle.com/javase/tutori...tcreation.html
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    The nextLine() method does NOT return a Borrower object. Read the API doc for the Scanner class to see what it returns.
    You should read the tutorial for details on how to create an instance of a class:
    http://docs.oracle.com/javase/tutori...tcreation.html


    Ignore Supernatural, I need something in the background to concentrate haha :')
  16. #24
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,722
    Rep Power
    348
    What is your question?
    Its better if you copy and paste text. Images don't allow copying of text for a response.
  18. #25
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    What is your question?
    Its better if you copy and paste text. Images don't allow copying of text for a response.
    Sorry it's just I've never got that error before.

    This is what the methods should do:



    PHP Code:

        
    private void addBorrower()
        {   
            
    System.out.print("Enter Borrower: ");
            
    String borrower myScanner.nextLine();
            
    borrowerList.addBorrower();
        }

        private 
    void getNumberOfBorrowers()
        {
            
    System.out.println("Current number of borrowers: " 
                
    borrowerList.getNumberOfBorrowers() + "\n");
        }

        private 
    void showBorrower()
        {
        }

        private 
    void showAllBorrowers()
        {
        }

        private 
    void removeBorrower()
        {
        }

        private 
    void quitCommand()
        {
            
    System.out.println("Goodbye! See you later!");
            
    System.exit(0);
        }

        private 
    void unknownCommand(int command)
        {
            
    System.out.println("The command you entered: " command 
                
    " seems to be invalid, please enter a valid command");
        }


  20. #26
  21. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,722
    Rep Power
    348
    What specific questions do you have now?
  22. #27
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    What specific questions do you have now?
    Erm,

    addBorrower using the BorrowerList addBorrower command by using a scanner

    removeBorrower using the BorrowerList class; Remove a borrower with the given library number. If successful output “Borrower with library [library No] removed.” If not then: “Borrower with library [library No] NOT removed.”

    showAllBorrowers using the BorrowerList command using a scanner
  24. #28
  25. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,722
    Rep Power
    348
    Start with the first one in the list. What have you tried and where are you having problems?
  26. #29
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Start with the first one in the list. What have you tried and where are you having problems?
    I've done it in other classes where I've just been creating objects like:

    PHP Code:
    private void addCommand()
        {   
            
    System.out.print("Enter student name : ");
            
    String studentName myScanner.nextLine();
            
    System.out.print("Enter student id : ");
            
    String studentID myScanner.nextLine();
            
    labClass.enrollStudent(new Student(studentNamestudentID));
        } 
    I just can't figure out how to create an object and add it to the ArrayList
  28. #30
  29. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,722
    Rep Power
    348
    1) use the new statement to create the object
    2) use the add statement to add it to the arraylist

IMN logo majestic logo threadwatch logo seochat tools logo