Hi! I'm making a code right now but I don't know how to continue.....my problem is that I have to make an online shopping list...first, data will be shown to the viewer or buyer...i've done that already. next the buyer should enter the itemID then the number of pieces of the particular item that matches the itemID to be bought is asked...i've also done that. now, after entering the input the prices of the items should be totaled and the the output should look like this:

itemID Units (quantity-number of items) Price
0220 2 650
0280 1 750

Total: 2050

i'm almost there....but my problem is how will I add all the items and I also don't know how to code that the itemID is equivalent to that item/product and is equivalent to that price.

hope you can help me....thank you!

here's the code I've done so far....

import javax.swing.JOptionPane;


public class ShoppingCart {
	
public static void main(String[] args) {
		
		String inputstr;
		
		JOptionPane.showMessageDialog 
	    (null, "ItemID" + "\t" + "     Description" + "\t" + "                           Price" + "\t" + "             Units" + "\n" +
	           "0220" + "\t" + "        Rolling Stones CD" + "\t" + "              650 Php" + "\t" + "            3" + "\n" +
	           "0280" + "\t" + "        Maroon 5 CD" + "\t" + "                       750 Php" + "\t" + "            1" + "\n" +
	           "0320" + "\t" + "        Paramore CD" + "\t" + "                      650 Php" + "\t" + "            2" + "\n" +
	           "0380" + "\t" + "        McFly CD" + "\t" + "                              580  Php" + "\t" + "           4" + "\n" +
	           "0420" + "\t" + "        Busted CD" + "\t" + "                           570 Php" + "\t" + "            5");
		
		
		inputstr = JOptionPane.showInputDialog("Enter ItemID: ");
		int input = Integer.parseInt(inputstr);
		
		String[] pieces = new String[input];
		
		for(int i=0;i<input; i++){
		
			pieces[i] = JOptionPane.showInputDialog("Enter No. of Pieces "+ (i+1));
			JOptionPane.showMessageDialog 
		    (null, "ItemID" + "\t" + "     Description" + "\t" + "                           Price" + "\t" + "             Units" + "\n" +
		           "0220" + "\t" + "        Rolling Stones CD" + "\t" + "              650 Php" + "\t" + "            3" + "\n" +
		           "0280" + "\t" + "        Maroon 5 CD" + "\t" + "                       750 Php" + "\t" + "            1" + "\n" +
		           "0320" + "\t" + "        Paramore CD" + "\t" + "                      650 Php" + "\t" + "            2" + "\n" +
		           "0380" + "\t" + "        McFly CD" + "\t" + "                              580  Php" + "\t" + "           4" + "\n" +
		           "0420" + "\t" + "        Busted CD" + "\t" + "                           570 Php" + "\t" + "            5");
			
			inputstr = JOptionPane.showInputDialog("Enter ItemID: ");
			int input1 = Integer.parseInt(inputstr);
		}
		
		if (inputstr = )
		
		
	}

}

by the way...my classmate said I should use if-else so that the itemID the buyer will enter will be equivalent to the product and price given but I don't know how to start the loop....

thank you so much! ^_^

The syntax for comparing a string to several values to see which one matches is something like this:

if (input.equals(value1)) {
   // handle value 1 here
} else if (input.equals(value2)) {
   // handle value 2 here
} else if (input.equals(value3)) {
   // handle value 3 here
}  // ... etc.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.