I am working on a library application which allows users to store, borrow and return technical manuals.
I have ran into a problem when building the return section of the application.
Currently, if the user borrows a manual and they wish to return it, they must enter the title of the manual from the list of borrowed manuals displayed. However, if the user wishes to return any manual after the first on that list, nothing happens. The user enters the name and hits the enter key, but the application simply halts.
Here is an example of the error I am describing:
Here is the relevant code:
static void returnManual(){
System.out.printf("\n\nHere are the Manual/s currently out on loan:\n\n");
if(ManualList.get(ManualChoice).status.equalsIgnoreCase(status2) && borrowedManuals.size() >= ManualChoice){
for (int i = 0; i < borrowedManuals.size(); i++)
System.out.println(borrowedManuals.get(i).displayManual());
returnManualTitle = Console.readString(Messages.enterManualTitle, Messages.tooShortMessage, 3);
}
int x = 0;
boolean titleExistance = false;
while (x < ManualList.size()){//Search for the Manual by title, if it exists change it's status,
//it's borrower and borrowDate.
if (ManualList.get(x).title.equalsIgnoreCase(returnManualTitle)){
ManualList.get(x).status = "Available";
ManualList.get(x).borrower = "N/A";
ManualList.get(x).borrowDate = "N/A";
ManualList.get(x).returnDate = "N/A";
int p = 0;
borrowLoop:
while (p < borrowedManuals.size()){//Search for the Manual by title, if it exists change it's status,
//it's borrower and borrowDate.
if (borrowedManuals.get(p).title.equalsIgnoreCase(returnManualTitle)){
borrowedManuals.remove(p);
break borrowLoop;
}
}
System.out.println(Messages.successReturnMessage);
titleExistance = true;
break;//if a title is found, break out of the loop and display choice menu.
}
x = x+1;
}//end of while loop.
if(titleExistance == false){
boolean repeatReturnManual = Console.readYesNo("\n--------------------------------------------------------------------------" + "\n\nThe Manual with the title "+"\""+returnManualTitle +"\""+ " wasn't found!"
+"\n\nDo you want to try again? (Y/N):\n");
System.out.println("\n--------------------------------------------------------------------------");
if(repeatReturnManual){
returnManual();
}else{
Menu.displayMenu();
}
}else if(titleExistance){
Menu.menuChoice = 7;
}
}
/**
* Removes the Manual.
*/