Question: In Java. Code won't run get this error message. Only the ItemNode class can be edited . Not the ShoppingList class . import java.util.Scanner; public

In Java. Code won't run get this error message. Only the ItemNode class can be edited. Not the ShoppingList class.

In Java. Code won't run get this error message. Only the ItemNode

import java.util.Scanner;

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

ItemNode headNode; // Create intNode objects ItemNode currNode; ItemNode lastNode;

String item; int i;

// Front of nodes list headNode = new ItemNode(); lastNode = headNode;

int input = scnr.nextInt();

for(i = 0; i

// Print linked list currNode = headNode.getNext(); while (currNode != null) { currNode.printNodeData(); currNode = currNode.getNext(); } } }

----------------------

public class ItemNode {

private String item; private ItemNode nextNodeRef;

public ItemNode() {

item = "";

nextNodeRef = null;

}

public ItemNode(String itemInit) {

this.item = itemInit;

this.nextNodeRef = null;

}

public ItemNode(String itemInit, ItemNode nextLoc) {

this.item = itemInit;

this.nextNodeRef = nextLoc;

}

public void insertAfter(ItemNode nodeLoc) {

ItemNode tmpNext;

tmpNext = this.nextNodeRef;

this.nextNodeRef = nodeLoc;

nodeLoc.nextNodeRef = tmpNext;

}

public void insertAtEnd(String value, ItemNode lastNode){

ItemNode aux = this.nextNodeRef;

if (aux == null){

aux = new ItemNode(value); this.nextNodeRef=aux; lastNode=aux; return;

}

while (aux.getNext() != null){

aux = aux.getNext();

}

setNext(aux, value); lastNode=aux.getNext();

}// TODO: Define insertAtEnd() method that inserts a node

public void setNext(ItemNode node, String value) {

node.nextNodeRef = new ItemNode(value);

}

public ItemNode getNext() {

return this.nextNodeRef;

}

public void printNodeData() {

System.out.println(this.item);

}

}

ShoppingList.java:23: error: incompatible types: ItemNode cannot be converted to string lastNode.insertAtEnd(headNode, currnode); Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error

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!