Page 4 of 4 First ... 234
  • Jump to page:
    #46
  1. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    You need to find a way to copy the error messages so you can post them.
    Find another way to compile the program so you can get error messages that can be copied. The javac command gives good error messages.
  2. #47
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    You need to find a way to copy the error messages so you can post them.
    Find another way to compile the program so you can get error messages that can be copied. The javac command gives good error messages.
    This is the error I get when compiling:
    No help available for this message.
    Please mail the text of the error message to mik@bluej.org -
    wel will then add help text to our databse. Thanks.

    no suitable constructor found for Borrower(java.lang.String.java.lang.String.java.lang.String,int,java.lang.String.)

    constructor Borrower.Borrower(java.lang.String.java.lang.String.java.lang.String,int,java.lang.String.java.lang. String.java.lang.String) is not applicable
    (actual and formal argument lists differ in length)
    constructor Borrower.Borrower(java.lang.String.java.lang.String.java.lang.String.java.lang.String.java.lang.Stri ng.java.lang.String) is not applicable
    (actual and formal argument lists differ in length)
  4. #48
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    actual and formal argument lists differ in length)
    As I've said before:
    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.

    Make a list of the args for the constructor
    and make a list of what you are giving it for args.
    Which one(s) are different?

    Or copy the text of the constructor statement and paste it in a text file
    Then copy the text of the new statement and paste it below the above line.
    Match them up and see where the difference is.
    Last edited by NormR; November 27th, 2013 at 08:52 AM.
  6. #49
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    As I've said before:
    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.

    Make a list of the args for the constructor
    and make a list of what you are giving it for args.
    Which one(s) are different?

    Or copy the text of the constructor statement and paste it in a text file
    Then copy the text of the new statement and paste it below the above line.
    Match them up and see where the difference is.
    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));
        } 
    • firstName - String
    • lastName - String
    • libraryNumber - String
    • noOfBooks - int
    • address - String


    PHP Code:
    public Borrower(String fNameString lNameString lNumber
                        
    String streetString townString postcode)
        {
            
    firstName fName;
            
    lastName lName;
            
    libraryNumber lNumber;
            
    noOfBooks 1;        
            
    address = new Address(streettownpostcode);
        } 
    • firstName - String
    • lastName - String
    • libraryNumber - String
    • noOfBooks - int
    • address - String


    so would I need to add the (street, town, postcode) next to address in the method?:

    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 street address: "); 
            
    String street myScanner.nextLine(); 
            
    System.out.print("Enter borrowers town address: "); 
            
    String town myScanner.nextLine(); 
            
    System.out.print("Enter borrowers postcode: "); 
            
    String postcode myScanner.nextLine(); 
            
    borrowerList.addBorrower(new Borrower(firstNamelastNamelibraryNumbernoOfBooksstreettownpostcode)); 
        } 
  8. #50
  9. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    o would I need to add the (street, town, postcode) next to address in the method?:
    Are you asking about the constructor? If the class needs those values passed to it and the current constructor does not have them, then you could change the constructor to include them.
  10. #51
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Are you asking about the constructor? If the class needs those values passed to it and the current constructor does not have them, then you could change the constructor to include them.
    I've got it working but when I do to run the program this happens:

    Menu Options:
    - Add a borrower.............................................[1]
    - Get the current number of borrowers...........[2]
    - Show the details of a certain borrower........[3]
    - Show all the details of all borrowers............[4]
    - Remove a borrower......................................[5]
    - Exit the program...........................................[0]


    Please enter a menu option number: 1

    Enter borrowers first name: Enter borrowers last name:
    "Enter borrowers first name: Enter borrowers last name: " - They come up together, I should be able to add the first name, press enter, then it should ask for the second name, not come up at the same time :S

    So like:

    Enter Borrowers first name:
    George

    Enter Borrowers last name:
    Brown
  12. #52
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    There is a problem with using nextLine() following a call to nextInt(). The end line character is left in the Scanner's buffer after nextInt() and you need to call nextLine() to read the end line character before you can use nextLine() to read the next input.
  14. #53
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    There is a problem with using nextLine() following a call to nextInt(). The end line character is left in the Scanner's buffer after nextInt() and you need to call nextLine() to read the end line character before you can use nextLine() to read the next input.
    All thanks a lot man! All fixed there!

    One last problem:

    PHP Code:
        private void removeBorrower()
        {
            
    System.out.println("Please Enter the borrowers library number: ");
            
    String libraryNumber myScanner.nextLine();
            if (
    borrowerList.removeBorrower(libraryNumber))
                
    System.out.println("The borrower with the library number " libraryNumber +
                    
    " has been succesfully removed");
            else
                
    System.out.println("Library number " libraryNumber " not found, please try again");
        } 
    I wrote a loop so when I choose to remove a borrower from the list using a library number, it would remove the borrower with that library number if it was found, or give an error if it isn't found.

    It compiles but when I select that option from my menu in the command window, it doesn't even give me chance to enter a library number, it just does this:

    Please enter a menu option number: 5
    Please Enter the borrowers library number:
    Library number not found, please try again
    Menu Options:
    - Add a borrower................................[1]
    - Get the current number of borrowers...........[2]
    - Show the details of a certain borrower........[3]
    - Show all the details of all borrowers.........[4]
    - Remove a borrower.............................[5]
    - Exit the program..............................[0]
  16. #54
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    it doesn't even give me chance to enter a library number
    Is it the problem I discussed in post#52?

    To see what is being read by the Scanner method, add a call to println() following the call to next... that prints out what was read.
  18. #55
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by NormR
    Is it the problem I discussed in post#52?
    Yes, sorry! Thanks!

    But it also seems the loop doesn't work D;

    I added a borrower with the library number "123"

    when I go to remove a borrower with the library number "345" it gives the correct "Number not found" error

    But then when I enter "123" it then again gives the "Number not found" error?
  20. #56
  21. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Sounds like you need to debug the code that is doing the search to see why it is not finding the desired object. Add some println() statements that print out the values the program is looking at so you can see what the computer sees when the code is executed. That will help you understand what the problem is.
  22. #57
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    hi there ~ solution for your class


    All classes are here except showBorrower as im still working on it ~ thx for your guide over BorrowerTUI also ~ Hope we can be friends ~ T.C
    ============================================

    import java.util.*;
    /**
    * Class Borrower representing a library user.
    *
    * @author Logendran 21289
    * @version 12th December 2013
    */
    public class BorrowerTUI
    {
    // DECLARE SPECIFIC OBJECT HERE
    private BorrowerList borrowerList;
    private Scanner myScanner;

    /**
    * Creates the BorrowerTUI class and the Scanner
    */
    public BorrowerTUI()
    {
    borrowerList = new BorrowerList();
    myScanner = new Scanner(System.in);
    }

    /**
    * This displays the menu on the BlueJ terminal window
    */
    public void menu()
    {
    int command = -1;

    while (command != 0)
    {
    displayMenu();
    command = getCommand();
    execute(command);
    }

    }

    /**
    * Adds a borrower
    */
    private void addBorrower()
    {
    System.out.println("\nYou will now be instructed through the process of adding a new Borrower.");
    System.out.print(" Enter a first name: ");
    String firstName = myScanner.nextLine();
    myScanner.nextLine();

    System.out.print(" Enter a surname: ");
    String lastName = myScanner.nextLine();

    System.out.print(" Enter a library number: ");
    String libraryNumber = myScanner.nextLine();

    System.out.print(" Enter a street name and number: ");
    String street = myScanner.nextLine();

    System.out.print(" Enter a town name: ");
    String town = myScanner.nextLine();

    System.out.print(" Enter a postcode: ");
    String postcode = myScanner.nextLine();

    System.out.println("\n A new Borrower has being added. \n");
    borrowerList.addBorrower(new Borrower(firstName, lastName, libraryNumber, street, town, postcode));
    }

    /**
    *
    */
    private void displayMenu()
    {
    System.out.println("Enter a number for the action you want to perform:");
    System.out.println(" Add a Borrower.........................[1]");
    System.out.println(" Display the number of Borrowers........[2]");
    System.out.println(" Remove a Borrower......................[3]");
    System.out.println(" Display all of the Borrowers...........[4]");
    System.out.println(" Display a Borrower.....................[5]");
    System.out.println(" Quit...................................[0] \n");
    }

    /**
    *
    */
    private void execute(int command)
    {
    if(command == 0)
    {
    quitCommand();
    }

    else if(command == 1)
    {
    addBorrower();
    }

    else if(command == 2)
    {
    getNumberOfBorrowers();
    }

    else if(command == 3)
    {
    removeBorrower();
    }

    else if(command == 4)
    {
    showAllBorrowers();
    }

    else if(command == 5)
    {
    showBorrower();
    }

    else
    {
    unknownCommand(command);
    }
    }

    /**
    *
    */
    private int getCommand()
    {
    System.out.print(" Enter a valid command: ");
    return myScanner.nextInt();
    }

    /**
    * Gets the number of Borrowers in the ArrayList.
    */
    private void getNumberOfBorrowers()
    {
    System.out.println("Current number of borrowers: "
    + borrowerList.getNumberOfBorrowers() + "\n");
    }

    /**
    * Quits the program based on user input.
    */
    private void quitCommand()
    {
    System.out.println("\n The application will now shut down!");
    System.exit(0);
    }

    /**
    * Removes a Borrower from the ArrayList.
    */
    private void removeBorrower()
    {
    System.out.print(" Enter a Borrower's Library Number: ");
    String libraryNumber = myScanner.nextLine();

    if(borrowerList.removeBorrower(libraryNumber))
    {
    System.out.println(" Borrower with Library Number [" + libraryNumber + "] removed.");
    }

    else
    {
    System.out.println(" Borrower with Library Number [" + libraryNumber + "] NOT removed.");
    }
    }

    /**
    * Print out all borrowers. Space should be left
    * between each to make it easier to read.
    */
    private void showAllBorrowers()
    {
    borrowerList.getAllBorrowers();
    }



    /**
    *
    */
    private void unknownCommand(int command)
    {
    if(command < 0 || command > 5)
    {
    System.out.println("Unknown Command: " + command + "\n");
    }
    }
    }

    ----------------------------------------------------------
    This one getBorrower class u searching for ~ T.C
    ===========================================

    /**
    * print details of a Borrower
    *
    * @param libraryNumber the borrower's library number
    * @return true if found
    */
    public boolean getBorrower(String libraryNumber)
    {
    for(Borrower borrower : borrowers)
    {
    if(libraryNumber.equals(borrower.getLibraryNumber()))
    {
    borrower.printBorrowerDetails();
    return true;
    }
    }
    System.out.println("Borrower with library number: " + libraryNumber
    + " not found.");
    return false;
    }
Page 4 of 4 First ... 234
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo