You will have to know the array index of the book you want to edit. Or some how you will have to have the reference to book object that you want to edit.
Once you have the index that you want to edit. You can do something like this.
Replace this by
$$$$$$$$ **if (selection == 2)
{
System.out.println("Editing a Book ");
String empty = input.nextLine();**$$$$$$$$$$
}
This
if (selection == 2) {
System.out.println("Editing a Book ");
System.out.println("Please enter title of book to edit:");
String title = input.next();
Book editingBook = findBookByTitle(title);
if(editingBook == null) {
System.out.println("Sorry no book found with title name = " + title);
} else {
// Now ask user for new price etc what ever you want to edit.
System.out.println("Please enter new price:");
int newPrice = input.nextInt();
editingBook.setPrice(newPrice);
// etc. other editing to book.
}
}
In Addition you will have to add a method in your manager class. called findBookByTitle
/**
* This function takes a book title and search in the book array.
*
* @param title
* @return returns null if title is not found.
*/
public Book findBookByTitle(String title) {
Book searchBook = null;
for (Book book : books) {
if(book.getTitle().equalsIgnoreCase(title)) {
searchBook = book;
break;
}
}
return searchBook;
}
Hope this helps :)