What's wrong with this code???? | Sololearn: Learn to code for FREE!

+2

What's wrong with this code????

class GroceryItem { public static void main(String[] args) { display String, name,price,total amount ; System.out.println("Enter 5 names of item and prices: "); ("milk",20); ("butter",50); ("eggs",189); ("bread",100); ("tuna",130); int i = 0; while (i < 5) { prices[i] = in.nextDouble(); i++; } double total = 0.00; for (double amount : prices) { total += amount; } System.out.printf("("Enter 5 names of item and prices:"); } }

11/30/2021 7:31:05 AM

Mirasol Sontousidad

16 Answers

New Answer

+6

import java.util.Scanner; class GroceryItem { public static void main(String[] args) { System.out.println("Item: price\n=========== "); System.out.println("milk : 20 \nbutter : 50 \neggs : 189 \nbread : 100 \ntuna : 100\n"); double[] prices = new double[5]; Scanner in = new Scanner(System.in); int i = 0; while (i < 5) { prices[i] = in.nextDouble(); i++; } double total = 0.0; for(double amount : prices) total += amount; for (double amount : prices) System.out.println(amount); System.out.println("\n"+total+" is Total price") ; } }

+3

What are these statements in your program? It's no meaning and invalid .. 1) display String, name,price,total amount ; 2) ("milk",20); ("butter",50); ("eggs",189); ("bread",100); ("tuna",130); ? what are you trying with these there?

+1

The should be display the name of items, price, and the total amount of grocery item

+1

The output should be be display the name of items, price, and the total amount of grocery item

+1

import java.util.Scanner; class GroceryItem { public static void main(String[] args) { display String, name,price,total amount ; System.out.println("Enter 5 names of item and prices: "); System.out.println("Item: price\n=========== ") ; System.out.println("milk : 20 "+"\n"+ "butter : 50" +"\n"+ "eggs : 189 \n"+ "bread : 100"+"\n"+ "tuna : 100"); for (double amount : prices) System.out.println(amount) ; System.out.println("Total price : " + total) ; Before these, initialize price[] array and "in" object as double[] price = new double[5]; Scanner in = new Scanner(System.in); } } Error again

+1

My post has suggestions to implement correct code .. Read again.. Try those.. If you not understand any then reply for that specific details...

+1

Sorry for the joke 😂😅 Cause the problem looked too simple I can't stop myself from laughing 😂🤣🤣😅

+1

By the way , Jayakrishna🇮🇳 how can you behave like a JVM ?

+1

Ash(Back In Original Form) "Like a JVM" what it means?

+1

Hi I know nothing about coding , please anyone explain

0

Can anyone help me

0

Oh seems like I arrived to strike this problem with the sword of java at time 😤 So let's finish this problem in another blink of an eye 😼😉

0

Here is a video about how to do it https://r.mtdv.me/9B22gtrUZd} Pause on minute 1:22 for seeing the full code (also on description it says about) (I created the video so that's why it's in a different platform

0

Tap Try it yourself to see the whole program in action.

-1

What's wrong with this code???? class GroceryItem { public static void main(String[] args) { display String, name,price,total amount ; System.out.println("Enter 5 names of item and prices: "); ("milk",20); ("butter",50); ("eggs",189); ("bread",100); ("tuna",130); int i = 0; while (i < 5) { prices[i] = in.nextDouble(); i++; } double total = 0.00; for (double amount : prices) { total += amount; } System.out.printf("("Enter 5 names of item and prices:"); } }

-2

1) Is it menu of items with price? solution: System.out.println("Item: price\n=========== ") ; System.out.println("milk : 20 "+"\n"+ "butter : 50" +"\n"+ "eggs : 189 \n"+ "bread : 100"+"\n"+ "tuna : 100"); 2) May you trying to display prices and total ? solution: for (double amount : prices) System.out.println(amount) ; System.out.println("Total price : " + total) ; Before these, initialize price[] array and "in" object as double[] price = new double[5]; Scanner in = new Scanner(System.in); Mirasol Sontousidad And import scanner as: import java.util.Scanner; 'Name of the items', you are not taking any input for this..! try all these.. and reply with code if anything going wrong..! hope it helps..