Question
Java programming Background Sometimes we want to keep the items in a list in sorted order, which we can achieve with a sorted list. The
Java programming
Background
Sometimes we want to keep the items in a list in sorted order, which we can achieve with a sorted list. The fundamental difference between a sorted list and an unsorted one is the "adding an item"/insertion method. Having a definition of a class for lists, we can obtain a sorted list class by altering the existing or adding new insertion method.
Task 1:
Derive a SortedArrayList
We cannot use the Collection.sorted () method.
Task 2:
Write a program to help a librarian in their daily work. The 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. R. Snow
Concurrent Programming
Stephen J. Hartley
Java Gently
Judith Bishop
Petri Nets
Wolfgang Reisig
Finite Transition Systems
Andre Arnold
4
Anna Smith
Zoe Brown
John Williams
John Smith
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 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.
u - 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.
r - 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 SortedArrayList
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. I 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started