我刚刚完成了这个程序的熨烫,但我仍然遇到问题。每当我完成购买时,程序不仅会打印我购买的商品,还会打印我没有购买的商品。我该怎么做?我只想打印我买的那些。
import javax.swing.JOptionPane;
public class sto
{
public static void main(String args[])
{
char s;
do
{
int pcod=0, qua=0;
int[] cod={101,102,103,104,105,106,107,108,109,110};
double[] pri={22.20,5.50,55,18.50,18.50,250,14.80,23,16.50,30};
String[] pro={"Notebook","Ballpen","Ink","Eraser","Memo Pad","Staple","Pencil","Diskette","Ruler","Glue"};
double[] sal=new double[10];
int[] qu=new int[10];
do
{
pcod=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Product Code:"));
if(pcod>0&&pcod<101||pcod>110)
{
JOptionPane.showMessageDialog(null,"INVALID PRODUCT CODE");
}
else
if(pcod>=101||pcod<=110)
{
for(int i=0;i<10;i++)
{
if(pcod==cod[i])
{
qua=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter quantity:"));
sal[i]=pri[i]*qua;
qu[i]=qua;
}
}
}
}while(pcod!=00);
double tsal=0;
for(int d=0;d<sal.length;d++)
{
tsal+=sal[d];
}
JOptionPane.showMessageDialog(null,"Items Bought:");
for(int i=0;i<sal.length;i++)
{
JOptionPane.showMessageDialog(null,pro[i]+" "+qu[i]+"x ................"+sal[i]);
}
JOptionPane.showMessageDialog(null,"Total sales................"+tsal+" Pesos");
s=JOptionPane.showInputDialog(null,"Thank You!!\n\nShop Again?(Y/N)").charAt(0);
}
while(s=='y');
}
}