Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CoffeeMachine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Getting Started

Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.

## Folder Structure

The workspace contains two folders by default, where:

- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies

Meanwhile, the compiled output files will be generated in the `bin` folder by default.

> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.

## Dependency Management

The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Binary file added CoffeeMachine/bin/App.class
Binary file not shown.
Binary file added CoffeeMachine/bin/Coffee.class
Binary file not shown.
Binary file added CoffeeMachine/bin/CoffeeBuilder.class
Binary file not shown.
Binary file added CoffeeMachine/bin/DisplayPanel.class
Binary file not shown.
Binary file added CoffeeMachine/bin/Inventory.class
Binary file not shown.
Binary file added CoffeeMachine/bin/OrderManager.class
Binary file not shown.
13 changes: 13 additions & 0 deletions CoffeeMachine/src/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.util.*;

public class App {
public static void main(String[] args) throws Exception {

DisplayPanel dp = DisplayPanel.getDisplayPanelInstace();
dp.displayWelcomeScreen();

}


}

24 changes: 24 additions & 0 deletions CoffeeMachine/src/Coffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Coffee {

boolean milk;
boolean water;
boolean sugar;
boolean hot;
String quantity;
boolean strong;
String coffeeName;
public static Coffee coffee;

public static Coffee getCoffeeInstance(){
return (coffee == null)? new Coffee() : coffee;
}
public Coffee(){

}

public void buildCoffee(Coffee cfb){
//send message to kitchen
}


}
101 changes: 101 additions & 0 deletions CoffeeMachine/src/CoffeeBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
public class CoffeeBuilder {

boolean milk;
boolean water;
boolean sugar;
boolean hot;
String quantity;
boolean strong;
String coffeeName;
Inventory inventory;

public static CoffeeBuilder coffeeBuilder;
OrderManager orderManager;

public CoffeeBuilder() {
milk = false;
water = false;
sugar = false;
hot = false;
quantity = "Medium";
strong = false;
coffeeName = "";
orderManager = OrderManager.getOrderManagerInstance();
inventory = Inventory.getInventoryInstance();
}

public static CoffeeBuilder getCoffeeBuilderInstance(){
return (coffeeBuilder == null)? new CoffeeBuilder() : coffeeBuilder;
}

public void buildCoffee( CoffeeBuilder cfb){

}

public void setMilk(boolean flag){
this.milk = flag;
}
public void setWater(boolean flag){
this.water= flag;
}
public void setSugar(boolean flag){
this.sugar = flag;
}
public void setHot(boolean flag){
this.hot = flag;
}
public void setQuantity(String quant){
this.quantity = quant;
}
public void setcoffeeName(String cn){
this.coffeeName = cn;
}
public void setStrong(boolean flag){
this.strong = flag;
}


public boolean getMilk(){
return milk;
}
public boolean getWater(){
return water;
}
public boolean getSugar(){
return sugar;
}
public boolean getHot(){
return hot;
}
public String getQuantity(){
return quantity;
}
public boolean getStrong(){
return strong;
}
public String getcoffeeName(){
return coffeeName;
}

public int placeOrder(CoffeeBuilder cb){
int orderNum = cb.orderManager.createNewOrder();
addBills(cb,orderNum);
return orderNum;
}
private void addBills(CoffeeBuilder cb, int orderNum){

orderManager.addBills(orderNum, inventory.getCoffeesAndPrices().get(cb.coffeeName));
orderManager.addBills(orderNum, (cb.getMilk() ? inventory.getAddonAndPrices().get("Milk"):0.0));
orderManager.addBills(orderNum, (cb.getWater() ? inventory.getAddonAndPrices().get("Water"):0.0));
orderManager.addBills(orderNum, (cb.getHot() ? inventory.getAddonAndPrices().get("Hot"):0.0));
orderManager.addBills(orderNum, (cb.getStrong() ? inventory.getAddonAndPrices().get("Strong"):0.0));
orderManager.addBills(orderNum, (cb.getSugar() ? inventory.getAddonAndPrices().get("Sugar"):0.0));

}

public double calculateTotalBill(int orderNum){
return orderManager.getTotalBill(orderNum);
}


}
143 changes: 143 additions & 0 deletions CoffeeMachine/src/DisplayPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*solely for the purpose of displaying the Output and taking input details, this will also validate the input*/

import java.util.*;

public class DisplayPanel {
Inventory inventory;
int MAX_COFFESS;
public static DisplayPanel displayPanel;
CoffeeBuilder coffeeBuilder;
Scanner s;
public static DisplayPanel getDisplayPanelInstace(){
return (displayPanel == null)? new DisplayPanel() : displayPanel;
}

public DisplayPanel(){
inventory = Inventory.getInventoryInstance();
s = new Scanner(System.in);
}

public void displayWelcomeScreen(){
System.out.println("\n######### Welcome to Prudhvi Coffee Shop ###########\n");
System.out.print("\n*--* Please select your coffee from the below list *--*\n");
displayCoffeeOptions();
takeUserInput();

}

private void takeUserInput(){

int coffeeSelection = takeIntUserInput();
if(coffeeSelection == 9){
exitFromApp();
}

if(coffeeSelection < 1 || coffeeSelection > MAX_COFFESS){
System.out.println("\nYou have made an incorrect selection, could you please select again?\n");
takeUserInput();
}else{
String selectedCoffee = inventory.getCoffeeName(coffeeSelection);
System.out.println("You have selected " + selectedCoffee);
coffeeBuilder = CoffeeBuilder.getCoffeeBuilderInstance();
coffeeBuilder.coffeeName = selectedCoffee;
//offer add-ons
System.out.println("\n Would you like to have addons ? \n 1. Yes \n 2. No");
int choice = takeIntUserInput();
if(choice == 2){
checkOut(coffeeBuilder);
}else{
offerAddons(coffeeBuilder);
checkOut(coffeeBuilder);
}
}

}
private void exitFromApp(){
System.out.println("\nThank you for visiting! Have a nice Day...\n");
System.exit(0);
}
private void checkOut(CoffeeBuilder coffeeBuilder){
int orderNum = coffeeBuilder.placeOrder(coffeeBuilder);
displayOrderDetails();
double totalBill = coffeeBuilder.calculateTotalBill(orderNum);
System.out.print("\nHere is your Order Number : "+ orderNum);
System.out.print("\nHere is your total bill [0.5% service tax included]: ₹"+ Math.round(totalBill));
System.out.println("\n\nPlease take your bill and wait while we make your coffee... \nHave a nice day!!!\n");
exitFromApp();

}

private void displayOrderDetails(){

System.out.print("\nThank you!, Here are your order details :\n");
System.out.println("\nCoffee : " + coffeeBuilder.getcoffeeName());
System.out.println("\nAdditional Milk : " + (coffeeBuilder.getMilk()==true ? "Yes" : "No"));
System.out.println("\nHot Coffee : " + (coffeeBuilder.getHot() ==true? "Yes" : "No"));
System.out.println("\nSize : " + coffeeBuilder.getQuantity());
System.out.println("\nStrong Coffee : " + (coffeeBuilder.getStrong()==true? "Yes" : "No"));
System.out.println("\nMore Sugar : " + (coffeeBuilder.getSugar()==true? "Yes" : "No"));
System.out.println("\nMore Water : " + (coffeeBuilder.getWater()==true? "Yes" : "No"));

}

private int takeIntUserInput(){
int n = s.nextInt();
if(n == 9 || n == 44){
exitFromApp();
}
return n;
}

private void offerAddons(CoffeeBuilder coffeeBuilder){
Map<String, Double> addonAndPrices = inventory.getAddonAndPrices();
int selection;

System.out.println("\nWould you like to have additional Milk for ₹" + addonAndPrices.get("Milk") + " ?\n 1. Yes \n 2. No \n33. Exit from Addons \n44. Exit Order");
selection = takeIntUserInput();
validateInput(selection);
coffeeBuilder.setMilk(selection == 1 ? true : false);
System.out.println("\nWould you like to add more Water for ₹" + addonAndPrices.get("Water") + " ? \n 1. Yes \n 2. No \n33. Exit from Addons \n43. Exit Order");
selection = takeIntUserInput();
validateInput(selection);
coffeeBuilder.setWater(selection == 1 ? true : false);
System.out.println("\nWould you like to have additional Sugar for ₹" + addonAndPrices.get("Sugar") + " ?\n 1. Yes \n 2. No \n33. Exit from Addons \n44. Exit Order");
selection = takeIntUserInput();
validateInput(selection);
coffeeBuilder.setSugar(selection == 1 ? true : false);
System.out.println("\nWould you like to have it Strong for ₹" + addonAndPrices.get("Strong") + " ?\n 1. Yes \n 2. No \n33. Exit from Addons \n44. Exit Order");
selection = takeIntUserInput();
validateInput(selection);
coffeeBuilder.setStrong(selection == 1 ? true : false);
System.out.println("\nWould you like have it very Hot for ₹" + addonAndPrices.get("Hot") + " ? \n 1. Yes \n 2. No \n33. Exit from Addons \n44. Exit Order");
selection = takeIntUserInput();
validateInput(selection);
coffeeBuilder.setHot(selection == 1 ? true : false);

}

private void validateInput(int selection){
// if(selection != 1 && selection != 2){
// System.out.println("\nYou have made an incorrect selection, could you please select again?\n");
// }
if(selection == 33){
checkOut(coffeeBuilder);
} else if(selection == 44 ){
exitFromApp();
}
}

private void displayCoffeeOptions(){

Map<String, Double> coffeeMap = inventory.getCoffeesAndPrices();
Map<Integer, String> coffeeSnoMap = inventory.getCoffeesAndSNo();
MAX_COFFESS = coffeeMap.size();

System.out.println("\nS.No Name Price\n");
for (int i = 1;i<=coffeeSnoMap.size();i++) {
System.out.println(i+ ". "+ coffeeSnoMap.get(i) + " ₹" + coffeeMap.get(coffeeSnoMap.get(i)));

}
System.out.println("\n *--* Enter 9 for exit *--* \n");
}

}
66 changes: 66 additions & 0 deletions CoffeeMachine/src/Inventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import java.util.*;

public class Inventory {

public static Inventory inventory ;
Map<Integer, String> coffeeSnoMap;
Map<String, Double> coffeePriceMap;
Map<Integer, String> addOnsSnoMap;
Map<String, Double> addOnsPriceMap;

public Inventory() {
coffeePriceMap = new HashMap<>();
coffeeSnoMap = new HashMap<>();
addOnsSnoMap = new HashMap<>();
addOnsPriceMap = new HashMap<>();
getCoffeesInfo();

}
public static Inventory getInventoryInstance(){
return (inventory == null)? new Inventory() : inventory;
}

public Map<String, Double> getCoffeesAndPrices(){
return coffeePriceMap;
}
public Map<String, Double> getAddonAndPrices(){
return addOnsPriceMap;
}
public Map<Integer, String> getCoffeesAndSNo(){
return coffeeSnoMap;
}

public String getCoffeeName(int sno){
return coffeeSnoMap.get(sno);
}

private void getCoffeesInfo(){

coffeePriceMap.put("Nescafe Classic", 120.0);
coffeePriceMap.put("Continental Extra", 110.50);
coffeePriceMap.put("Bru Instant", 85.10);
coffeePriceMap.put("Tata Coffee", 90.50);

coffeeSnoMap.put(1,"Nescafe Classic");
coffeeSnoMap.put(2,"Continental Extra");
coffeeSnoMap.put(3,"Bru Instant");
coffeeSnoMap.put(4, "Tata Coffee");

addOnsSnoMap.put(1, "Milk");
addOnsSnoMap.put(2, "Water");
addOnsSnoMap.put(3, "Sugar");
addOnsSnoMap.put(4, "Hot");
addOnsSnoMap.put(5, "Strong");

addOnsPriceMap.put("Milk", 10.0);
addOnsPriceMap.put("Water", 20.0);
addOnsPriceMap.put("Sugar", 10.0);
addOnsPriceMap.put("Hot", 5.0);
addOnsPriceMap.put("Strong", 15.0);


}



}
Loading