Hello I am trying to create a Java Application where the user enters the quantity of items from a catalogue and the price of each item. The application should display the total cost of the required items. The user can purchase more than one item at a time.
If they receive a 11% discount if they buy 5 or more of an item.
The problem is the the loop only allows you enter in the quantity of items and when you quit it will not display the total for the customer.
I have only started learning Java a few months ago. I used a tutorial where you have one input dialog box as a basis for the code below, but I am not sure how I can get the loop to work and display the results with two input dialog boxes. tried everything I know. If anyone I can help I would appreciate. Thanks.
package loop; import java.text.DecimalFormat; import javax.swing.JOptionPane; public class Loop { /** * @param args the command line arguments */ public static void main(String[] args) { int itemCounter, itemValue, itemQuantity, total, discount; itemCounter=0; itemValue =0 ; itemQuantity=0; total=0; String valueStr, shoppingStr, quantityStr; while (itemCounter !=-1){ total= itemQuantity * itemValue; itemCounter+=itemCounter; quantityStr = JOptionPane.showInputDialog("enter item quantity or -1 to quit"); itemQuantity = Integer.parseInt(quantityStr); valueStr = JOptionPane.showInputDialog("enter item quantity or -1 to quit"); itemValue = Integer.parseInt(valueStr); } DecimalFormat twoDigits = new DecimalFormat ("0:00"); if (itemCounter >=5) { discount = (int) (total * 0.11); } else { discount = 0; } JOptionPane.showMessageDialog (null, "the total cost is "+twoDigits.format(discount)); } }