Skip to content

Instantly share code, notes, and snippets.

@SproutSeeds
Created May 2, 2019 00:34
Show Gist options
  • Save SproutSeeds/40ac93a36fa26262ed9eae8efe3d8789 to your computer and use it in GitHub Desktop.
Save SproutSeeds/40ac93a36fa26262ed9eae8efe3d8789 to your computer and use it in GitHub Desktop.
CoffeeShop
import java.text.NumberFormat;
public class CoffeeShop {
private int milk;
private int coffee;
private int bagels;
private int muffins;
int capCount = 0;
int espCount = 0;
int bagCount = 0;
int mufCount = 0;
int totalCap = 0;
int totalEsp = 0;
int totalMuf = 0;
int totalBag = 0;
private int returnedOrders = 0;
private double totalSales;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String sales = formatter.format(totalSales);
public CoffeeShop() {
milk = 400;
coffee = 300;
bagels = 75;
muffins = 50;
}
public String toString() {
return ("Cappuccino Count: " + totalCap + "\n" + "Espresso Count: " + totalEsp + "\n" + "Bagel Count: "
+ totalBag + "\n" + "Muffin Count: " + totalMuf + "\n" + "Returned Orders: " + returnedOrders + "\n"
+ "Total Sales: $" + totalSales + "\n");
}
public void processOrder(Order order) {
capCount = order.getCappuccinoCount();
espCount = order.getEspressoCount();
bagCount = order.getBagelCount();
mufCount = order.getMuffinCount();
// System.out.println(capCount);
// System.out.println(espCount);
// System.out.println(bagCount);
// System.out.println(mufCount);
// System.out.println(this.milk);
// System.out.println(this.coffee);
// System.out.println(this.bagels);
// System.out.println(this.muffins);
if (capCount > 0) {
for (int i = capCount; i > 0; i--) {
if (this.milk - 4 >= 0 && this.coffee - 2 >= 0) {
this.milk -= 4;
this.coffee -= 2;
totalCap++;
} else {
returnedOrders++;
}
}
}
// System.out.println(this.milk);
// System.out.println(this.coffee);
// System.out.println(totalCap);
// System.out.println(espCount);
// System.out.println(capCount);
if (espCount > 0) {
for (int i = espCount; i > 0; i--) {
if (this.coffee - 1 >= 0) {
this.coffee -= 1;
totalEsp++;
} else {
returnedOrders++;
}
}
}
if (bagCount > 0) {
for (int i = bagCount; i > 0; i--) {
if (this.bagels - 1 >= 0) {
this.bagels -= 1;
totalBag++;
} else {
returnedOrders++;
}
}
}
if (mufCount > 0) {
for (int i = mufCount; i > 0; i--) {
if (this.muffins - 1 >= 0) {
this.muffins -= 1;
totalMuf++;
} else {
returnedOrders++;
}
}
}
totalSales += order.calculateTotal();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment