记录产品订购

时间:2011-08-23 03:54:42

标签: java

所以我的第一个问题已修复:CLICK HERE 感谢seanA的快速反应...

我现在的第二个问题是我不知道如何记录买方订购的数据 所以在最终订单显示中它将显示如下内容: CLICK TO VIEW

这是PointofSale类的更新代码 建议添加方法或任何需要的东西:)提前致谢

import java.util.*;
public class PointOfSale extends ProductDisplay
{   public double amount; public double total;
    public PointOfSale()
    {   System.out.print("\nPurchase Item(y/n)?:\t\t");
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        if("y".equalsIgnoreCase(line)){
        OpenOrder();
            }
    }
    //=============================================
    public void OpenOrder() // New Order
    {   ArrayList<String> ProductList = new ArrayList<String>();
        ProductList.add("A001");    ProductList.add("A002");
        ProductList.add("A003");    ProductList.add("A004");
        ProductList.add("A005");
        System.out.print("Enter Product Code:\t\t");
        Scanner sc = new Scanner(System.in);
        String code = sc.next();
        if(ProductList.contains(code))
        { product.getProduct(code); EnterQuantity();        }
        else System.out.print("Product Code is Invalid\n"); System.exit(0);}
    //==============================================
    public void EnterQuantity()  //Entering Quantity
    {
        try{
            System.out.print("Enter Quantity:\t\t\t");
            Scanner sc = new Scanner(System.in);
            int quantity = sc.nextInt();
            amount = quantity * product.getPrice();
            total = total + amount;
            System.out.print("Amount:\t\t\t\t\t" + amount + "\n");
            AddItem(); }
        catch (InputMismatchException nfe)
            {System.out.print("\nInvalid Entry: Input must be a Number.\n"); System.exit(0);}
    }
    //==============================================
    public void AddItem()  //Adding Item
    {
        try{
            System.out.print("Add More Item(y/n)?:\t\t\t");
            Scanner sc = new Scanner(System.in);
            String item = sc.next();
            if("y".equalsIgnoreCase(item)){
            OpenOrder();}
            else if("n".equalsIgnoreCase(item)){
            System.out.print("Total:\t\t" + total + "\n");}
            }
        catch (InputMismatchException nfe)
            {System.out.print("\nInvalid Entry: Input must be a Number.\n"); System.exit(0);}
    }
    // Main Method
    public static void main(String[] args)
    {   new PointOfSale(); }
}

1 个答案:

答案 0 :(得分:0)

您需要存储在数组中输入的数据或使用java.util.Vector。

使用for循环以您想要的形式显示它

我希望它有所帮助。

:)