Can you help me with this??
The total will be displayed only when the user type -1.
And it will continue looping if you will not type -1.
And it will also continue to add the total(that will be displayed only if you type -1).
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Commission3{
public static void main(String args[]) {
String name, item, ans;
int choice=0, cnt=0,m1=2.93,m2=4.50,m3= 9.98,m4=4.49,m5=6.87;
int total=0,count=1, Quantity=0,z=0;
DecimalFormat twoDigits = new DecimalFormat("0.00");
while (choice!=-1) {
item=JOptionPane.showInputDialog("Product No. Retal Price\n"+
"\nProduct 1 $ 2.93"+
"\nProduct 2 $ 4.50"+
"\nProduct 3 $ 9.98"+
"\nProduct 4 $ 4.49"+
"\nProduct 5 $ 6.87"+
"\n\n Type -1 to show the Final Result"+
"\nEnter Product Number");
JOptionPane.showInputDialog("Quantity Sold fo the Product");
choice=Integer.parseInt(item);
switch(choice)
{
case 1:
z=m1*Quantity;
total += z;
count++;
break;
case 2:
z=m2*Quantity;
total += z;
count++;
break;
case 3:
z=m3*Quantity;
total += z;
count++;
break;
case 4:
z=m4*Quantity;
total += z;
count++;
case 5:
z=m5*Quantity;
total += z;
count++;
break;
}
total += z;
count++;
JOptionPane.showMessageDialog(null,"The total Retail Price is "+total,"RESULT",
JOptionPane.INFORMATION_MESSAGE);
}
if(choice==-1){
total +=choice;
count++;
JOptionPane.showMessageDialog(null,"The total Retail Price is "+total,"RESULT",
JOptionPane.INFORMATION_MESSAGE);
}
System.exit(0);
}
}