WSQ11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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