|
please help
hi guys.
im struggling with a question that was given to me over easter. I dont quite understand what is being asked to do, and thought that you would be able to help.
This is the question given:
"Complete the methods as indicated by the comments. A test application has been provided (LibraryTest.java)-your output should match that indicated in the comments.
A book has the following data associated with it; author, title, classmark, whether it is on loan or not and the date it is due to be returned. The classmark has the form LLDD.DD.LDD.LD where L represents a letter and D a digit.
For example: Author: Bruce Eckel
Title:THinking in Java
Classmark: QA76.73.J38.E2
Due: 28th March 08
It should not be possible to change the author, title and classmark fields of a book object after it has been created. It should not be possible to renew Book objects, they muct return before being loaned out again.
Book.java is the first command:
//
// Book.java
//
// A class to represent a single book stored in the library.
// Each Book is defined by it's author, title and classmark
//
/* Create and import appropriate packages */
/* Appropriate class declaration */ {
// Define fields with private access
private String author;
private String title;
private String classmark;
private GregorianCalendar due;
private boolean onLoan;
// Creates a new instance of Book
public Book(String inAuthor, String inTitle, String inClassmark) {
/* Complete method */
}
// Returns true if the book is currently on loan, false otherwise
public boolean isOnLoan() {
/* Complete method */
}
// Mark the book as being on loan for a specified period (in days)
public void loan(int numOfDays) {
/* Set the due field to be numOfDays later than today's date. Check for any
possible errors in the use of this method. */
}
// Mark the book as having been returned
public void returnBook() {
/* Complete method */
}
/* Appropriate accessors and mutators for author, title, classmark */
// Access the date the book is due to be returned. Should return an
// appropriate value if the book is not currently on loan
public GregorianCalendar getDueDate() {
/* Complete method */
}
// Produce an appropriate string representation of the book object
public String toString() {
/* Complete method */
}
// An internal method to check whether the classmark is valid
private static boolean isValidClassmark(String inClassmark) {
/* Complete method */
}
}
This is the second part of the program Library.java
//
// Library.java
//
// A class to represent and manipulate a set of books.
//
/* Create and import appropriate packages */
/* Appropriate class declaration */ {
// Use a Vector to store the books
private Vector books;
// Creates a new Library instance
public Library() {
/* Complete method */
}
// Add a book to the library
public void add( String author, String title, String classmark ) {
/* Complete method */
}
// Produce an appropriate string representation of the book object
public String toString( ) {
/* Complete method */
}
// Access an element of the list
public Book getBook(int i) {
/* Complete method */
}
// Determine number of books in the library
public int size() {
/* Complete method */
}
}
This is the LibraryTest.java mentioned in the question:
/* import necessary packages */
public class LibraryTest {
public static void main(String[] args) {
Library lib = new Library();
lib.add("Bruce Eckel", "Thinking in Java", "QA76.73.J38.E2");
System.out.println(lib);
lib.add("Bruce Eckel", "Thinking in C#", "QA76.73.J28.E2");
System.out.println(lib);
lib.getBook(0).loan(7);
System.out.println(lib);
lib.getBook(0).returnBook();
System.out.println(lib);
lib.add("Cay Horstmann","Big Java","QA76.73.J38.E2");
System.out.println(lib);
System.out.println(lib.size());
System.out.println(lib.getBook(1));
}
/* Should produce output similar to:
Bruce Eckel, Thinking in Java, QA76.73.J38.E2 [available]
Bruce Eckel, Thinking in Java, QA76.73.J38.E2 [available]
Bruce Eckel, Thinking in C#, QA76.73.J28.E2 [available]
Bruce Eckel, Thinking in Java, QA76.73.J38.E2 [20/4/2008]
Bruce Eckel, Thinking in C#, QA76.73.J28.E2 [available]
Bruce Eckel, Thinking in Java, QA76.73.J38.E2 [available]
Bruce Eckel, Thinking in C#, QA76.73.J28.E2 [available]
Bruce Eckel, Thinking in Java, QA76.73.J38.E2 [available]
Bruce Eckel, Thinking in C#, QA76.73.J28.E2 [available]
Cay Horstmann, Big Java, QA76.73.J38.E2 [available]
3
Bruce Eckel, Thinking in C#, QA76.73.J28.E2 [available]
*/
}
Thanks
Chris
|