Objective

Practice all concepts from CPCS-202 and CPCS-203, with a focus on making classes and creating objects from these classes. Specifically, you will practice making an array of objects and manipulating/using the data inside the array. Finally, and VERY important is that this program requires you to read from a file and write to a file (practice with File I/O). This is very important because all programs during the semester will use File I/O.

The Problem

FCIT is introducing a new service for FCIT students. It is starting a book loaning service, FCIT Library. FCIT Library provides textbooks for all courses in the College. FCIT students are automatically eligible to use this service. However, the library is on a tight budget; there is exactly one book available for each course! So, for example, if Student A borrows the course textbook for Data Structures, no other student can borrow that book until Student A returns the book to the library.

FCIT Library is in need of a program that:

Keeps track of all textbooks for FCIT courses. Keeps track of students who are allowed to borrow books from the FCIT Library. These students must be added to, or removed from, the FCIT Library system. Additionally, students can borrow books and return them at their convenience.

During the program, the following things can occur (just as in a normal library):

New students can be added to the enrolled group of students. For example, perhaps a student transferred from another faculty. So this new student can be added as a new student who can borrow books from FCIT Library.

New Textbooks can be added to the list of FCIT Library books. For example, perhaps the library doesn't initially own the CPCS204 new textbook. So this new book, the CPCS204 book, can be added as a new book for FCIT Library. Note: when new books are added for the first time, they are initialized with a quantity of 1, and it is immediately set to "Available".

Students can come throughout the day to borrow books from the library. If the book is available, the student will borrow the book. The book will be marked as unavailable, and the ID of the student will be saved into the record of the book (to show which student borrowed the book).

Students can only borrow a maximum of 5 books at a time. Meaning, once a student has 5 books in their possession, they cannot borrow any more books until they first return some books. So, for example, if they return 2 books, they are allowed to borrow 2 more books. However, they can borrow at most 5 books at any given time. Students will also return books that they borrowed. When a student returns a book, the book is immediately marked as available, and the student information should be removed from the record of the book.

A search can be conducted to find information about books.

Also, a search can be done to display the information for a certain student and list all the books he/she is currently borrowing.

You will use File I/O to read input from a file and then print the output to a file. To be clear, you will read COMMANDS from an input file. Example commands are ADDSTUDENT, ADDBOOK, BORROWBOOK, etc. Then, depending on the command, you will either add a new student or book, have a student borrow a book, search for a book, etc. But instead of printing to the console window (screen), you will print to an output file.

Implementation

For this program, you will create two Classes (UML diagram shown below): see image.

You will use the FCITstudent class to create nodes of type FCITstudent, and you will use the FCITbook class to create nodes of type FCITbook, which of course are used to represent the books in the FCIT Library.

The first two lines of the input file are as follows:

Line 1: the maximum number of books that can be available in the library.
Line 2: the maximum number of students registered with the library.

You must read these values into appropriate variables (such as maxBooks and maxStudents).

Next, you will use these new values to make two new arrays:

1.An array of FCITstudent object references
2.An array of FCITbook object references

To help you, here is the code to do this:

FCITbook[] books = new FCITbook[maxBooks];
FCITstudent[] students = new FCITstudent[maxStudents];

What do these lines do? They create an array of references. Note: each reference has a default value of null. Until now, we have NOT created any objects. For example, FCITstudent objects are only created when we see the command ADDSTUDENT. At that time, a new

FCITstudent object will be created and the reference for that object will be saved in the appropriate location of the array.

Input File Specifications

You will read in input from a file, "FCITlibrary.in". Have this AUTOMATED. Do not ask the user to enter "FCITlibrary.in". You should read in this automatically.

Note: a *.in file is just a regular text file. Also, a *.out file is a regular text file. Do not be scared by this. Instead of calling the input and output file as input.txt and output.txt, it is better for those files to have a good name. Therefore, the input file will be called FCITlibrary.in and the output file will be called FCITlibrary.out.

The first line of the file will be an integer, d, representing the maximum number of books in the FCIT faculty. The second line of the file will be an integer representing the maximum possible number of students registered in the FCIT library. Each of the remaining lines will have a command, which is then followed by relevant data as described below (and this relevant data will be on the same line as the command).

The commands you will have to implement are as follows:

ADDSTUDENT - Adds a new student to the library registry. The command will be followed by the following information all on the same line: ID, an integer representing the student ID number; firstName, a string representing the student first name; and lastName, another string for student last name.

When you read the ADDSTUDENT command, you must make a new object of type FCITstudent. Next, you must scan the additional information (listed above) and save this information into the correct data members of the new object. Each item will be unique. Meaning, the input file is guaranteed to not have duplicate items added to the library student registry via the ADDSTUDENT command. Finally, you must save the reference of this object inside the appropriate index of the student array.

*Note: this array must stay in sorted order based on the ID of the student. So the student with the smallest ID value will be at index 0, the product with the next smallest at index 1, and so on. Therefore, when you save the object reference into the array, you must first find the correct sorted index. After you find the correct insertion location, if there is no object at that location, then you can easily save the object reference at this index. BUT, IF there is an object at the index that you find, you must SHIFT that object, AND all objects to the right of it, one space to the right. This is how you make a new space in the array for the new object.

Example: if your array already has 6 student object references, from index 0 to index 5. And now you want to add a new student object reference at index 4 (based on the sorted location). Before you can add the new product object reference at index 4, you must SHIFT the product object references at index 4 and index 5 to index 5 and index 6. Basically you need to move them one position over to the right. Now, you have an empty spot at index 4 for the new product object reference.

ADDBOOK - Adds a new book to the FCIT Library. The command will be followed by the following information all on the same line: ID, an integer representing the book ID number (ISBN); name, a string representing the name of the book (the name is guaranteed to not have any spaces in itso it is easy to read); firstName, a string representing the first name of the author; and lastName, another string for student last name of the author.

The ADDBOOK command is processed very similarly to the ADDSTUDENT command. The array of FCITbook objects must stay in sorted order based on the ID of the book (smallest book first). So again, you must use shifting to make space in the array to add a new book. Shifting is a very slow operation, but we want you to practice it for this assignment.

BORROWBOOK - This command is for students requesting to borrow a book. The command will be followed by the following information all on the same line: student ID, an integer representing the ID of the student borrowing the book, and book ID, an integer representing the ID of the book being borrowed. If the book is available and if the student is not currently borrowing 5 books, then the student is allowed to borrow the book. The ID of the student is saved into the record of the book (into the FCITbook object for the book) and the book availability is set to 'false' (to show the book is not available). Additionally, the ID of the book must be saved into the array of currently borrowed books, booksBorrowed[], found within the FCITstudent object. You should save the ID of the borrowed book into the next available cell of the array. Meaning, if the student currently has 3 books borrowed, these three books will be saved at Index 0, Index 1, and Index 2 of the booksBorrowed[] array. The new book being borrowed should be saved into Index 3.

RETURNBOOK - This command is used for students returning a book. The command will be followed by the following information all on the same line: student ID, an integer representing the ID of the student returning the book. When a RETURNBOOK command is executed, the student will return the book that is stored in Index 0 of the booksBorrowed[] array. Therefore, even if a student has 5 books, the result of executing the RETURNBOOK command is that the student returns only one book, specifically, the book at Index 0. Note: after this book is "returned" to the system, the remaining books in the booksBorrowed[] array will need to SHIFT to the left. So if there were 3 books before the RETURNBOOK command, and these three books were in Index 0, Index 1, and Index2, after the command finishes, there should only be 2 books, in Index 0 and Index 1. Hint: after shifting, you will need to set the reference at Index 2 to point to null!

DISPLAYBOOK - This command will be followed by an integer on the same line, representing the book ID you must search for and then display. Note, when processing this command, you must use the Binary Search algorithm. To confirm that you are using Binary Search properly, you must print the indices that are visited during the search. Please see output for details on what you must print.

DISPLAYSTUDENT - This command will be followed by an integer on the same line, representing the student ID of the student to display. Note, when processing this command, you must use the Linear Search algorithm...(Indices must be shown: 0 1 etc). To confirm that you are using Linear Search properly, you must print the indices that are visited during the search. Please see output for details on what you must print.

DELETESTUDENT - This command will be followed by an integer on the same line, the student ID of the student who should be removed from the system. Note: before a student can be deleted, any and all currently borrowed books must be returned. Then, once all borrowed books are returned, the student can be removed from the system. Of course, this will require SHIFTING of the FCITstudent objects in order to maintain the sorting of the array.

*See output for different printing possibilities.

To implement these commands, you should make many methods to help you. Here are some example methods:

void addBook(books, input, output);
void addStudent(students, input, output);
void displayBook(books, input, output);
void displayStudent(students, input, output);
void borrowBook(students, books, input, output);
void returnBook(students, books, input, output);
void deleteStudent(students, books, input, output);
int findBook(books, bookID);
int findStudent(students, studentID);

These methods can be in your main program. They can be part of the FCITstudent class, or they can be part of the FCITbook class. YOU are the programmer! The choice is up to you and your style for how you want to use these methods and where you want to use them. Also, you may want to use more methods to help you do certain tasks as needed in the program.

Output Format

Your program must output to a file, called "FCITlibrary.out". You must follow the program specifications exactly. You will lose points for formatting errors and spelling.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.