Getting methods to work in a simple Java program -
i've got of program working apart few bits aren't, i'm new java it's not obvious i'm meant do.
here methods:
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; }
here main code:
stockitem item_1 = new stockitem("a654y", 1000, 50, 500, 13); int quantityin = item_1.getquantityinstock(); (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"); } }
it's simple stock control program counts days 50, each day reducing amount of stock (quantityinstock) x amount (dailydemand) , when gets day (for instance every 10th day (haven't yet made method this, not sure how go it) order more stock (reorder) delivered , added current stock after amount of days after order (leadtime). think i'm there, last bit can't work out.
this output i'm getting @ moment:
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 ...
i "batch ordered, batch received" go alongside relevant day (3rd column) instead of under, can't work out how.
any great! thanks.
i printing console after have run through 2 if
statements determining weather or not show batch received
or batch ordered
.
so change for
loop this
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); }
i created variable named out
. keep adding content variable , @ end of loop prints out
. way not have worry printing console in fancy ways.
update
here solution stock problem.
int reorderthreshold = 10; stockitem item_1 = new stockitem("a654y", 1000, 50, 500, 13); int ordertraveltime = 0; boolean orderintravel = false; for(int = 0; < 50; i++){ //do other things, printing out daily demand , if(orderintravel && ordertraveltime < item_1.getleadtime()){//if order has been ordered , has not arrived ordertraveltime ++; } else if(orderintravel && ordertraveltime >= item_1.getleadtime()){//if ordered , has arrived ordertraveltime = 0; orderintravel = false; item_1.quantityinstock += item_1.getreorder(); } if(item_1.getquantityinstock() < reorderthreshold){//if stock gets low, order orderintravel = true; } }
Comments
Post a Comment