Skip to content

Instantly share code, notes, and snippets.

Created May 4, 2016 03:31
What would you like to do?
public class Book {
String title;
boolean borrowed; //default boolean value is false
// Creates a new Book
public Book(String bookTitle) {
// Marks the book as rented
public void borrowed() {
// Marks the book as not rented
public void returned() {
// Returns true if the book is rented, false otherwise
public boolean isBorrowed(){
// Implement this method
return this.borrowed;
// Returns the title of the book
public String getTitle() {
// Implement this method
return this.title; //
public static void main(String[] arguments) {
// Small test of the Book class
Book example = new Book("The Da Vinci Code");
System.out.println("Title (should be The Da Vinci Code): " + example.getTitle());
System.out.println("Borrowed? (should be false): " + example.isBorrowed());
System.out.println("Borrowed? (should be true): " + example.isBorrowed());
System.out.println("Borrowed? (should be false): " + example.isBorrowed());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment