Need help solving this issue.   ShoppingList Class   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 type ListItem LinkedList shoppingList = new LinkedList(); String item; // TODO: Scan inputs (items) and add them to the shoppingList LinkedList // Read inputs until a -1 is input item = scnr.next(); while (!item.equals("-1")) { shoppingList.add(item); item = scnr.next(); } // TODO: Print the shoppingList LinkedList using the printNodeData() method for (int i = 0; i < shoppingList.size(); i ++) { ListItem list = new ListItem(); list.listItem(); list.printNodeData(); } } }   ListItem Class     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); } }   ListItem Class   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); } }       I am able to add the items to the shopping list but I have been stuck on trying to print the list using the printNodeData method that is in the ListItem class.   Current Error Mesage on Run   ShoppingList.java:29: error: cannot find symbol list.listItem(); ^ symbol: method listItem() location: variable list of type ListItem 1 error

Question

Need help solving this issue.

 

ShoppingList Class

 

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 type ListItem

LinkedList<String> shoppingList = new LinkedList<String>();

String item;

// TODO: Scan inputs (items) and add them to the shoppingList LinkedList
// Read inputs until a -1 is input

item = scnr.next();
while (!item.equals("-1")) {
shoppingList.add(item);
item = scnr.next();
}


// TODO: Print the shoppingList LinkedList using the printNodeData() method

for (int i = 0; i < shoppingList.size(); i ++) {
ListItem list = new ListItem();
list.listItem();

list.printNodeData();
}

}
}

 

ListItem Class

 

 

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);
}
}

 

ListItem Class

 

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);
}
}

 

 

 

I am able to add the items to the shopping list but I have been stuck on trying to print the list using the printNodeData method that is in the ListItem class.

 

Current Error Mesage on Run

 

ShoppingList.java:29: error: cannot find symbol
list.listItem();
^
symbol: method listItem()
location: variable list of type ListItem
1 error

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: What is the Meaning of SCROLLLOCK_ON?

A: SCROLLLOCK_ON When the scroll lock mode is on, then the arrow keys would scroll the contents of a t...

Q: Briefly explain microprogram

A: Here we are discussing about the microprogram. Here we have disussed some important point about the ...

Q: What do you call the constructor that is provided by the compiler, if no constructor is specified wh...

A: If no constructor is specified when a class is written then compiler provides default constructor. T...

Q: . What is the purpose of the “C” specifier in the extern declaration in procedures called fromC++?

A: The "C" specifier in the extern declaration tells the C++ compiler that there is a function which wa...

Q: True or False To append data to an existing file, you open it with the File.AppendText method.

A: File.AppendText(string) method is used to append UTF-8 encoded text to an existing or a new file. Th...

Q: please solve this in python

A: 1. We ask for the number of inputs from the user to add to the dictionary. 2. We ask for the key and...

Q: use c code to Develop a function void printToggled(char str[]) that gets a string as a parameter and...

A: Conversion of string from lower case into upper case: 1. Check if the string characters are in lower...

Q: COSC 1336 – ProgrammingFundamentals I Python Programming Write a class named RetaiI_Item that holds ...

A: We are using following information: Initial InventoryItem Number Description Units in Inventory Pri...

Q: Write a program in C++ that asks the user how many numbers she would like to compare; Then accepts t...

A: The following algorithm is required for writing the program to find the smallest, largest from given...