Starting from:
$29.99

$23.99

Lab 03 To Do List Solution

Objective:

 

Implement a system that keeps tracks of tasks you have to do!

 

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 doesn’t 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 isn’t 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 GroceryList 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 I’m in a spicy mood so let’s 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? I’ll 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 don’t 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!

 
Lab Report Questions:

Name some advantages of using a linked list instead of an array.
Name some disadvantages of using a linked list instead of an array.
Finally:

Upload the .java file to the dropbox

 

More products