Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These are the last two methods in a java programming assignment for singly-linked lists. There are multiple classes in the project. I just need some

image text in transcribed

image text in transcribedimage text in transcribed

These are the last two methods in a java programming assignment for singly-linked lists. There are multiple classes in the project. I just need some assistance setting this up (if/elses, loops, creating file objects, scanner objects, etc.). I can apply the necessary variables specific to my program, please just assist with the outline/general code setup. Tabs should correspond to the indents in the numbered instructions.

Thanks in advance!

Implemented DataFileOps Methods (Overridden): Tip: Implement these after you are sure that the rest of the class is working correctly. There are two methods in the DataFileOps interface that you will need to implement. When both of these work correctly, the data entered in the program will be persistent. This means every time the program is run, the data will remain from the previous session. The methods are already being called in the CS310Assignment5 class. 2. Try The data is stored in a file named "readinglogdata.txt" in a directory named "data" in the project directory structure. This is already created for you. Initially this file will be empty. The readinglogdata-backup.txt file contains a copy of some sample data that you can use when testing your program. It is encouraged for you to generate some of the file data manually. public boolean loadData(String filename) This method will load the data contained in the specified filename into the Book Reading Log object. This is the algorithm for the method: 1. Create a File object based on the filename parameter 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 line Values) 10. Check if the line Values array has the correct number of items (12) 11. Check if the first item in lineValues is BOOK" 12. Output a line starting with "LOADING BOOK: " followed by the second element in lineValues (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 Book ReadEntry 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 2. Try public boolean saveData (String filename) This method will save the current state (the BookReadEntry objects stored in the singly linked list) of the BookReadingLog 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 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 ReadingLog 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. Implemented DataFileOps Methods (Overridden): Tip: Implement these after you are sure that the rest of the class is working correctly. There are two methods in the DataFileOps interface that you will need to implement. When both of these work correctly, the data entered in the program will be persistent. This means every time the program is run, the data will remain from the previous session. The methods are already being called in the CS310Assignment5 class. 2. Try The data is stored in a file named "readinglogdata.txt" in a directory named "data" in the project directory structure. This is already created for you. Initially this file will be empty. The readinglogdata-backup.txt file contains a copy of some sample data that you can use when testing your program. It is encouraged for you to generate some of the file data manually. public boolean loadData(String filename) This method will load the data contained in the specified filename into the Book Reading Log object. This is the algorithm for the method: 1. Create a File object based on the filename parameter 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 line Values) 10. Check if the line Values array has the correct number of items (12) 11. Check if the first item in lineValues is BOOK" 12. Output a line starting with "LOADING BOOK: " followed by the second element in lineValues (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 Book ReadEntry 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 2. Try public boolean saveData (String filename) This method will save the current state (the BookReadEntry objects stored in the singly linked list) of the BookReadingLog 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 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 ReadingLog 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

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

Recommended Textbook for

A Complete Guide To Data Science Essentials

Authors: Miguel

1st Edition

9358684992, 978-9358684995

Students also viewed these Databases questions

Question

11. Are your speaking notes helpful and effective?

Answered: 1 week ago

Question

The Goals of Informative Speaking Topics for Informative

Answered: 1 week ago