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.
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 errorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started