I created a method which searches for a string in an array list, however I the problem is, if I search for a book it has to be the exactly how it was inputted into the array list.
e.g if I type in "Harry Potter" as a book title and search for it, I have to put in "Harry Potter", I can't put "harry potter" or "HARRY POTTER"as it won't recognize it, i know there is something called ignore case but can't get it to work, or may have had it in the wrong place.
My code:
public void searchBook() {
System.out.println("\n"+"Enter the title of the book you would like to search for: ");
String search = input.nextLine();
for (int i = 0; i < newBook.size(); i++) {
// IF statement to check that any book in the array list equals what
// the user has typed in
if ( newBook.get(i).getTitle().equals(search) ) {
System.out.println(("Book ID: " + newBook.get(i).getBookID() + " Title: " + newBook.get(i).getTitle()
+ " Author: " + newBook.get(i).getAuthor() + " Genre: " + newBook.get(i).getGenre()
+ " Date registered: " + newBook.get(i).getDateReg() + " Loan Status: "
+ newBook.get(i).getLoan() + " Number of times loaned: " + newBook.get(i).getNumOfLoans()));
} else {
System.out.println("No match was found");
}
} // end of for
}// end of method
newBook.get(i)a ton of times, call it once and store it in a local variable.