[Solved]Given Listitem Class Complete Main Using Built Linkedlist Type Create Linked List Called S Q37034760
Given a ListItem class, complete the main() using the built-inLinkedList type to create a linked list calledshoppingList. The program should read items frominput (ending with -1), adding each item to shoppingList, andoutput each item in shoppingList using the printNodeData()method.
Ex. If the input is
milkbreadeggswafflescereal-1
the output is
milkbreadeggswafflescereal
—————
ShoppingList.java
import java.util.Scanner;
import java.util.LinkedList;
public class ShoppingList {
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
// TODO: Declare a LinkedList called shoppingList of typeListItem
String item;
// TODO: Scan inputs (items) and add them to the shoppingListLinkedList
// Read inputs until a -1 is input
// TODO: Print the shoppingList LinkedList using theprintNodeData() method
}
}
—————–
*readable file only*
listitem.java
public class ListItem {
private String item;
public ListItem() {
item = “”;
}
public ListItem(String itemInit) {
this.item = itemInit;
}
// Print this node
public void printNodeData() {
System.out.println(this.item);
}
}
Expert Answer
Answer to Given a ListItem class, complete the main() using the built-in LinkedList type to create a linked list called shoppingLi… . . .
OR

