Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In JAVA, write a class ToDoList with the following Internal class ListNode which has Instance Variables data of type String link of type ListNode Constructors
In JAVA, write a class ToDoList with the following
Internal class ListNode which has
Instance Variables
data of type String
link of type ListNode
Constructors
Default
Parameterized
Instance Variables
head: a ListNode which always points to the beginning of the linked list
current: a ListNode which moves to point at different items in the list
previous: a ListNode which points to the item behind current.
Constructor
A default constructor that initializes head to an empty ListNode and sets current and previous to point at the head.
Methods
goToNext: This moves the current node forward in the list by one node. It doesnt move forward if that node is null
gotoPrev: This moves the current node backwards in the list by one node. It does not move backwards if the current node is the head.
getDataAtCurrent: returns the data at the current node as long as the current isnt null
setDataAtCurrent: takes in a parameter of type String and sets the data at the current node to that value as long as current is not null
addItem: This method adds a new node at the end of the list (HINT: Look for first null element using a loop). If the list is empty (thus head is null) then it starts the list.
insertAfterCurrent: creates a new node based on data that is passed in by a parameter and puts that node after the current position
deleteCurrentNode: removes the current node from the list by resetting the links
showList: prints out the contents of the list line-by-line
Finally write a driver that implements an instance of TodoList and demonstrates each of the methods work.
Example Dialog:
To Do List Tester!
Adding Five Tasks To Do
Printing List
1. Buy Ground Beef
2. Buy Cheese
3. Buy Taco Shells
4. Make Tacos
5. Eat Tacos
I forgot to get salsa. Let me add that after step 2.
Printing List
1. Buy Ground Beef
2. Buy Cheese
3. Buy Salsa
4. Buy Taco Shells
5. Make Tacos
6. Eat Tacos
On second thought Im in a spicy mood so lets change salsa to hot sauce.
Printing List
1. Buy Ground Beef
2. Buy Cheese
3. Buy Hot Sauce
4. Buy Taco Shells
5. Make Tacos
6. Eat Tacos
Do people put guacamole on tacos? Ill add it after step 3.
Printing List
1. Buy Ground Beef
2. Buy Cheese
3. Buy Hot Sauce
4. Buy Guacamole
5. Buy Taco Shells
6. Make Tacos
7. Eat Tacos
On second thought I dont think they do let me take that out.
1. Buy Ground Beef
2. Buy Cheese
3. Buy Hot Sauce
4. Buy Taco Shells
5. Make Tacos
6. Eat Tacos
Now I have tested the perfect taco related list!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started