I'm having trouble with the enterItemInfo() method at the bottom of the block. I want a user to input an item name, and an item price right after, and loop through a number of times equal to itemNames.length. The problem I'm having is that when I run this method, it somehow skips right to the second input, and then any input given results in an error. Not sure where I'm going wrong here.
import java.util.Scanner;
public class Item {
//FIELDS
private int itemAmount;
private String[] itemNames;
private double[] itemPrices;
Scanner item = new Scanner(System.in);
public int getItemAmount() {
return this.itemAmount;
}
public void setItemAmount() {
System.out.println("Please enter the number of items: ");
this.itemAmount = item.nextInt();
System.out.print("There are " + this.itemAmount + " items.");
}
public void enterItemInfo() {
itemNames = new String[this.itemAmount];
for (int i = 0; i < itemNames.length; i++) {
System.out.println("Enter the next item name: ");
itemNames[i] = item.nextLine();
System.out.println("Enter the price for " + itemNames[i] + ": ");
itemPrices[i] = item.nextDouble();
item.nextLine();
}
}
}