import java.util.ArrayList;
/**
* A class to hold details of books I've read this year.
*
* @author Arran D. Stewart
* @version 2018.03.01
*/
public class BooksReadJournal {
// An ArrayList for storing the titles of books read.
private ArrayList<String> bookTitles;
/**
* Create a BooksReadJournal object
*/
public BooksReadJournal() {
bookTitles = new ArrayList<>();
}
/**
* Add a book to the collection.
* @param title The title of the book to be added.
*/
public void addBook(String title) {
bookTitles.add(title);
}
/**
* Return the number of books in the collection.
* @return The number of books in the collection.
*/
public int getNumberOfBooks() {
return bookTitles.size();
}
/**
* Print the details of a book from the collection.
* @param index The index of the book whose details are to be printed.
*/
public void printBookTitle(int index) {
if(index >= 0 && index < bookTitles.size()) {
String title = bookTitles.get(index);
System.out.println(title);
}
}
/**
* Remove a book from the collection.
* @param index The index of the book to be removed.
*/
public void removeBook(int index) {
if(index >= 0 && index < bookTitles.size()) {
bookTitles.remove(index);
}
}
}