我对编程很陌生,而且我很难找出某个问题。
我在我的基本POS java项目中有一个“添加订单”功能,但是一旦我从另一个列表中添加另一个订单,收据中显示的唯一一个是我订购的最后一个订单。
所以这里只是我的代码的示例:
System.out.println("--------------------------------------");
System.out.println("Your order(s): ");
System.out.println(order+" x "+howmany+" = P "+tempBill);
System.out.println("--------------------------------------");
// STORE IN A HOLDER VARIABLE IN CASE OF ADDING ORDERS
ordery[i2] = order;
tempBilly[i2] = tempBill;
howmanyarray[i2] = howmany;
i2++;
// CHOOSING IF ADD MORE ORDER OR PROCEED TO PAYMENT
System.out.println("What do you wish to do after this?");
System.out.println("[1] Add Order\n[2] Proceed to Payment\n[3] Cancel ");
do
{
System.out.print("Enter the number of your choice: ");
choice2 = input.nextInt();
if (choice2==1) {
readMain();
}
else if (choice2==2)
{
System.out.println("--------------------------------------");
System.out.println("ITEM(S) ORDERED: ");
for (a = 1; a < i2; a++) {
System.out.println(ordery[a]+" x "+howmanyarray[a]+" = P "+tempBilly[a]);
totalBill = totalBill + tempBilly[a];
}
System.out.println();
do
{
System.out.print("Enter amount of cash for payment: ");
cash = input.nextDouble();
if (cash>=totalBill) {
System.out.println();
System.out.println("xxxxxxxxx OFFICIAL RECEIPT xxxxxxxxx");
System.out.println("ORDER(S):");
System.out.println(" • "+order+" x "+howmany);
System.out.println("TOTAL BILL: P "+totalBill);
System.out.println("AMOUNT PAID: P "+cash);
System.out.println("CHANGE: P "+bills.change(cash, totalBill));
PrintWriter resibo = new PrintWriter(new FileWriter("resibo.txt", true));
Date dt = new Date();
resibo.write("xxxxxxxxx OFFICIAL RECEIPT xxxxxxxxx\n");
resibo.write(dt.toString());
resibo.write("\nORDER(S):\n");
resibo.write(" • "+order+" x "+howmany+"\n");
resibo.write("TOTAL BILL: P "+totalBill+"\n");
resibo.write("AMOUNT PAID: P "+cash+"\n");
resibo.write("CHANGE: P "+bills.change(cash, totalBill));
resibo.write("\n\n");
resibo.close();
System.out.println("--------------------------------------");
System.out.println("THANK YOU! PLEASE COME AGAIN!");
System.out.println("--------------------------------------");
System.out.println();
read.close();
String[] str = null;
try2.main(str);
}
}
while (cash<totalBill || cash<0);
}
else if (choice2==3){
try2.customer();
}
}
while (choice2>3 || choice2<=0);
以下是示例输出的图像:output
我尝试从饮料清单中订购冰沙然后继续付款,付款后应该显示我订购的两件物品,但它只显示我订购的最后一件(冰沙)。这是图片或收据:receipt
请帮助我。谢谢。