Skip to content

Instantly share code, notes, and snippets.

@gilrg18
Created May 4, 2016 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilrg18/4375df27cd5517710ee612c2d0691e8f to your computer and use it in GitHub Desktop.
Save gilrg18/4375df27cd5517710ee612c2d0691e8f to your computer and use it in GitHub Desktop.
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