Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Single Linked List (Java assignment ) Today's you will write a program with three classes, the first class will be the driver, second will be

Single Linked List (Java assignment )

Today's you will write a program with three classes, the first class will be the driver, second will be the LinkedList class, and the third will be the Node class that will be holding the data.

The first class, Driver class will just create an instance of the Linked List class and then control the flow of the program.

The Second class with be the Node class, this is where you store each individual Student's name which is your data, it will have:

Two private variables (no need for a new class, just put the name in the Node class):

A String to hold the name of the student

Node next

A setNext() method that will allow you to set the reference of the instance variable next.

A getNext() method that will return the Item that next is referencing.

A toString() method to print out the name of the student

A getName() to return the name for comparison

All names will be initialized in constructor and you don't need methods to change them, just retrieve them for printing or searching.

The second class will be the class that manages the linked list that is made up of the Node objects. The LinkedList Class will contain:

An instance field Node reference to the first Node object in the list. (starts null for empty list)

Then you will need methods for handling all the menu choices in the driver.

Note: After you get one of the print or delete methods working the traversal is the same for both of them.

All items will be added to the end of the list, not the front.

Clear the list is just setting the correct reference to null, very simple. all of the other methods I did on the board.

The third class is the Driver, just like my example, should contain:

A menu that calls a method that is an infinite do/while loop until the user gives -1 to exit.

Inside the loop you should print a menu and then wait for user input.

Methods for printing the menu:

What would you like to do? Press 1 to add an item to the back of the list Press 2 to print the list Press 3 to delete an item Press 4 to clear the whole list Press -1 to exit 

The input from the user should go into a switch statement that switches for each input:

case 1:

linkedlist.addItem(node);

. The menu method should consistently run until the user gives a -1.

You are to implement a linked list of the Node objects. Singular linked list. Assume new objects are always added to the back of the list.

Make sure you handle special cases such as adding an item to an empty list, deleting the first, etc. etc.

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago

Question

2. What, according to Sergey, was strange at this meeting?

Answered: 1 week ago