2014-12-01 90 views
0

我已經得到了大部分程序,除了一些不是的,我是新來的Java,所以它不是很明顯,我打算做什麼。獲取方法在一個簡單的Java程序中工作

這裏是方法:

public String getInventoryCode() 
{ 
    return inventoryCode; 
} 

public int getQuantityInStock() 
{ 
    return quantityInStock; 
} 

public int getDailyDemand() 
{ 
    return dailyDemand; 
} 

public int getReOrder() 
{ 
    return reOrder; 
} 

public int getLeadTime() 
{ 
    return leadTime; 
} 

public int newDeliveryIn(int newDeli) 
{ 
    quantityInStock += reOrder; 

    return newDeli; 
} 

下面是主要代碼:

StockItem item_1 = new StockItem("A654Y", 1000, 50, 500, 13); 

int quantityIn = item_1.getQuantityInStock(); 

for (int n = 1; n <=50 ; n++) 
{ 
    quantityIn -= item_1.getDailyDemand(); 

    System.out.print(n + "\t"); 
    System.out.println(quantityIn); 

    if (n % item_1.getLeadTime() == 1){ 

     System.out.println("Batch Ordered"); 
    } 

    else if (n % item_1.getLeadTime() == 0){ 

     quantityIn += item_1.getReOrder(); 
     System.out.println("Batch Received"); 
    }  
} 

這是其計算天數達50一個簡單的庫存控制程序,每天減少的庫存量(數量InStock)乘以X數量(dailyDemand),然後當它達到某一天(例如每隔10天(還沒有爲此做出一個方法,因爲不知道如何去做)它會訂購更多的股票(reOrder )將在一定天數後交付並添加到當前股票中訂單後(leadTime)。我想我幾乎在那裏,只是我無法解決的最後一點。

這是輸出我的那一刻得到:

1 950 
Batch Ordered 
2 900 
3 850 
4 800 
5 750 
6 700 
7 650 
8 600 
9 550 
10 500 
11 450 
12 400 
13 350 
Batch Received 
14 800 
Batch Ordered 
15 750 
16 700 
17 650 
18 600 
19 550 
20 500 
21 450 
22 400 
23 350 
24 300 
25 250 
26 200 
Batch Received 
27 650 
Batch Ordered 
... 

我還要「批量訂購,已批量收到」去旁邊的有關日期(第3列),而不是之下,但可以如何解決問題。

任何幫助將是偉大的!謝謝。

回答

1

我會通過打印您通過兩個if語句運行確定天氣或不顯示Batch ReceivedBatch Ordered後安慰做到這一點。

所以for循環改變這種

for (int n = 1; n <=50 ; n++) 
{ 
    String out = ""; 

    quantityIn -= item_1.getDailyDemand(); 

    out += n; 
    out += " " + quantityIn; 

    if (n % item_1.getLeadTime() == 1){ 

     out += " Batch Ordered"; 
    } 

    else if (n % item_1.getLeadTime() == 0){ 

     quantityIn += item_1.getReOrder(); 
     out += " Batch Received"; 

    } 

    System.out.println(out); 

} 

我剛剛創建了一個名爲out變量。我不斷向這個變量添加內容,並在for循環結尾打印out。這樣你就不必擔心以任何奇特的方式打印到控制檯。

更新

這是股票問題的解決方案。

int reOrderThreshold = 10; 
StockItem item_1 = new StockItem("A654Y", 1000, 50, 500, 13); 

int orderTravelTime = 0; 
boolean orderInTravel = false; 

for(int i = 0; i < 50; i++){ 
    //Do other things, like printing out daily demand and i 
    if(orderInTravel && orderTravelTime < item_1.getLeadTime()){//If order has been ordered and has not arrived 
    orderTravelTime ++; 
    } else if(orderInTravel && orderTravelTime >= item_1.getLeadTime()){//If ordered and has arrived 
    orderTravelTime = 0; 
    orderInTravel = false; 

    item_1.quantityInStock += item_1.getReOrder(); 
    } 

    if(item_1.getQuantityInStock() < reOrderThreshold){//If stock gets to low, order 
    orderInTravel = true; 
    } 
} 
+0

很好,謝謝。你有什麼想法解決我在問題中提到的問題嗎?總而言之,我想將其設置爲在X天進行訂單,然後X天后訂單將交付並添加到quantityIn。非常感謝 – Liam 2014-12-01 22:54:06

+0

@James Sure,如何「確定它在X天訂購」確定?當物品數量低於一個數字?每10天? – 2014-12-01 23:03:00

+0

真棒謝謝,我刪除了我的最後一條評論,試圖標記你但沒有工作。再次感謝:) – Liam 2014-12-01 23:12:43

0

使用

System.out.print(quantityIn); 

在主代碼

0

在此之前:

System.out.println(quantityIn); 

檢查,如果批量訂購或之後接受了!如果是使用

print(quantityIn) 

代替

System.out.println(quantityIn); 
相關問題