import java.io.*;
import java.util.*;
import java.lang.*;
import java.text.*;
import java.util.Random;
import java.util.regex.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class lemonade {
public static void main
(String[] args
) { while (playAgain.equals("y") || playAgain.equals("yes")) {
Scanner scan
= new Scanner
(System.
in); String[]weather
= {"Humid",
"Clear",
"Cloudy",
"Rainy"}; int dayLength;
int day = 1;
int potentialCustomers = 0;
double actualCustomers = 0;
double wallet = 20;
int lemonStock = 0;
int sugarStock = 0;
int iceStock = 0;
int cupStock = 0;
double lemonPrice = 0.15;
double sugarPrice = 0.10;
double icePrice = 0.05;
double price = 0;
double price_success = 0;
double lemon_success = 0;
int lemonNeeded = 3;
double sugar_success = 0;
int sugarNeeded = 2;
double ice_success = 0;
int iceNeeded = 0;
double recipe_success = 0;
double percent_success;
double sales = 0;
System.
out.
println("\nTry to create the perfect recipe for your lemonade stand. \nKeep in mind that weather and temperature are variables \nthat will affect how much ice you need for your recipe.\nAnd don't forget about price!\n"); System.
out.
println("Press Enter to continue...");
System.
out.
println("Please enter the number of days you would like to sell for."); dayLength = scan.nextInt();
//PRINT STATS///////////////////////////////
System.
out.
println("\n\nYour Stock:\nWallet: $"+wallet
+"\nLemons: "+lemonStock
+"\nSugar: "+sugarStock
+"\nIce: "+iceStock
+"\nCups: "+cupStock
+"\nDays to sell: "+dayLength
+"\n");
//BUY STOCK/////////////////////////////////
System.
out.
println("Buy Lemons @ $0.15 per lemon"); int lemonTemporary = scan.nextInt();
while (lemonTemporary*0.15 > wallet) {
System.
out.
println("You don't have enough $. How many lemons would you like to buy?"); lemonTemporary = 0;
lemonTemporary += scan.nextInt();
}
lemonStock += lemonTemporary;
wallet = wallet - (lemonStock*0.15);
System.
out.
println("Wallet: $"+wallet
+"\nLemon stock: "+lemonStock
+"\n"); //Lemon End//Sugar Start//
System.
out.
println("Buy Sugar @ $0.10 per cup of sugar"); int sugarTemporary = scan.nextInt();
while (sugarTemporary*0.10 > wallet) {
System.
out.
println("You don't have enough $. How much sugar would you like to buy?"); sugarTemporary = 0;
sugarTemporary += scan.nextInt();
}
sugarStock += sugarTemporary;
wallet = wallet - (sugarStock*0.10);
System.
out.
println("Wallet: $"+wallet
+"\nSugar stock: "+sugarStock
+"\n"); //Sugar End//Ice Start//
System.
out.
println("Buy Ice @ $0.05 per ice cube"); int iceTemporary = scan.nextInt();
while (iceTemporary*0.05 > wallet) {
System.
out.
println("You don't have enough $. How much ice would you like to buy?"); iceTemporary = 0;
iceTemporary += scan.nextInt();
}
iceStock += iceTemporary;
wallet = wallet - (iceStock*0.05);
System.
out.
println("Wallet: $"+wallet
+"\nSugar stock: "+sugarStock
+"\n"); //Ice End//Cup Stock//
System.
out.
println("Your grandmother donated 100 cups."); cupStock += 100;
//End Cup Stock//
//////////////////////////////START GAME PLAY///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
while (dayLength >= day){
int random = rand.nextInt(4) + 0;
int temp = 50 + rand.nextInt(55);
///////RANDOMIZER FOR WEATHER AND CUSTOMERS/////////
System.
out.
println("\nDay "+day
+": Today is "+weather
[random
]+" and "+temp
+" degrees Fahrenheit in California."); if (weather[random] == "Humid") {potentialCustomers = temp + 10;}
if (weather[random] == "Clear") {potentialCustomers = temp + 5;}
if (weather[random] == "Cloudy") {potentialCustomers = temp - 5;}
if (weather[random] == "Rainy") {potentialCustomers = temp - 10;}
////////ICE FACTOR//////
if (potentialCustomers >= 95) { iceNeeded = 4;}
if (potentialCustomers >= 85 && potentialCustomers < 95) { iceNeeded = 3;}
if (potentialCustomers >= 75 && potentialCustomers < 85) { iceNeeded = 2;}
if (potentialCustomers >= 65 && potentialCustomers < 75) { iceNeeded = 1;}
if (potentialCustomers < 65) { iceNeeded = 0;}
//////END ICE FACTOR////
System.
out.
println("Your potential customers are: "+potentialCustomers
+".\n");
/////////////////BUY STOCK//////////
int days_left = dayLength - day;
System.
out.
println("Your Stats:\nWallet: $"+wallet
+"\nLemons: "+lemonStock
+"\nSugar: "+sugarStock
+"\nIce: "+iceStock
+"\nCups: "+cupStock
+"\n\n"); System.
out.
println("\nDo you need to restock? >> Y or N"); yesNo = scan.next();
if (yesNo.equals("y") || yesNo.equals("yes")) {
System.
out.
println("Buy Lemons @ $0.15 per lemon"); lemonTemporary = scan.nextInt();
while (lemonTemporary*0.15 > wallet) {
System.
out.
println("You don't have enough $. How many lemons would you like to buy?"); lemonTemporary = 0;
lemonTemporary += scan.nextInt();
}
lemonStock += lemonTemporary;
wallet = wallet - (lemonStock*0.15);
System.
out.
println("Wallet: $"+wallet
+"\nLemon stock: "+lemonStock
+"\n"); //Lemon End//Sugar Start//
System.
out.
println("Buy Sugar @ $0.10 per cup of sugar"); sugarTemporary = scan.nextInt();
while (sugarTemporary*0.10 > wallet) {
System.
out.
println("You don't have enough $. How much sugar would you like to buy?"); sugarTemporary = 0;
sugarTemporary += scan.nextInt();
}
sugarStock += sugarTemporary;
wallet = wallet - (sugarStock*0.10);
System.
out.
println("Wallet: $"+wallet
+"\nSugar stock: "+sugarStock
+"\n"); //Sugar End//Ice Start//
System.
out.
println("Buy Ice @ $0.05 per ice cube"); iceTemporary = scan.nextInt();
while (iceTemporary*0.05 > wallet) {
System.
out.
println("You don't have enough $. How much ice would you like to buy?"); iceTemporary = 0;
iceTemporary += scan.nextInt();
}
iceStock += iceTemporary;
wallet = wallet - (iceStock*0.05);
System.
out.
println("Wallet: $"+wallet
+"\nSugar stock: "+sugarStock
+"\n");
//Ice End//
}
///////END RESTOCK//////////
//////////////CREATE RECIPE///////////////////
System.
out.
println("\nThe correct recipe is crucial for sales. \nAdd items to create your perfect recipe."); System.
out.
println("Lemons:"); int lemonRecipe = scan.nextInt();
while (lemonRecipe > lemonStock) {
System.
out.
println("You don't have enough lemons.\nLemons:"); lemonRecipe = scan.nextInt();
}
//Stock Mod//lemonStock -= lemonRecipe;
int sugarRecipe = scan.nextInt();
while (sugarRecipe > sugarStock) {
System.
out.
println("You don't have enough sugar.\nSugar:"); sugarRecipe = scan.nextInt();
}
//Stock Mod//sugarStock -= sugarRecipe;
int iceRecipe = scan.nextInt();
while (iceRecipe > iceStock) {
System.
out.
println("You don't have enough ice.\nIce:"); iceRecipe = scan.nextInt();
}
//Stock Mod//iceStock -= iceRecipe;
////////////END RECIPE/////////////////
/////ONLY ALLOW WHAT'S IN STOCK TO BE SOLD///// //////// ////////
int originalCustomers = potentialCustomers;
int cups = lemonRecipe * 10;
int cupSold = 0;
do{
cupSold++;
potentialCustomers--;
if (cupSold % cups == 0) {
lemonStock -= lemonRecipe;
sugarStock -= sugarRecipe;
iceStock -= iceRecipe;
}
}while ((potentialCustomers > 0) && ( (lemonRecipe <= lemonStock) && (sugarRecipe <= sugarStock) && (iceRecipe <= iceStock) ));
potentialCustomers = originalCustomers - potentialCustomers;
cupStock -= cupSold;
/////// //////// //////// /////Stock Mod////// //////// ////////
//////////SET PRICE///////////
System.
out.
println("Name your price."); price = scan.nextDouble();
if (price <= .5) {price_success = 10;}
if (price <= .75 && price > .5) {price_success = 8;}
if (price <= 1 && price > .75) {price_success = 6;}
if (price <= 1.25 && price > 1) {price_success = 4;}
if (price <= 1.75 && price > 1.25) {price_success = 2;}
if (price > 1.75) {price_success = 0;}
/////////////END PRICE///////
///////////////////////////PRICE AND RECIPE CALCULATIONS////////////////////////
if (lemonRecipe == lemonNeeded) { lemon_success = 10; }
else { lemon_success = rand.nextInt(5) + 1;}
if (sugarRecipe == sugarNeeded) { sugar_success = 10; }
else { sugar_success = rand.nextInt(7) + 1; }
if (iceRecipe == iceNeeded) { ice_success = 10; }
else { ice_success = rand.nextInt(5) + 1; }
recipe_success = (lemon_success + sugar_success + ice_success) / 3;
percent_success = (recipe_success + price_success) / 20;
actualCustomers
= Math.
round(percent_success
* potentialCustomers
); if ((potentialCustomers < originalCustomers) && price < 3 && lemonRecipe > 0 && sugarRecipe > 0) {
System.
out.
println("You ran out of stock for recipe."); }
if (lemonRecipe
== 0 || sugarRecipe
== 0) {actualCustomers
= 0; System.
out.
println("That was a recipe for disaster, NOT lemonade.");} if (price
>= 3) {actualCustomers
= 0; System.
out.
println("Your price was TOO steep!");} sales
= Math.
round(actualCustomers
* price
); wallet += sales;
///////////////////////////////END CALCULATIONS////////////////////////////////
////////PRINT STATS AT END OF DAY//////////
System.
out.
println("You sold to "+actualCustomers
+" out of "+originalCustomers
+" customers and made $"+sales
+" in sales today.\nDays left: "+days_left
+"\n"); day++;
if (dayLength >= day) {
cupStock += 100;
System.
out.
println("Your looted 100 more cups from ol Granny Mae."); }
}
////////PLAY AGAIN?/////////
System.
out.
println("You walked away with $"+wallet
+" in your pocket."); System.
out.
println("Play Again? >> Y or N"); yesNo = scan.next();
playAgain = yesNo;
}
//////////////////////////////END GAME PLAY/////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
System.
out.
println("Goodbye."); }
}