Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA. Need an example of what this method looks like with syntax. Can use filler for variables not known as I have them and

IN JAVA. Need an example of what this method looks like with syntax. Can use filler for variables not known as I have them and can just swap them in.

image text in transcribed

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 Book ReadEntry 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 Book ReadEntry 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 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 Book ReadEntry 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 Book ReadEntry 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

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

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago