Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Martin Bruce

Greenhorn
+ Follow
since Oct 25, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Martin Bruce

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.

A member asked this a while back and seems to be heading down the wrong road, can anyone help him out and at the same time help me? we are doing similar projects!
12 years ago

This works but I can't help thinking it was far to easy??
12 years ago
Forgot something important to store the books and users I should use SortedLinkedList<E> class.
12 years ago
Am I on the right track??

12 years ago
I just don't get how I will make sure say a int is read for the first line, then a string for the 2nd and 3rd, then another int and then more strings.


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
Snow
Concurrent Programming
Stephen Hartley
Java Gently
Judith Bishop
Petri Nets
Wolfgang Reisig
Finite Transition Systems
Andre Arnold
3
Emma Brown
Anna Smith
John Williams



This is what I have been asked to do and then it goes on to say, my program

should then store the information about books and users.

12 years ago
Cheers!

I was thinking BufferedReader would be the best way is this infact wrong and using the Scanner way would be better?
12 years ago
I would like to be able to read a list of books and a list of users from a file.

The content of the input file needs to have the following format:

The first line contains an integer representing the number of books in the library.
The second and third line contains info about the books (second line containing the title and the third line containing the autor's name).
The fourth line contains an integer representing the number of library users.
This is then followed by the info about users (one line for every user).

An example of what I am trying to do is below:



Can anyone help me out, I'm very stuck on what to do!
12 years ago