记录订购产品
所以我的第一个问题已经被固定在这里: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(); }
}
您需要存储您在数组中输入的数据或使用java.util.Vector。
使用for循环中要
我希望它能帮助的形式显示出来。
:)
你能为我做一个关于如何在这堂课中使用矢量的例子吗? –
嘿没关系我现在得到的代码:3 –
很高兴你得到了codez。希望你有*的理解*。 :) –
你有没有试图解决这个问题?如果是这样的话?如果不是这样,你应该将问题分解成更小的步骤,并尝试一次解决每一步。一个有用的参考可以帮助这个步骤[所以,你需要编写一个程序,但不知道如何开始](http://home.earthlink.net/~patricia_shanahan/beginner.html)Patricia Shanahan。 *然后*如果您遇到困难,您可以回过头来问一个更具体和可回答的问题。 –