Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

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

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

What have you done that shows initiative and willingness to work?

Answered: 1 week ago

Question

Explain how cultural differences affect business communication.

Answered: 1 week ago

Question

List and explain the goals of business communication.

Answered: 1 week ago