Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 订购录音制品_Java - Fatal编程技术网

Java 订购录音制品

Java 订购录音制品,java,Java,因此,我的第一个问题已在此处解决: 感谢seanA的快速响应 我现在的第二个问题是,我不知道如何记录买家订购的数据 因此,在最终订单显示中,它将显示如下内容: 下面是类PointofSale的更新代码 如果需要,建议添加方法或任何东西:提前感谢 import java.util.*; public class PointOfSale extends ProductDisplay { public double amount; public double total; public

因此,我的第一个问题已在此处解决: 感谢seanA的快速响应

我现在的第二个问题是,我不知道如何记录买家订购的数据 因此,在最终订单显示中,它将显示如下内容:

下面是类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(); }
}

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

使用for循环以所需的形式显示它

我希望有帮助


您是否尝试解决此问题?如果是,在哪里?如果没有,你应该将问题分解成更小的步骤,并尝试一次解决一个步骤。帕特里夏·沙纳汉(Patricia Shanahan)提供了一个有用的参考资料,可以帮助完成这一步骤。然后,如果你陷入困境,你可以回来问一个更具体、更能回答的问题。你能给我举个例子,说明我如何在这门课上使用vector吗?很高兴你得到了codez。希望你能理解