Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-01-2008, 02:39 AM
Member
 
Join Date: Apr 2008
Location: Wales
Posts: 2
chris is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-01-2008, 03:02 AM
Member
 
Join Date: Feb 2008
Location: Oregon, USA
Posts: 24
Bluefox815 is on a distinguished road
Send a message via MSN to Bluefox815
You need to create a Book class that can represent any book you might have in your Library.

Then you need to make a Library class that can hold a number of Book objects and do certain things like add a new book to the library [add(String,String,String)] or take a book from the library and get info from it [getBook(int)]

How you do that, I don't really know, but you have all the required methods laid out for you. Good luck!
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-01-2008, 03:24 AM
Member
 
Join Date: Apr 2008
Location: Wales
Posts: 2
chris is on a distinguished road
okay, thank you for your help.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-01-2008, 03:53 AM
Member
 
Join Date: Feb 2008
Location: Oregon, USA
Posts: 24
Bluefox815 is on a distinguished road
Send a message via MSN to Bluefox815
also, you made your topic "please help" which is frowned upon so you probably won't be getting help from anyone else (you should give your thread a descriptive title).

Last edited by Bluefox815 : 04-01-2008 at 05:02 AM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-01-2008, 04:32 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
The author of the classes has provided two classes with member variables and methods. The goal is to complete the implementation of each of the two classes so that you can run the third, test class and get the output requested at the end.
The Book class stores all the information to describe a book and you can get information from it. The Library class keeps a collection of Books in a Vector and also provides ways of obtaining information about these books.
I would start with the Book class and build it up according to the requirements.
Then I would add a main method to the Book class and try it out - test its methods, see what it will do, make sure things compile and work the way you want.
Once you have it the way you want (according to the requirements given) you can move on and have a go at the Library class. Finally test them with LibraryTest.
For example, you could start with the Book class declaration and constructor:
Code:
public class Book { // Define fields with private access private String author; ... // Creates a new instance of Book public Book(String inAuthor, String inTitle, String inClassmark) { // Initialize member variables with argument values. author = inAuthor; ... } ... }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 12:37 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org