2016-12-10 29 views
0

我有一個客戶類。如何將三個類的實例綁定在一起?

public Customer(boolean regular, boolean payAhead, boolean loyal, String userName, double amountOfStorage) { 
    this.regular = regular; 
    this.payAhead = payAhead; 
    this.loyal = loyal; 
    this.userName = userName; 
    this.amtOfStore = amountOfStorage; 
} 

我使用Map來讓用戶通過JTextField選擇他們是什麼客戶。

Map<String, Customer> map = new HashMap<>(); 
map.put("Kyle", new Customer(true, false, false, "Kyle", 1000.00)); 
map.put("Andrew", new Customer(false, true, false, "Andrew", 0.00)); 
map.put("Connor", new Customer(false, false, true, "Connor", 5000.00)); 

這一切都有效。我也有一個Store類。

public Store(String name, double cost, double mbAmount, int itemCnt, double ship) { 
    this.name = name; 
    this.cost = cost; 
    this.mbAmount = mbAmount; 
    this.itemCnt = itemCnt; 
    this.ship = ship; 
} 

具有多個Store實例。

Store sitem1 = new Store("Movie", 20.00, 500, 0, 0.00); 
Store sitem2 = new Store("Lamborghini", 2000000.00, 0, 0, 5000); 
Store sitem3 = new Store("Song", .99, 50, 0, 0); 
Store sitem4 = new Store("Headphones", 25.00, 0, 0, 3.00); 
Store sitem5 = new Store("iPhone", 894.92, 0, 0, 10.00); 
Store sitem6 = new Store("Coffe Maker", 50.67, 0, 0, 7.00); 
Store sitem7 = new Store("Video Game", 59.99, 40000, 0, 0); 
Store sitem8 = new Store("Laptop", 500.00, 0, 0, 6.76); 
Store sitem9 = new Store("Old Movie", 2.99, 100, 0, 0); 
Store sitem10 = new Store("Tv Show", .99, 20, 0, 0); 

和一個ShoppingCart類。

public ShoppingCart(double shippingCost, double storageSize, double totalPrice, double temp, int cartCount) { 
    this.shippingCost = shippingCost; 
    this.storageSize = storageSize; 
    this.totalPrice = totalPrice; 
    this.temp = temp; 
    this.cartCount = cartCount; 
} 

我需要它,所以當一個客戶註銷(計劃永遠不會關閉),並在商店和購物車類另一個日誌是唯一給他,同時保持這是由以前的客戶輸入的信息。在這種情況下,程序再次關閉。

+0

請說明您的具體問題或添加其他詳細信息,以確切地突出顯示您的需求。正如目前所寫,很難確切地說出你在問什麼。請參閱「如何問問」頁面以獲取有關澄清此問題的幫助。 – rodrigoap

+0

您需要某處存儲對象的列表。您還需要與客戶關聯的ShoppingCart。你可能會發現一個數據庫在這裏很有用。 Sqlite是一個很好的起點 –

+0

你是在一個線程中運行這個代碼嗎? – recurf

回答

0

將購物車添加到您的客戶類,代表該客戶當前的購物車。

通過客戶訪問和修改購物車。

一位顧客有一個購物車。

+0

這並沒有真正解決如何保存購物車的「會話」 –

+0

我懷疑他還沒有(持久性部分),只是把所有東西都放在內存中。 – Reek

+0

可能不是,但它是問題的一部分。 「註銷...,同時保留先前客戶輸入的信息。」 –

相關問題