整理简单Java程序的代码

时间:2014-12-03 04:01:11

标签: java methods

我有以下程序,它正如我所希望的那样工作,但现在我想整理代码,将位放入新方法中,所以我不会在main方法中留下大量代码。我是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;
}

*/ Would like to use these */

*/ Would like to use instead of quantityIn -= item_1.getDailyDemand() in main method */

public void removeDailyDemand(){

    quantityInStock -= dailyDemand;
}

*/ Would like to use instead of quantityIn < reOrderThreshold  */

public void newDeliveryIn(){
    ; 
}    

*/ Would like to use instead of quantityIn += item_1.getReOrder() in main method */

public void isReOrderPoint(){
    ; 
}

我想要使用它们的最后三种方法,但是我不确定如何,所以它们目前没有做任何事情,我已经完成所有其他工作,正如我所希望的那样。

这是主要代码:

/* Create new item - Inventory Code, Starting Quantity In Stock, Daily Demand, Re-order Amount, Time in Transit (Lead-time) */ 

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

    /* Column titles */

            System.out.println("Day" + "\t" + "Stock" + "\t" + "Order Status");
            System.out.println("");

            /*Variables */

    int reOrderThreshold = 600;
    int orderTravelTime = 0;
    boolean orderInTravel = false;
    int quantityIn = item_1.getQuantityInStock();

    /* For loop to count 50 days */

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

        /* Remove daily demand from current stock */
        quantityIn -= item_1.getDailyDemand();

        out += n;
        out += " " + "\t" + quantityIn + "\t";

        /* If order has been ordered and has not arrived */

        if (orderInTravel && orderTravelTime < item_1.getLeadTime()) { 

            orderTravelTime++;

                            out += "In Transit -" + "\t";

        /* If ordered and has arrived */

        } else if (orderInTravel && orderTravelTime >= item_1.getLeadTime()) { 
            orderTravelTime = 0;
            orderInTravel = false;

                            quantityIn += item_1.getReOrder();
                            out += "New Stock Delivered (" + item_1.getReOrder()")   and Will be Added to Quantity in Stock the Next Day";

        }
                    /* If stock gets too low, order */

        if (quantityIn < reOrderThreshold) { 
            orderInTravel = true;

            out += "Ordered";
        }

                    /* Print out results */

        System.out.println(out);
    }

以下是输出的一部分:

Day Stock   Order Status

1   950 
2   900 
3   850 
4   800 
5   750 
6   700 
7   650 
8   600 
9   550 Ordered
10  500 In Transit -    Ordered
11  450 In Transit -    Ordered
12  400 In Transit -    Ordered
13  350 In Transit -    Ordered
14  300 In Transit -    Ordered
15  250 New Stock Delivered (500) and Will be Added to Quantity in Stock the Next Day
16  700 
17  650 
18  600 
19  550 Ordered
20  500 In Transit -    Ordered
21  450 In Transit -    Ordered
...

我希望这很清楚,我没有包含所有代码,但如果足够的话,请考虑我已经包含的内容。

提前致谢。

0 个答案:

没有答案