I'm trying to set up a constructor so that it asks how many items I have on a grocery list. Based on the number that's entered, a loop will run that many times. With each iteration of the loop, it will ask for the name, price, and taxable status of the item. I've set up my code below, but I keep getting the following error:
Constructor in class cannot be applied to given type. Required: int; found:java.lang.String,int,java.lang.String; Reason: actual and formal argument lists differ in length.
Is there a way to set up the constructor and array list so that they accept both int and String types?
public class Item
{
// instance variables - replace the example below with your own
private ArrayList<Item> items;
private int numberofItems;
private int count;
private String itemName;
private int cost;
private String taxable;
/**
* Constructor for objects of class Item
*/
public Item(int numberofItems)
{
items=new ArrayList<>();
this.numberofItems = numberofItems;
}
/**
* adds items to the arrayList
*/
public Item addItems(String itemName, int cost, String taxable)
{
for (count =0; count <= numberofItems; count++); {
items.add(new Item(itemName,cost, taxable));
}
}
// /**
// * Adds an item to the ItemList
// */
// public void addItem(String itemName, int cost, String taxable)
// {
// items.add(new ItemList(itemName, cost, taxable));
}