/** * This class represents a (simplified) book * * @author cs161 * @version spring2019 */ public class Book{ // Instance variables private String title; private String author; private boolean finished; /** * Creates a new book * @param title * The title of the book * @param author * The author of the book */ public Book(String title, String author){ this.title = title; this.author = author; finished = false; } /** * Gets the title of the book * @return The title of the book */ public String getTitle(){ return title; } /** * Gets the author's name * @return The author's name */ public String getAuthor(){ return author; } /** * Marks the book as finished */ public void finished(){ finished = true; } /** * Returns whether the book has been finished or not * @return True if the book is finished, false otherwise */ public boolean getFinished(){ return finished; } /** * Returns a string representation of the book * @return A string representation of the book */ public String toString(){ String str = ""; if(finished){ str += "[x] "; } else{ str += "[o] "; } str += title + " by " + author; return str; } /** * Determines if two books are equal * @param other * This is the other book we are testing for equality * * @return True if the books are equal, false otherwise */ public boolean equals(Book other){ String otherTitle = other.title; String otherAuthor = other.author; return title.equals(otherTitle) && author.equals(otherAuthor); } }