Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Starbucks;
- import java.util.*;
- public class Starbucks {
- private static final String MAKE_AN_ORDER = "1";
- private static final String ORDERS = "2";
- private static final String BILL = "3";
- private static final String REMOVE = "4";
- private static final String EXIT = "0";
- private static final String Choice = "Please choose an option:";
- private static final String Welcome = "***************WELCOME**************";
- /*
- Done 1. When the customer order list is empty and he chose to see his current order - Print that he hasn't ordered anything yet.
- Done 2. Transform the multiple if/else to a switch case. Check examples how switch works.
- Done 3. There should not be any coma after the last item in the order list.
- Done 4. Add a new option in the menu called: I want to pay. It should print out the price. Each item costs 5.51 euro.
- Done 5. Move the project to a separate package
- */
- /*
- Done 6. Learn how to format your code in IntelliJ - a keyboard shortcut combination
- Done 7. Optimize your code to use defined constants instead of the same String written many times
- Done 8. Every single item should have it's own price. ex. Espresso - 2.50 euro, Cappuccino - 3.50. Maybe use HashMap in a way ? Check examples and what is it used for?
- Done 9. The client should be able to remove an item from his order (This should reduce also the price. Just keep in mind when testing.)
- Done 10. The method payTheBill should not PRINT, it should directly return the price. Then the price should be print in the main method.
- */
- /*
- Done 11. What is the difference between BREAK and RETURN in examples! Not stupid theory
- 12. Rename CurrentOrder to Item
- Done 13. Include also FOOD in the menu
- Done 14. What is the difference between Class and Object ? What is interface ?
- Done 15. What is an abstract method in interface ? How to implement abstract methods?
- Done 16. Define all of the food/drink as classes like: class Espresso / class Burger they will extend an interface
- Food with abstract methods: getPrice and getCalories which needs to be implemented in the classes who extends it.
- So the price should be defined in the method per different class. ex.Espresso
- Done 17. The HashMap should contain those objects as a Key and the value of the map should be the available count of the items.
- Like: map (Espresso, 10)
- 18. When the client orders the exiting count of our products should decrease
- 19. All the functionality should remain working.
- */
- private static HashMap<Food, Integer> menu = new HashMap<>();
- private static List<CurrentOrder> currentOrderList = new ArrayList<>();
- public static double price = 0.0;
- public static void main(String[] args) {
- Cappuccino cappuccino = new Cappuccino();
- Cake cake = new Cake();
- Espresso espresso = new Espresso();
- Burger cheeseburger = new Burger();
- menu.put(espresso, 10);
- menu.put(cappuccino, 30);
- menu.put(cheeseburger, 40);
- menu.put(cake, 25);
- String customerChoice = "";
- while (!customerChoice.equalsIgnoreCase(EXIT)) {
- customerChoice = menu();
- switch (customerChoice) {
- case MAKE_AN_ORDER:
- makeAnOrder();
- break;
- case ORDERS:
- if (currentOrderList.isEmpty()) {
- System.out.println("You haven`t ordered yet!");
- } else {
- System.out.println("Your current order is: ");
- printCurrentOrderList();
- }
- break;
- case BILL:
- if (currentOrderList.isEmpty()) {
- System.out.println("You haven`t ordered yet!");
- return;
- } else {
- double bill = payTheBill();
- System.out.println("Your totalBill is: " + bill + " Euro.");
- }
- break;
- case REMOVE:
- if (currentOrderList.isEmpty()) {
- System.out.println("You haven`t ordered yet!");
- return;
- } else {
- remove();
- }
- break;
- case EXIT:
- System.out.println("Thank you for coming! Have a nice day!");
- break;
- }
- System.out.println();
- }
- }
- private static void makeAnOrder() {
- System.out.println("Available drinks: ");
- System.out.println();
- for (Map.Entry item : menu.entrySet()) {
- System.out.println(item.getKey() +":" );
- System.out.println(item.getKey() + ": " );
- System.out.println(item.getKey()+ ": " );
- System.out.println(item.getKey() + ": ");
- }
- System.out.println("Choice:");
- Scanner scanner = new Scanner(System.in);
- String item = scanner.nextLine();
- currentOrderList.add(new CurrentOrder(item));
- }
- private static double payTheBill() {
- double totalAmount = 0;
- for (CurrentOrder currentOrder : currentOrderList) {
- totalAmount += menu.get(currentOrder.getCurrentOrder());
- }
- return totalAmount;
- }
- private static void printCurrentOrderList() {
- for (CurrentOrder currentOrder : currentOrderList) {
- CurrentOrder lastOrder = currentOrderList.get(currentOrderList.size() - 1);
- if (currentOrder.getCurrentOrder().equalsIgnoreCase(lastOrder.getCurrentOrder())) {
- System.out.print(currentOrder.getCurrentOrder());
- } else {
- System.out.print(currentOrder.getCurrentOrder() + ", ");
- }
- }
- }
- private static void remove() {
- System.out.println("Please enter an item you want to remove: ");
- Scanner scanner = new Scanner(System.in);
- String itemToBeRemoved = scanner.nextLine();
- CurrentOrder foundItem = null;
- for (CurrentOrder order : currentOrderList) {
- if (order.getCurrentOrder().equalsIgnoreCase(itemToBeRemoved)) {
- foundItem = order;
- }
- }
- if (foundItem != null) {
- currentOrderList.remove(foundItem);
- }
- }
- private static String menu() {
- System.out.println(Welcome);
- System.out.println("1.Make an order");
- System.out.println("2.Check your order");
- System.out.println("3.Pay the bill");
- System.out.println("4.Remove order item");
- System.out.println("0.Exit");
- System.out.print(Choice);
- Scanner yourChoice = new Scanner(System.in);
- return yourChoice.nextLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement