Task 2:
You are asked to write a program to help a librarian in their daily work. Your program should read a list of books and a list of users from a file. The content of the input file should have the following form: The first line contains an integer representing the number of books in the library, and is followed by the information about the books (two lines for every book: one line containing the title and the second one containing the author’s name). The next line contains an integer representing the number of library users, followed by the information about the users (one line for every user with their first name and surname). Example file content is given below:
5
Concurrent Programming
C. Snow
Concurrent Programming
Stephen J. Hartley
Java Gently
Judith Bishop
Petri Nets
Wolfgang Reisig
Finite Transition Systems
Andre Arnold
3
Emma Brown
Anna Smith
John Williams
The program should be able to store the information about books and users:
1. For each book, the information required is: the title, author’s name, whether it is on loan or not, and if it is on loan, who borrowed it. We assume that every book has only one author and that there are no two books in the library with the same title and author.
2. For each user, the library should know the first name, surname and the number of books currently held by the user. We assume that at any time a user can hold at most 3 books. We also assume that no two users share both the first name and the surname.
After the initial information has been read from the file, the librarian will be working with the program interactively. The program should display a menu on the screen offering a choice of possible operations, each represented by a lower case letter:
f - to finish running the program.
b - to display on the screen the information about all the books in the library.
v - to display on the screen the information about all the users.
i - to update the stored data when a book is issued to a user.
l - to update the stored data when a user returns a book to the library.
You should implement all the above operations.
Additional assumptions:
1. When f is selected, the program stops running and all the data are lost. The program could be extended to save all the data to a file, but this is not a part of the project!
2. To store books and users you should use SortedLinkedList<E> class. Books should be sorted in the ascending order of surnames of authors. You can assume that each author has only one surname and that it is always given after the first name(s) and/or initial(s). If there are several books by authors with the same surname, their order in the sorted list is not important. Users should be sorted in the ascending order of their surnames. If two users have the same surname then the first names should decide their order. You can assume that each user has exactly one first name and exactly one surname.
3. When a book is to be issued to a user, it must be checked whether the user is a valid user, and that the book is on the list of the books in the library. If not, an appropriate message should be displayed on the screen. If the request is a valid one, the program should check whether the book is on loan or not. If the book is currently on loan, a note to the user who is holding the book should be printed to a file informing that the book was requested by another user and should be returned as soon as possible. If the book is available, the stored information should be updated accordingly.
4. When a book is returned by a user, it must be checked whether the user is a valid user, and that the book is on the list of the books in the library and has been borrowed by this user. If not, an appropriate message should be displayed on the screen. If the request is a valid one, the stored information should be updated accordingly.
john mater wrote:Thanks, as this is the case how do I invoke a method based on the string entered?
john mater wrote:Thanks, as this is the case how do I invoke a method based on the string entered?
Campbell Ritchie wrote:Why are you using the compareTo method rather than equals?
Never say anything good about that reprobate Ritchie.Brian Wolf wrote:. . . I went with the quickest solution . . .
Campbell Ritchie wrote:You haven't got the quickest method yet Look at this old post.
Never never say == true or == false or similar. You might get nasty errors if you write = instead of ==. Anyway, you can delete every == true and replace every == false with a ! in the right location and the code's effect will be unchanged.
john mater wrote:Thanks Brian,
This helps a lot however my code needs to be slightly different. The user needs to choose an option and each option will invoke a different method.. will a set of if else statements modelled around your code suffice?
Don't get me started about those stupid light bulbs. |