Results 1 to 5 of 5

Thread: please help

  1. #1
    chris is offline Member
    Join Date
    Apr 2008
    Location
    Wales
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    Bluefox815 is offline Member
    Join Date
    Feb 2008
    Location
    Oregon, USA
    Posts
    49
    Rep Power
    0

    Default

    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!

  3. #3
    chris is offline Member
    Join Date
    Apr 2008
    Location
    Wales
    Posts
    2
    Rep Power
    0

    Default

    okay, thank you for your help.

  4. #4
    Bluefox815 is offline Member
    Join Date
    Feb 2008
    Location
    Oregon, USA
    Posts
    49
    Rep Power
    0

    Default

    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 04:02 AM.

  5. #5
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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:
    Java 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;
            ...
        }
    
        ...
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •