Skip to content

Instantly share code, notes, and snippets.

@gilrg18 gilrg18/Book
Created May 4, 2016

Embed
What would you like to do?
WSQ11
public class Book {
String title;
boolean borrowed; //default boolean value is false
// Creates a new Book
public Book(String bookTitle) {
this.title=bookTitle;
}
// Marks the book as rented
public void borrowed() {
this.borrowed=true;
}
// Marks the book as not rented
public void returned() {
this.borrowed=false;
}
// 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());
example.borrowed();
System.out.println("Borrowed? (should be true): " + example.isBorrowed());
example.returned();
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
You can’t perform that action at this time.