Question: You will be writing a WordNode class to create a Linked List of WordNodes. (1) Complete the WordNode class per the following specifications: Private class

You will be writing a WordNode class to create a Linked List of WordNodes.

(1) Complete the WordNode class per the following specifications:

  • Private class attributes
    • String element
    • class reference for a next node,
  • Public methods:
    • Constructors: empty and non-empty parameter list - (1 pt each)
    • insertAfterHead() - (1 pt)
    • getData()
    • getNext()
    • printNodeData()

(2) In the Main class, complete the two TODO sections to add a node after the head node and print the data for all of the nodes in the linked list.

When the input is:

5 Strawberry Cloud Bird Table Walk 

The output should be:

The words in the list are: Walk Table Bird Cloud Strawberry

import java.util.Scanner;

public class Main {

public static void main(String[] args) { Scanner scnr = new Scanner(System.in);

WordNode headNode; WordNode currNode;

// Front of nodes list, the head node doesn't store any data // and is known as a dummy node headNode = new WordNode();

int input = scnr.nextInt(); scnr.nextLine();

for (int i = 0; i < input; i++) { // TODO: read the users input, create a new Node storing the users input, and // insert the new node after the head node } System.out.println(); System.out.println("The words in the list are:"); // TODO: Iterate through the list to print the linked list, // DO NOT Print the dummy head node }

}

-Other class

public class WordNode {

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!