Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this side project. Any help would be appreciated. Working in Java. Attached at the bottom is the template file. I need

I need help with this side project. Any help would be appreciated. Working in Java. Attached at the bottom is the template file. I need the class template filled in according to the instructions provided.

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

BELOW IS THE TEMPLATE FILE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

image text in transcribed

BookReading Log UML Diagram: BookReading Log listHead: Book ReadNode list Tail: Book ReadNode numberOfBooksRead: int + Book Reading Log() + isReading LogEmpty(): boolean + getNumberOfBooksRead(): int + addBook (BookReadEntry bookEntryObj): boolean + removeBook (String bookTitle): BookReadEntry + findBook (String bookTitle): BookReadEntry + displayReading Log(): void + loadData(String filename): boolean + saveData(String filename): boolean Constructor: The BookReading Log class has only one constructor. public BookReadingLog() The default constructor ensures that all data member values are initialized as follows. The list head and list tail are both assigned to null. The number of books read is assigned to zero. Getters & Setters: The BookReadingLog class will have only one getter and no setters. The single getter for the class will return the current value of number of books read (i.e., the size of the singly linked list). BookReading Log Methods: The BookReading Log class has one additional method that is not an implementation for an abstract method. public boolean is ReadingLogEmpty() This method returns whether the log is currently empty. There are at least two ways to determine whether the list is empty, with the ideal one being testing whether the list head is null. The other option is testing whether the number of books read value is zero, however if this value is not updated correctly testing it could produce erroneous results. public boolean addBook (Book ReadEntry bookEntryObj) The addBook method will add a new book entry to the end of the singly linked list (technically it is adding a new book read entry). There are two cases to consider here. First, if the list is empty, the head and the tail will both point to the same thing. Otherwise, the new node in the linked list needs to be added at the tail end. This is an O(1) method. 1. Create a new BookReadNode and set the BookReadEntry parameter as its data 2. If the list is empty 3. Set both the head and tail to point to the new node 4. Else the list is not empty 5. Add the new node at the tail (this is two lines of code) 6. Increase the number of books that were read 7. Return true or false appropriately public BookReadEntry removeBook (String bookTitle) The removeBook method will remove a book read entry from the singly linked list based on the book title provided as the parameter. It must be an exact match for the remove to occur. If there are duplicates, only the first book that matches will be removed. If the book is in the list, then the entry that contains it will be returned, otherwise null is returned. This method requires two pointers (references) into the linked list to function correctly. There are also several special cases that need to be dealt with. This is an O(n) method. 1. Setup a current and previous pointer into the singly linked list. The current pointer will start at the list head. The previous pointer will start at null. 2. While searching for a match and the current pointer is not null 3. Get the BookReadEntry object at the current pointer location 4. If the BookReadEntry object is not null 5. Get the Book object out of the entry object 6. If the Book object is not null 7. Get the book title from the Book object 8. If the current title matches the book title parameter 9. Save the BookReadEntry object reference 10. If the current pointer is the list head 11. Update the list head to point to the next node 12. Else the node being removed is not the head 13. Update the previous pointer next link to point to the current pointer next link 14. If the removed node is the tail 15. Update the tail to point to the previous node 16. Decrease the number of books that were read 17. Indicate searching can stop 18. Update previous to point to current 19. Update current to point to the current next link 20. Return the removed BookReadEntry object or null Important: Testing a reference for null is a valuable skill to develop. If a reference is null and a method is called upon it, a NullPointerException will be thrown, causing the program to potentially crash or behave improperly. public BookReadEntry findBook (String bookTitle) The findBook method will attempt to find a book read entry based on the string name provided. It must be an exact match for the book to be found. If there are duplicates, only the first book that matches will be located. If the book was found, the method will return a reference to the BookReadEntry containing it, otherwise it will return null. This is performing linear/sequential search and it is an O(n) method. 1. Setup a current pointer into the singly linked list that starts at the list head. 2. While searching for a match and the current pointer is not null 3. Get the BookReadEntry object at the current pointer location 4. If the BookReadEntry object is not null 5. Get the Book object out of the entry object 6. If the Book object is not null 7. Get the book title from the Book object 8. If the current title matches the book title parameter 9. Save the BookReadEntry object reference 10. Indicate searching can stop 11. Update current to point to the current next link 12. Return the found BookReadEntry object or null public void displayReadingLog() The displayReading Log method will display the current state of the BookReading Log in a format similar to this when the log is empty: ** Displaying Books Read Log - oldest to Newest ** The Reading Log is Empty! And like this when there is data in the log: ** Displaying Books Read Log - Oldest to Newest ** 1. Watership Down by Richard Adams finished on 2017-02-18 at 10:01:21 and is owned 2. The Churn by James S.A. Corey finished on 2019-01-03 at 09:52:44 and is Not Owned 3. Six Wakes by Mur Lafferty finished on 2019-01-22 at 20:55:25 and is owned 4. Fuzzy Nation by John Scalzi finished on 2019-04-10 at 18:16:20 and is Not Owned Each BookReadEntry will indicate what number it is (starting at one) and what contents it contains. Each listing will be indented two spaces. The item number will be followed by the toString of the actual BookReadEntry stored in the log. The display order is chronologically oldest to newest, so the oldest finished book is displayed first and the most recently finished book is displayed last. This is exactly how the items are being stored in the singly linked list. This is an O(n) method. public boolean loadData(String filename) This method will load the data contained in the specified filename into the BookReading Log object. This is the algorithm for the method: 1. Create a File object based on the filename parameter 2. Try 3. Create a Scanner object opening with the File object as the parameter 4. Catch FileNotFoundException 5. Display an appropriate error message indicating what file could not be opened 6. Return false 7. While the file has a line to read 8. Read the line 9. Split the line based on the " ###" delimiter value (stored in variable lineValues) 10. Check if the line Values array has the correct number of items (12) 11. Check if the first item in line Values is "BOOK 12. Output a line starting with LOADING BOOK: " followed by the second element in line Values (the book title) 13. Attempt to locate the book in the reading log 14. If the book was found (non-null value returned) 15. Store the book object reference to use later 16. Else the book was not found 17. Create a new Book object with the correct split line values 18. Get a new instance of a Calendar object 19. Set the Calendar object fields to the correct values from the split line (YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND) 20. Create a new BookReadEntry object with the new book, new calendar, and ownership status from the split values 21. Call the addBook () method with the new BookReadEntry object 22. Else if not a book 23. Output this error message (it is two lines, second slightly indented): ERROR: Illegal Item Type! Item Type Ignored: 24. Else if line Values array is the incorrect size (not 12) 25. Output this error message (it is two lines, second slightly indented): ERROR: Illegal Line Format! Line Ignored: 26. Return true indicating that the values were loaded from the file, even if the file was empty or there were errors in the lines public boolean saveData(String filename) This method will save the current state (the BookReadEntry objects stored in the singly linked list) of the Book Reading Log object to a file specified by filename. This method overwrites the data already contained in the file. This is the algorithm for the method: 1. Create a File object based on the filename parameter 2. Try 3. Create a Print Writer object with the File object as the parameter 4. Catch general Exception 5. Display an appropriate error message indicating what file could not be created 6. Return false 7. For all BookReadEntry objects in the Book Reading Log singly linked list 8. Output a line starting with "SAVING BOOK: " followed by the title of the specific book being saved (not the entire toString) 9. Write the string returned from the toFileFormat () method to the file 10. Close the Print Writer object to finish writing to the file 11. Return true if the data was successfully written to the file or false if there were problems creating the file Note: The output from the load and save methods is really just for debugging purposes. Normally it would not be displayed in the final version of a program, although it might be generated and written to a file or there might be a way to trigger the output using the command line arguments. Note: All methods that are overridden or implemented from an interface need to be preceded with the @Override flag right before the method signature. /* * CS 310 Assignment 5 - Singly Linked Lists */ package cs310datastructures; import java.io.File; import java.io.FileNotFoundException; import java.io. PrintWriter: import java.util.Scanner; import java.util.Calendar; * @author TODO * @version TODO */ public class Book Reading Log The head node reference for the singly linked list */ private BookReadNode listHead; The tail node reference for the singly linked list */ private BookReadNode listTail; /* */ The number of items stored in the singly linked list private int numberOfBooksRead; Complete this class according to the Assignment 5 Specifications // TODO } BookReading Log UML Diagram: BookReading Log listHead: Book ReadNode list Tail: Book ReadNode numberOfBooksRead: int + Book Reading Log() + isReading LogEmpty(): boolean + getNumberOfBooksRead(): int + addBook (BookReadEntry bookEntryObj): boolean + removeBook (String bookTitle): BookReadEntry + findBook (String bookTitle): BookReadEntry + displayReading Log(): void + loadData(String filename): boolean + saveData(String filename): boolean Constructor: The BookReading Log class has only one constructor. public BookReadingLog() The default constructor ensures that all data member values are initialized as follows. The list head and list tail are both assigned to null. The number of books read is assigned to zero. Getters & Setters: The BookReadingLog class will have only one getter and no setters. The single getter for the class will return the current value of number of books read (i.e., the size of the singly linked list). BookReading Log Methods: The BookReading Log class has one additional method that is not an implementation for an abstract method. public boolean is ReadingLogEmpty() This method returns whether the log is currently empty. There are at least two ways to determine whether the list is empty, with the ideal one being testing whether the list head is null. The other option is testing whether the number of books read value is zero, however if this value is not updated correctly testing it could produce erroneous results. public boolean addBook (Book ReadEntry bookEntryObj) The addBook method will add a new book entry to the end of the singly linked list (technically it is adding a new book read entry). There are two cases to consider here. First, if the list is empty, the head and the tail will both point to the same thing. Otherwise, the new node in the linked list needs to be added at the tail end. This is an O(1) method. 1. Create a new BookReadNode and set the BookReadEntry parameter as its data 2. If the list is empty 3. Set both the head and tail to point to the new node 4. Else the list is not empty 5. Add the new node at the tail (this is two lines of code) 6. Increase the number of books that were read 7. Return true or false appropriately public BookReadEntry removeBook (String bookTitle) The removeBook method will remove a book read entry from the singly linked list based on the book title provided as the parameter. It must be an exact match for the remove to occur. If there are duplicates, only the first book that matches will be removed. If the book is in the list, then the entry that contains it will be returned, otherwise null is returned. This method requires two pointers (references) into the linked list to function correctly. There are also several special cases that need to be dealt with. This is an O(n) method. 1. Setup a current and previous pointer into the singly linked list. The current pointer will start at the list head. The previous pointer will start at null. 2. While searching for a match and the current pointer is not null 3. Get the BookReadEntry object at the current pointer location 4. If the BookReadEntry object is not null 5. Get the Book object out of the entry object 6. If the Book object is not null 7. Get the book title from the Book object 8. If the current title matches the book title parameter 9. Save the BookReadEntry object reference 10. If the current pointer is the list head 11. Update the list head to point to the next node 12. Else the node being removed is not the head 13. Update the previous pointer next link to point to the current pointer next link 14. If the removed node is the tail 15. Update the tail to point to the previous node 16. Decrease the number of books that were read 17. Indicate searching can stop 18. Update previous to point to current 19. Update current to point to the current next link 20. Return the removed BookReadEntry object or null Important: Testing a reference for null is a valuable skill to develop. If a reference is null and a method is called upon it, a NullPointerException will be thrown, causing the program to potentially crash or behave improperly. public BookReadEntry findBook (String bookTitle) The findBook method will attempt to find a book read entry based on the string name provided. It must be an exact match for the book to be found. If there are duplicates, only the first book that matches will be located. If the book was found, the method will return a reference to the BookReadEntry containing it, otherwise it will return null. This is performing linear/sequential search and it is an O(n) method. 1. Setup a current pointer into the singly linked list that starts at the list head. 2. While searching for a match and the current pointer is not null 3. Get the BookReadEntry object at the current pointer location 4. If the BookReadEntry object is not null 5. Get the Book object out of the entry object 6. If the Book object is not null 7. Get the book title from the Book object 8. If the current title matches the book title parameter 9. Save the BookReadEntry object reference 10. Indicate searching can stop 11. Update current to point to the current next link 12. Return the found BookReadEntry object or null public void displayReadingLog() The displayReading Log method will display the current state of the BookReading Log in a format similar to this when the log is empty: ** Displaying Books Read Log - oldest to Newest ** The Reading Log is Empty! And like this when there is data in the log: ** Displaying Books Read Log - Oldest to Newest ** 1. Watership Down by Richard Adams finished on 2017-02-18 at 10:01:21 and is owned 2. The Churn by James S.A. Corey finished on 2019-01-03 at 09:52:44 and is Not Owned 3. Six Wakes by Mur Lafferty finished on 2019-01-22 at 20:55:25 and is owned 4. Fuzzy Nation by John Scalzi finished on 2019-04-10 at 18:16:20 and is Not Owned Each BookReadEntry will indicate what number it is (starting at one) and what contents it contains. Each listing will be indented two spaces. The item number will be followed by the toString of the actual BookReadEntry stored in the log. The display order is chronologically oldest to newest, so the oldest finished book is displayed first and the most recently finished book is displayed last. This is exactly how the items are being stored in the singly linked list. This is an O(n) method. public boolean loadData(String filename) This method will load the data contained in the specified filename into the BookReading Log object. This is the algorithm for the method: 1. Create a File object based on the filename parameter 2. Try 3. Create a Scanner object opening with the File object as the parameter 4. Catch FileNotFoundException 5. Display an appropriate error message indicating what file could not be opened 6. Return false 7. While the file has a line to read 8. Read the line 9. Split the line based on the " ###" delimiter value (stored in variable lineValues) 10. Check if the line Values array has the correct number of items (12) 11. Check if the first item in line Values is "BOOK 12. Output a line starting with LOADING BOOK: " followed by the second element in line Values (the book title) 13. Attempt to locate the book in the reading log 14. If the book was found (non-null value returned) 15. Store the book object reference to use later 16. Else the book was not found 17. Create a new Book object with the correct split line values 18. Get a new instance of a Calendar object 19. Set the Calendar object fields to the correct values from the split line (YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND) 20. Create a new BookReadEntry object with the new book, new calendar, and ownership status from the split values 21. Call the addBook () method with the new BookReadEntry object 22. Else if not a book 23. Output this error message (it is two lines, second slightly indented): ERROR: Illegal Item Type! Item Type Ignored: 24. Else if line Values array is the incorrect size (not 12) 25. Output this error message (it is two lines, second slightly indented): ERROR: Illegal Line Format! Line Ignored: 26. Return true indicating that the values were loaded from the file, even if the file was empty or there were errors in the lines public boolean saveData(String filename) This method will save the current state (the BookReadEntry objects stored in the singly linked list) of the Book Reading Log object to a file specified by filename. This method overwrites the data already contained in the file. This is the algorithm for the method: 1. Create a File object based on the filename parameter 2. Try 3. Create a Print Writer object with the File object as the parameter 4. Catch general Exception 5. Display an appropriate error message indicating what file could not be created 6. Return false 7. For all BookReadEntry objects in the Book Reading Log singly linked list 8. Output a line starting with "SAVING BOOK: " followed by the title of the specific book being saved (not the entire toString) 9. Write the string returned from the toFileFormat () method to the file 10. Close the Print Writer object to finish writing to the file 11. Return true if the data was successfully written to the file or false if there were problems creating the file Note: The output from the load and save methods is really just for debugging purposes. Normally it would not be displayed in the final version of a program, although it might be generated and written to a file or there might be a way to trigger the output using the command line arguments. Note: All methods that are overridden or implemented from an interface need to be preceded with the @Override flag right before the method signature. /* * CS 310 Assignment 5 - Singly Linked Lists */ package cs310datastructures; import java.io.File; import java.io.FileNotFoundException; import java.io. PrintWriter: import java.util.Scanner; import java.util.Calendar; * @author TODO * @version TODO */ public class Book Reading Log The head node reference for the singly linked list */ private BookReadNode listHead; The tail node reference for the singly linked list */ private BookReadNode listTail; /* */ The number of items stored in the singly linked list private int numberOfBooksRead; Complete this class according to the Assignment 5 Specifications // TODO }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the difference between a phase and a microconstituent?

Answered: 1 week ago