我一直很难做到这一点,我一直在寻找关于如何编码的想法,但我仍然是一个初学者。这是我的源代码。也许你会读到我的想法。它运行得并不如它应该的那样好。
import javax.swing.JOptionPane;
public class sto
{
public static void main(String args[])
{
char s;
do
{
int pcod=0, qua;
int[] cod={101, 102, 103, 104, 105, 106, 107, 108, 109, 110};
double[] pri={1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 0.1};
double [] sal=new double[10];
String[] pro={"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"};
do
{
if(pcod>=101||pcod<=110)
{
pcod=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Product Code:"));
for(int i=0;i<10;i++)
{
if(pcod==cod[i])
{
qua=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter quantity:"));
sal[i]=pri[i]*qua;
JOptionPane.showMessageDialog(null,"You bought:\n"+pro[i]+"......"+pri[i]+" Pesos x"+qua);
}
}
}
else
if(pcod<=101||pcod>=110)
JOptionPane.showMessageDialog(null,"INVALID PRODUCT CODE");
//some codes here to make you return to enter a product code again.
}while(pcod!=00);
for(int d=0;d<10;d++)
sal[d]=qua;
JOptionPane.showMessageDialog(null,"Total sales.........."+sal[d]+" Pesos");
s=JOptionPane.showInputDialog(null,"Shop Again?(Y/N)").charAt(0);
}
while(s=='y');
}
}