View Full Version : Assignment for college

Jon Smith
10-11-2008, 06:28 PM
Hey guys, i got this assignment due on monday. I seem to have run into a bit of a jam.

I will attach the assignment here, and my code thus far, let me know if i am on the right track. And additionally, i would like you to tel me what i should do for the library and loan classes, so far, i am not sure if i am on the right path with that.

Thanks in advance

Jon Smith
10-11-2008, 06:29 PM
Here is the question:

An R&D library maintains a database of its books. The database also keeps track of all its borrowers.

For each book its ISBN, title, type, status, author, publisher and date borrowed if the book is on loan are kept. Each book is aware of who its borrower is, whether it is overdue or not its expected date of return, its status (whether its IN or OUT) and fines owed. Each book can be lent for a different period depending on its type, compulsory: 4 weeks, reference: 2 weeks and special reserved: 1 week. If a book is returned after its due date a fee will be charged based on the type of book, compulsory: $2 per day, reference: $3 per day, reserved: $5 per day.

For each Borrower the Borrower’s Id, name, address, status and number of books currently on loan are stored. A borrower can be lent up to five (5) books. Books will be lent to borrowers with no overdue books, fewer that five books out and total fees less than $100. A borrower is aware of the set of books he borrowed and if he can borrow.
Each class has a manager which keeps a collection of the items; that is the Book class has a Book manager, the Borrower class will have a Borrower manager and the Loan class is managed by the Library. The following methods are in the Library class but are implemented in the appropriate manager class depending on the function.

ADDBORROWER: Adds a new borrower
DROPBORROWER: Drops a borrower if there is no overdue or he has no books to return
CHECKIN: Returns a book. The status of the book is updated and any overdue is calculated
CHECKOUT: Lends a book to a valid borrower
ADDBOOK: Adds a book to the library
DROPBOOK: Removes a book from the library provided it is not on loan
SEARCH: Searches for a book to determine if it is available for loan. If the book is not available, the borrower of the book is returned and the expected date of return.

This scenario assumes that there is only one copy of each book.
Write an Object Oriented solution to create the database and perform the specified tasks. The application class MUST be called Test. java. ALL data MUST be read from the text file db.txt.
All data sections are terminated with the keyword ‘END’.

Sample Data: Book
Dietel0004 Java How to Program r IN 0131016210 Dietel &Dietel Prentice Hall
Flanag0204 Java In a Nutshell c OUT 0596002831 David Flanagan O’Reilly 03-06-20

Sample Data: Borrower
99100452 John Smith #5 Hillview Drive, Tunapuna UnderGrad 5
02154632 Chris Chami #16 Insane Lane, St. Anns Lecturer 0

Sample Data: Transactions
ADDBORROWER: 01253642 Mary Joe Milner Hall, St. Augustine Postgrad 2
DROPBORROWER: 01526324 Mark Hamil Trinity Hall, St. Augustine Undergrad 2
CHECKIN: Dietel0004 01253642
CHECKOUT: MS00898666 99100452
ADDBOOK: PC00023457 PC Magazine j IN 2003 15-06-03
DROPBOOK: Flanag0204
SEARCH: MS10034568

Please note:
1. Date and ISBN are of type String.
2. Tabs separate data elements.

The following classes exist:
Book: This defines a Book object.
BookManager: This class manages the collection of Book objects. It is responsible for adding, dropping, searching and printing all the data for a book.
Borrower: This defines a Borrower object.
BorrowerManager: This class manages the collection of Book objects. It is responsible for adding, dropping, searching and print all the data for a borrower.
Loan: This class holds all loan information i.e. ISBN, BorrowerId, BorrowDate and DueDate.
Library: This class manages all the loans as well as manages the book and borrower manager. It handles all check ins and checkouts of books. It tests whether the borrower is able to borrow a book and if a book is available for loan. It searches the loans to determine whether a book is overdue and calculates any overdue available. The Library class calls the relevant add, drop and search methods in the borrower classes. For example, the Library class with have an addBorrower method which simply calls the addBorrower method in the BorrowerManager class.
Test: This class is responsible for reading in all the data and calling the relevant methods based on the transactions to be performed.

10-11-2008, 08:22 PM
Looks to be mostly in the right direction, although your code formatting could do with work (capitals are reserved for class names, and your indentation is irregular — looks like you're mixing spaces and tabs? Don't do that). Note that the point of having a separate BookManager class is that one doesn't have to make the methods static — so one can have more than one BookManager in use at one time.

Jon Smith
10-12-2008, 12:11 AM
Oh, wel i know my code formatting needs some work, this is just in the work you know, once everything is fixed i will make it neater.

Okay, thanks a lot for your advice.

Well, regarding the test class, i am a little bit confused as to what i should do.

This is what i got so far, i am trying to compile to see if its working, but i keep getting errors: cannot find symbol method in.next (), cannot find symbol method in.nextInt().

Should i be going this road, or is there something else i should do. Please direct me.

For the record, as far as Java Programming goes, i don't know a great deal. We recently started Classes and Objects. Currently i know Reading and writing to files, working with methods and arrays.

I now checked my email, my tutor sent us a new text file to read from. Its different from the previous one. I will attach it to my post.
She also sent us a message: If the book status is IN then the date borrowed should be set to null and you should not read any data after the publisher.
Ignore all processing that deals with overdues and fees since you cannot manipulate the String as a date.
For each borrower the only restriction will now be the 5 books.

Code for Test class thus far. {I feel ashamed for putting this crap on the internet, lol}

import java.io.*;
import java.util.*;

public class Test{

public static void main (String [] args)throws IOException{

FileReader in= new FileReader ("db.txt");

ReadBorrowerData (in);

}//end main

public static String ReadBorrowerData (FileReader in) throws IOException{
String readfile;


while (!readfile.equals("END")){
long idnum=in.next();
String name=in.next();
String address=in.next();
String status=in.next();
int booksonloan=in.nextInt();
}//end while

}//end method

}//end class