package eco;

public class Economy {

	public static int treasury = 0;

	public static int wheatPrice = 10;
	public static int supplyShock = 0;

	public static float shockRatio = 2f;

	public static int foreignDemand = 1000;

	public static int buyWheat(int ammount){
		return 0;
	}

	public static void sellWheat(int ammount){
		while (ammount > 0 && foreignDemand > 0){
			if (ammount >= 100){
				int toSell = ammount - 100;
				treasury += toSell * getRealPrice();
				ammount -= toSell;
				supplyShock += shockRatio;
				foreignDemand -= toSell * getRealPrice();
			}
			else{
				int toSell = ammount;
				treasury += toSell * getRealPrice();
				ammount -= toSell;
				supplyShock += shockRatio;
				foreignDemand -= toSell * getRealPrice();
			}
		}
	}

	public static int getRealPrice(){
		return wheatPrice - supplyShock;
	}

	public static void updateMarket(int time){
		float timeMul = (float) Math.sin(Math.toRadians(time / 8f));
		int deltaPrice = (int) (timeMul * 1f);
		wheatPrice += deltaPrice;
		foreignDemand -= (timeMul * 50);
	}

}

@@ -11,276 +11,252 @@
 o;%0A%0A
-public class Economy %7B%0A%0A%09public static int treasury = 0;%0A%0A%09public static
+/**%0A* This class describes the international market for wheat,%0A*
  i
-n
 t 
-wheatPrice = 10;%0A%09public static int supplyShock = 0;%0A%0A%09public static float shockRatio = 2f;%0A%0A%09public static int foreignDemand = 1000;%0A%0A%09public static int buyWheat(int ammount)%7B%0A%09%09return 0;%0A%09%7D
+manages wheat reserve goals and sells or buys to%0A* meet it.%0A*%0A* @Author phil%0A*/%0A%0Apublic class Economy %7B%0A%0A%09private static int treasury = 0;%0A%0A%09private static int wheatPrice = 10;
 %0A%0A%09p
@@ -272,17 +272,15 @@
 tic 
-void sell
+int buy
 Whea
@@ -301,107 +301,80 @@
 %7B%0A%09%09
-while (ammount %3E 0 && foreignDemand %3E 0)%7B%0A%09%09%09if (ammount %3E= 100)%7B%0A%09%09%09%09int toSell = ammount - 100;%0A%09
+int neededMoney = wheatPrice * ammount;%0A%09%09if (neededMoney %3C= treasury)%7B%0A
 %09%09%09t
@@ -385,144 +385,49 @@
 ury 
-+= toSell * getRealPrice();%0A%09%09%09%09ammount -= toSell;%0A%09%09%09%09supplyShock += shockRatio
+-= neededMoney
 ;%0A%09%09%09
-%09foreignDemand -= toSell * getRealPrice()
+return ammount
 ;%0A
-%09
 %09%09%7D%0A%09%09
-%09
 else
@@ -435,176 +435,80 @@
 %0A%09%09%09
-%09
 int 
-toSell = ammount;%0A%09%09%09%09treasury += toSell * getReal
+canBuy = treasury / wheat
 Price
-()
 ;%0A%09%09%09
-%09ammount -= toSell;%0A%09%09%09%09supplyShock += shockRatio;%0A%09%09%09%09foreignDemand -= toSell * getRealPrice();%0A%09%09%09%7D
+treasury = 0;%0A%09%09%09return canBuy;%09%09
 %0A%09%09%7D
@@ -535,32 +535,45 @@
 int 
-getRealPrice(
+sellWheat(int ammount
 )%7B%0A%09%09
+t
 re
-turn
+asury +=
  whe
@@ -584,21 +584,35 @@
 ice 
-- supplyShock
+* ammount;%0A%09%09return ammount
 ;%0A%09%7D
@@ -663,175 +663,136 @@
 %7B%0A%09%09
-float timeMul = (float) Math.sin(Math.toRadians(time / 8f));%0A%09%09int deltaPrice = (int) (timeMul * 1f);%0A%09%09wheatPrice += deltaPrice;%0A%09%09foreignDemand -= (timeMul * 50);
+wheatPrice += Util.randInt(-5, 7); // Biased to increase over time%0A%09%7D%0A%0A%09public static int getTreasury()%7B%0A%09%09return treasury;%09
 %0A%09%7D
+%09
 %0A%0A%7D%0A

Update Economy.java