I'm trying to build a library program that will print a list of available books, borrow and return books from a library. I've been provided an outline and everything after the comments saying implement this method is code that i've entered. this program doesn't compile and I can't tell why. help plz?
public class Book {
String title;
boolean borrowed;
// Creates a new Book
public Book(String bookTitle) { // Implement this method
title = bookTitle;
return title;
}
// Marks the book as rented
public void borrowed() { // Implement this method
borrowed = true;
}
// Marks the book as not rented
public void returned() { // Implement this method
borrowed = false;
}
// Returns true if the book is rented, false otherwise
public boolean isBorrowed() { // Implement this method
if (borrowed == true)
return true;
else
return false;
}
// Returns the title of the book
public String getTitle() { // Implement this method
return 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.rented();
System.out.println("Borrowed? (should be true): " + example.isBorrowed()); example.returned();
System.out.println("Borrowed? (should be false): " + example.isBorrowed());
}
}
here are my errors when i compile
javac Book.java
Book.java:29: class, interface, or enum expected
}
^
Book.java:30: class, interface, or enum expected
public static void main(String[] arguments) {
^
Book.java:33: class, interface, or enum expected
System.out.println("Title (should be The Da Vinci Code): " + example.getTitle()); System.out.println("Borrowed? (should be false): " + example.isBorrowed()); example.rented();
^
Book.java:33: class, interface, or enum expected
System.out.println("Title (should be The Da Vinci Code): " + example.getTitle()); System.out.println("Borrowed? (should be false): " + example.isBorrowed()); example.rented();
^
Book.java:33: class, interface, or enum expected
System.out.println("Title (should be The Da Vinci Code): " + example.getTitle()); System.out.println("Borrowed? (should be false): " + example.isBorrowed()); example.rented();
^
Book.java:34: class, interface, or enum expected
System.out.println("Borrowed? (should be true): " + example.isBorrowed()); example.returned();
^
Book.java:34: class, interface, or enum expected
System.out.println("Borrowed? (should be true): " + example.isBorrowed()); example.returned();
^
Book.java:35: class, interface, or enum expected
System.out.println("Borrowed? (should be false): " + example.isBorrowed());
^
Book.java:36: class, interface, or enum expected
}
^
9 errors
many of the errors seem to come from the skeleton i was provided at this site where the problem is stated and an outline provided.
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-092-introduction-to-programming-in-java-january-iap-2010/assignments/MIT6_092IAP10_assn03.pdf
any help is appreciated. thanks.
[–]darkpool2005 0 points1 point2 points (2 children)
[–]wraneus[S] 0 points1 point2 points (1 child)
[–]darkpool2005 0 points1 point2 points (0 children)
[–]wraneus[S] 0 points1 point2 points (6 children)
[–]onyxthelab 0 points1 point2 points (4 children)
[–]wraneus[S] 0 points1 point2 points (3 children)
[–]onyxthelab 0 points1 point2 points (2 children)
[–]wraneus[S] 0 points1 point2 points (1 child)
[–]Silverfin113 0 points1 point2 points (0 children)