Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class CoffeePurchasingApp
- {
- public static void main(String[] args)
- {
- int choice, quantity, beverageDecision, pastryDecision, beverageChoice, pastryChoice, beverageQuantity, pastryQuantity;
- String name, couponCode;
- String[] validCoupon = {"COFFEE1", "LATTE23", "I<3JAVA", "SCONEZ", "MUFFIN!LOLOL"};
- boolean validCouponCode, validChoice, validPastry, validBeverage;
- Scanner kbd = new Scanner(System.in);
- Scanner stringScanner = new Scanner(System.in);
- System.out.println("Welcome to the Java Coffee Shop!");
- System.out.println("---Purchasing Menu---");
- System.out.println("1. Place an order");
- System.out.println("2. Check order status");
- System.out.println("3. Exit");
- System.out.println("Enter an action");
- int input = kbd.nextInt();
- boolean invalidInput = !(input == 1 || input == 2 || input == 3);
- if(invalidInput)
- {
- System.out.println("Error. Please enter a valid input");
- System.exit(0);
- }
- switch(input)
- {
- case 1:
- printMenu();
- System.out.println("Enter a name for the order: ");
- Scanner keyboard = new Scanner(System.in);
- name = keyboard.nextLine();
- System.out.println("Enter the item number: ");
- choice = kbd.nextInt();
- validChoice = (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5 || choice == 6);
- if(!validChoice)
- {
- System.out.println("Error, please enter a valid input.");
- System.exit(0);
- }
- System.out.println("Enter the quantity: ");
- quantity = kbd.nextInt();
- switch(choice)
- {
- case 1:
- System.out.println("Would you like to add a pastry? (Enter 0 for no, or 1 for no)");
- pastryChoice = kbd.nextInt();
- if(pastryChoice == 0)
- {
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- }
- System.out.println("Great! Which one would you like?");
- pastryDecision = kbd.nextInt();
- validPastry = (pastryDecision == 5 || pastryDecision == 6);
- if(!validPastry)
- {
- System.out.println("Error. Please enter a valid input.");
- System.exit(0);
- }
- System.out.println("And how many?");
- pastryQuantity = kbd.nextInt();
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- break;
- case 2:
- System.out.println("Would you like to add a pastry? (Enter 0 for no, or 1 for yes)");
- pastryChoice = kbd.nextInt();
- System.out.println("Great! Which one would you like?");
- pastryDecision = kbd.nextInt();
- validPastry = (pastryDecision == 5 || pastryDecision == 6);
- if(!validPastry)
- {
- System.out.println("Error. Please enter a valid input.");
- System.exit(0);
- }
- System.out.println("And how many?");
- pastryQuantity = kbd.nextInt();
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- break;
- case 3:
- System.out.println("Would one you like to add a pastry? (Enter 0 for no, or 1 for yes)");
- pastryChoice = kbd.nextInt();
- validChoice = (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5 || choice == 6);
- if(!validChoice)
- {
- System.out.println("Error, please enter a valid input.");
- System.exit(0);
- }
- if(pastryChoice == 0)
- {
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- }
- System.out.println("Great! Which one would you like?");
- pastryDecision = kbd.nextInt();
- validPastry = (pastryDecision == 5 || pastryDecision == 6);
- if(!validPastry)
- {
- System.out.println("Error. Please enter a valid input.");
- System.exit(0);
- }
- System.out.println("And how many?");
- pastryQuantity = kbd.nextInt();
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- break;
- case 4:
- System.out.println("Would you like to add a pastry? (Enter 0 for no, or 1 for yes)");
- pastryChoice = kbd.nextInt();
- if(pastryChoice == 0)
- {
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- }
- System.out.println("Great! Which one would you like?");
- pastryDecision = kbd.nextInt();
- validPastry = (pastryDecision == 5 || pastryDecision == 6);
- if(!validPastry)
- {
- System.out.println("Error. Please enter a valid input.");
- System.exit(0);
- }
- System.out.println("And how many?");
- pastryQuantity = kbd.nextInt();
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- break;
- case 5:
- System.out.println("Would you like to add a beverage? (Enter 0 for no, or 1 for yes)");
- beverageChoice = kbd.nextInt();
- if(beverageChoice == 0)
- {
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- }
- System.out.println("Great! Which one would you like?");
- beverageDecision = kbd.nextInt();
- validBeverage = (beverageDecision == 1 || beverageDecision == 2 || beverageDecision == 3 || beverageDecision == 4);
- if(!validBeverage)
- {
- System.out.println("Error. Please enter a valid input.");
- System.exit(0);
- }
- System.out.println("And how many?");
- beverageQuantity = kbd.nextInt();
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- break;
- case 6:
- System.out.println("Would you like to add a beverage? (Enter 0 for no, or 1 for yes)");
- beverageChoice = kbd.nextInt();
- if(beverageChoice == 0)
- {
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- }
- System.out.println("Great! Which one would you like?");
- beverageDecision = kbd.nextInt();
- validBeverage = (beverageDecision == 1 || beverageDecision == 2 || beverageDecision == 3 || beverageDecision == 4);
- if(!validBeverage)
- {
- System.out.println("Error. Please enter a valid input.");
- System.exit(0);
- }
- System.out.println("And how many?");
- beverageQuantity = kbd.nextInt();
- System.out.println("Enter a coupon code (or press ENTER to skip): ");
- couponCode = stringScanner.nextLine();
- validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
- if(validCouponCode)
- {
- System.out.println("Your code has been accepted! You will receive 20% off!");
- }
- break;
- }
- }
- }
- public static void printMenu()
- {
- System.out.println("Here is our menu: ");
- System.out.println("Item Number\t Item \t\t Cost ");
- System.out.println("1.\t\t Coffee \t $1.50");
- System.out.println("2.\t\t Latte \t\t $3.50");
- System.out.println("3.\t\t Cappuccino \t $3.25");
- System.out.println("4.\t\t Espresso \t $2.00");
- System.out.println("5.\t\t Scone \t\t $2.50");
- System.out.println("6.\t\t Muffin \t $3.00");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement