Hi guys,
My code freezes in the console after a BookID is input, following the prompt "Enter the bookID of the book you wish to loan out".
Can't spot where I've gone wrong.
Thanks!
public static void issueBook() { // choose userID to issue to Scanner uid = new Scanner(System.in); System.out.println("\nEnter the userID of the user you wish to issue a book to:"); int userIDToIssue = uid.nextInt(); // get userID from user input System.out.println("UserID taken in by scanner: " + userIDToIssue); String userToIssueFirstName = ""; String userToIssueSurname = ""; String userFullName = userToIssueFirstName + " " + userToIssueSurname; // find user by ID ListIterator<User> findUserID = userStore.listIterator(); ListIterator<Book> findBookID = bookStore.listIterator(); boolean userFound = false; boolean bookFound = false; while (findUserID.hasNext() && userFound == false) { User u = findUserID.next(); if (u.getUserID() == userIDToIssue) { userFound = true; // stops while loop //code to run: if (u.booksHeld>=3) { System.out.println("The user already has 3 books. They must first return a book to be able to take out another book"); // Test userFound assignment to true: System.out.println(userFound); issueBook(); } else { // issue the book // variables: userToIssueFirstName = u.userFirstName; userToIssueSurname = u.userSurname; Scanner bid = new Scanner(System.in); System.out.println("\nEnter the bookID of the book you wish to loan out"); int bookIDToIssue = bid.nextInt(); // copy userBorrowing name to Book object while (findBookID.hasNext() && bookFound == false) { Book b = findBookID.next(); if (b.getBookID() == bookIDToIssue) { bookFound = true; // stops while loop // code to run: if (b.onLoan == true) { System.out.println("This book is currently out on loan. A message will be generated for the current borrowee to notify them that it has been requested by somebody else."); // TODO: export message to text file } else if (b.onLoan == false) { b.userBorrowingFirstName = userToIssueFirstName; // name of user borrowing the book is set b.userBorrowingSurname = userToIssueSurname; b.onLoan = true; // book is set to being on loan } } else { System.out.println("Book does not exist"); issueBook(); } } } u.booksHeld ++; // then update the number of books held - end } } }