I have an array list containing books. What I am trying to do (for various reasons) is use a While loop to keep on adding books to my array list until I tell the program to stop. In order to get it to stop, I am using a Scanner to ask the human user if another book should be added. If the user says yes, then the method would repeat, otherwise, the method will stop.
Unfortunately, I am stuck in 2 areas (for now). First, I am not sure how to insert the decision into the method, I tried:
while(decision.equals("Yes"){addBooks(anyTitle,anyAuthor);},
however, that just seemed wrong as it goes into a loop (while I want), however it causes 2 issues: A)Even if I type something else, the method does not end (unless I use another scanner and include a break), and B) The same inputted fields get inserted into the array list over and over again, without giving me a chance to input new Strings.
/**
* Method to add a single book
*/
public void setOneBook(String anyTitle, String anyAuthor){
bookList.add (new Book(anyTitle,anyAuthor));
}
/**
* Method to add books to collection until the command to stop is given.
*/
public void addBooks(String anyTitle, String anyAuthor){
bookList.add (new Book(anyTitle,anyAuthor));
System.out.println("Would you like to add another book?");
String decision = keybd.next();
}
I'm feeling pretty dumb at the moment, so please keep any snide comments to yourself.
While this is up, I will be messing around with my code, so if anything changes (for better or for worse), I will update my post.