No response.

I'm currently working on a simple program that takes user input to create a gorcery list with prices and item names. It's not giving me any error codes when I run but rather nothing is appearing. I'll attach a photo below.
No description
16 Replies
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @rainymc_! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
rainymc_
rainymc_OP3mo ago
No description
lisan
lisan3mo ago
how do you want to take item if your itemNames has 0 elements so size is 0
rainymc_
rainymc_OP3mo ago
so should i keep it at a set amount or ask the user for the amount of items beforehand and set that to the size?
lisan
lisan3mo ago
u can even do while true, and if user wants to finish shopping he should write for example finish.
if (item.equals("finish")) break;
if (item.equals("finish")) break;
rainymc_
rainymc_OP3mo ago
No description
rainymc_
rainymc_OP3mo ago
Would this work? I've tried running and am now getting a seperate problem
rainymc_
rainymc_OP3mo ago
No description
Carter
Carter3mo ago
look up how to take in a Double it should be scanner.nextDouble() you're calling scanner.next()
rainymc_
rainymc_OP3mo ago
Sorry for not updating the screenshot, I did notice that and fixed it earlier
lisan
lisan3mo ago
write this code here, on chat
john
john3mo ago
import java.util.Scanner; import java.util.ArrayList;
public class TotalPrice{
public static void main(String[] args) {
Scanner inpt = new Scanner(System.in);

ArrayList<String> itemNames = new ArrayList<String>();
ArrayList<Double> itemPrices = new ArrayList<Double>();

for (int i = 0; i < itemNames.size(); i++) {
String item = inpt.nextLine();
System.out.println("Please type in the name of the item you would like to purchase: ");
itemNames.add(item); //itemNames.add....system.in
Double price = inpt.nextBoolean();
System.out.println("Please type in the price of the item: ");
itemPrices.add(price);
if (item.equals("finish")) break;
else {
System.out.println("Error, please retype.");
}

}
}






}
public class TotalPrice{
public static void main(String[] args) {
Scanner inpt = new Scanner(System.in);

ArrayList<String> itemNames = new ArrayList<String>();
ArrayList<Double> itemPrices = new ArrayList<Double>();

for (int i = 0; i < itemNames.size(); i++) {
String item = inpt.nextLine();
System.out.println("Please type in the name of the item you would like to purchase: ");
itemNames.add(item); //itemNames.add....system.in
Double price = inpt.nextBoolean();
System.out.println("Please type in the price of the item: ");
itemPrices.add(price);
if (item.equals("finish")) break;
else {
System.out.println("Error, please retype.");
}

}
}






}
This message has been formatted automatically. You can disable this using /preferences.
lisan
lisan3mo ago
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

ArrayList<String> itemNames = new ArrayList<>();
ArrayList<Double> itemPrices = new ArrayList<>();

while (true) {
System.out.println("Please type in the name of the item you would like to purchase or finish: ");
String item = scanner.nextLine();
if (item.equals("finish")) {
break;
} else {
itemNames.add(item);
System.out.println("Please type in the price of the item: ");
Double price = scanner.nextDouble();
scanner.nextLine();
itemPrices.add(price);
}
}
System.out.println(itemNames);
System.out.println(itemPrices);

}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

ArrayList<String> itemNames = new ArrayList<>();
ArrayList<Double> itemPrices = new ArrayList<>();

while (true) {
System.out.println("Please type in the name of the item you would like to purchase or finish: ");
String item = scanner.nextLine();
if (item.equals("finish")) {
break;
} else {
itemNames.add(item);
System.out.println("Please type in the price of the item: ");
Double price = scanner.nextDouble();
scanner.nextLine();
itemPrices.add(price);
}
}
System.out.println(itemNames);
System.out.println(itemPrices);

}
JavaBot
JavaBot3mo ago
If Scanner#nextLine reads an empty line after calling a different Scanner#next method, take a look at this StackOverflow post.
dan1st
dan1st3mo ago
You'll also run into this problem
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server