#31
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    1) use the new statement to create the object
    2) use the add statement to add it to the arraylist
    PHP Code:
        private void addBorrower()
        {   
            
    System.out.print("Enter borrowers first name: ");
            
    String firstName myScanner.nextLine();
            
    System.out.print("Enter borrowers last name: ");
            
    String lastName myScanner.nextLine();
            
    System.out.print("Enter borrowers library number: ");
            
    String libraryNumber myScanner.nextLine();
            
    System.out.print("Enter the number of books: ");
            
    String noOfBooks myScanner.nextInt();
            
    System.out.print("Enter borrowers address: ");
            
    String address myScanner.nextLine();
            
    borrowerList.addBorrower(new Borrower(String firstNameString lastNameString libraryNumberInt  noOfBooksString address));

    ? :S
  2. #32
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    Does that work?
  4. #33
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Does that work?
    Hey,

    I've been playing around all day and I still can't get my head around it,

    No matter what I write I get the same error:

  6. #34
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    Its not possible to copy text from an image for my response.
    The constructor for the Borrower class needs to have some specific args when it is called. Look at the definition of the constructor and make sure you use exactly the same as it requires.
  8. #35
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Its not possible to copy text from an image for my response.
    The constructor for the Borrower class needs to have some specific args when it is called. Look at the definition of the constructor and make sure you use exactly the same as it requires.
    Sorry,

    addBorrower():
    PHP Code:
        private void addBorrower()
        {   
            
    System.out.print("Enter borrowers first name: ");
            
    String fName myScanner.nextLine();
            
    System.out.print("Enter borrowers last name: ");
            
    String lName myScanner.nextLine();
            
    System.out.print("Enter borrowers library number: ");
            
    String lNumber myScanner.nextLine();
            
    System.out.print("Enter the number of books: ");
            
    String noOfBooks myScanner.nextLine();
            
    System.out.print("Enter borrowers address: ");
            
    String address myScanner.nextLine();
            
    borrowerList.addBorrower(new Borrower(fNamelNamelNumbernoOfBooksaddress));
        } 
    Borrower Constructor:
    PHP Code:
    /**
         * Constructor for objects of class Borrower.
         * The number of books should be set to 1.
         * 
         * @param firstName The Borrower's first name 
         * @param lastName The Borrower's last name
         * @param lNumber The Borrower's library number
         * @param street The Borrower's street
         * @param town The Borrower's town
         * @param postcode The Borrower's postcode
         */
        
    public Borrower(String fNameString lNameString lNumber
                        
    String streetString townString postcode)
        {
            
    firstName fName;
            
    lastName lName;
            
    libraryNumber lNumber;
            
    noOfBooks 1;        
            
    address = new Address(streettownpostcode);
        } 
  10. #36
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    Did you change your call to the constructor to match what the constructor requires?

    Comments on this post

    • CleanSweep agrees : Thanks for helping
  12. #37
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Did you change your call to the constructor to match what the constructor requires?
    Um, I think so, Sorry, I really don't like scanners
  14. #38
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    Later you will learn how to get input from a user via a GUI form.
  16. #39
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Later you will learn how to get input from a user via a GUI form.
    That's what we're doing, I need to add a borrower to the array list using user input

    Sorry if I didn't make that clear before
  18. #40
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    You use textfields to get user input with a GUI, not a Scanner.
  20. #41
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    You use textfields to get user input with a GUI, not a Scanner.
    So could you possibly tell me how I would go about using a scanner to do this?

    I simply, simply cannot figure it out
  22. #42
  23. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    using a scanner to do this?
    What are the problems you are having? Please explain.

    Count the args and data type of the args to the constructor and be sure that the new statement has exactly the same number and data type.
  24. #43
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    What are the problems you are having? Please explain.

    Count the args and data type of the args to the constructor and be sure that the new statement has exactly the same number and data type.
    So it should be:
    PHP Code:
        private void addBorrower()
        {   
            
    System.out.print("Enter borrowers first name: ");
            
    String firstName myScanner.nextLine();
            
    System.out.print("Enter borrowers last name: ");
            
    String lastName myScanner.nextLine();
            
    System.out.print("Enter borrowers library number: ");
            
    String libraryNumber myScanner.nextLine();
            
    System.out.println("Enter borrowers books :");
            
    int noOfBooks myScanner.nextInt();
            
    System.out.print("Enter borrowers address: ");
            
    String address myScanner.nextLine();
            
    borrowerList.addBorrower(new Borrower(firstNamelastNamelibraryNumbernoOfBooksaddress));
        } 
    or am I still doing something incorrectly?
  26. #44
  27. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    am I still doing something incorrectly?
    If you are getting error messages, you need to copy the full text and paste it here.
  28. #45
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    If you are getting error messages, you need to copy the full text and paste it here.
    I'm using BlueJ so the error messages come up as dialogue box's not text to copy,

    I could upload the project for you if you want so you can look at the error message I'm getting.

IMN logo majestic logo threadwatch logo seochat tools logo