Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Implementation of a File containing the record structure for Books Title, Aut

ID: 3555739 • Letter: 1

Question

1. Implementation of a File containing the record structure for Books Title, Author

2. Implementation of READ FILE code, that executes whenever user requests a LIST of Books. The Books read are stored in an ArrayList structure in memory.

3. Implementation of WRITE FILE code, that executes whenever user requests to ADD a Book.

4. Implementation of a SORT Method in the Library Class, that sorts the Book List alphabetically by title.

5. Implementation of a REMOVE Method in the Library Class that removes a Book from the file.

6. It needs to read ALL the books from the file, loop through the ArrayList to find the textbook to be removed. Remove the textbook and WRITE the ArrayList of books back to File.

7. Create a Fiction and Nonfiction class that inherits Book. Look for the “Super

Explanation / Answer

package library; import java.util.ArrayList; import java.util.InputMismatchException; import java.util.Scanner; public class Book { public String title; public String author; public String publisher; public String publicationYear; public String status; public String borrower; public String borrowDate; public String returnDate; public String status1 = "Available"; public String status2 = "Borrowed"; public int BookChoice; static ArrayList UserList = new ArrayList(); static ArrayList BookList = new ArrayList(); static int choice ; static Scanner userInput = new Scanner(System.in); static Scanner choiceInput = new Scanner(System.in); /* * Book Constructor: */ /** * =================================================================================================== * Class Methods here: * =================================================================================================== */ public static void displayFirstMenu(){ System.out.println(">########################################################################"); System.out.println("> Choose one of the options below by typing the corresponding number: "); System.out.println(">===================================================================="); System.out.println("2- Add a book to the Library."); System.out.println("6- Blow up library."); System.out.println("7- Back to main menu."); System.out.println("0- Exit."); System.out.println(">########################################################################"); System.out.println("> Enter your option here: "); choice = choiceInput.nextInt();//User inputs a choice (integer). } public static void displaySecondMenu(){ System.out.println(">########################################################################"); System.out.println("> Choose one of the options below by typing the corresponding number: "); System.out.println(">===================================================================="); System.out.println("1- Check library list."); System.out.println("2- Add a book to the Library."); System.out.println("3- Borrow a book."); System.out.println("4- Return a book."); System.out.println("5- Delete a book."); System.out.println("6- Blow up library."); System.out.println("7- Back to main menu."); System.out.println("0- Exit."); System.out.println(">########################################################################"); System.out.println("> Enter your option here: "); choice = choiceInput.nextInt();//User inputs a choice (integer). } public String displayBook(){ String BookInfo = "----------------------------"+ " Title:.................."+title+ " Author:................."+author+ " Publisher:.............."+publisher+ " PublicationYear:........"+publicationYear+ " Status:................."+status+ " Borrower:..............."+borrower+ " Date Borrowed:.........."+borrowDate+ " Return date:............"+returnDate+ " ----------------------------"; return BookInfo; } public void createBook(){ System.out.println("> Enter the title of the book: "); title = userInput.nextLine(); System.out.println("> Enter the author of the book: "); author = userInput.nextLine(); System.out.println("> Enter the publisher of the book: "); publisher = userInput.nextLine(); System.out.println("> Enter the publication year of the book: "); publicationYear = userInput.nextLine(); borrower = "nobody"; borrowDate = "none"; returnDate = "none"; status = "Available"; } public void addBook(){ Book newBook = new Book(); //create new book object with status "Available." newBook.createBook(); BookList.add(newBook);//add the book to the BookList ArrayList. System.out.println("---------------------------------------------------------"); System.out.println("> You have successfully added the book to the library! "); System.out.println("---------------------------------------------------------"); } public void displayBookList(){ if (BookList.size() == 0){//If the library is empty, it goes back to main menu and choice. System.out.println(">-------------------------------------------------------------"); System.out.println("> There Library is Emply! Please add a book first! "); System.out.println(">-------------------------------------------------------------"); Book.displayFirstMenu();//Display to main menu. choice = choiceInput.nextInt();//Register new choice. } else { for (int i = 0; i