Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. /* Create a Coffee Shop application that uses a while loop to build a customer order. The Coffee Shops sells coffee ($3.25), espresso ($4.25), and tea ($2.75). The coffee selection presents the customer with the choices of iced (no charge), cream (50 cents), and sugar (50 cents). The espresso selection presents the customer with choice of caramel (no charge) and chocolate (no charge) with one shot (no charge) or two shots ($1.25) of espresso. Once the customer is done, he or she will receive a bill of the total price. After each selection, the customer will have the choice of returning to the main menu for additional purchases. Use nested loops to handle customers' submenu selections. */
  2. // Author: Alex Bennett
  3. // Date: 4/7/19
  4.  
  5. import java.util.Scanner;
  6. import java.util.Arrays;
  7. import java.util.List;
  8.  
  9. public class CoffeeShop {
  10. double coffee = 3.25;
  11. double espresso = 4.25;
  12. double tea = 2.75;
  13. double iced = 0;
  14. double cream = 0.50;
  15. double sugar = 0.50;
  16. double carmel = 0;
  17. double chocolate = 0;
  18. double shot = 0;
  19. double runningTotal;
  20. String customerSelection;
  21. double arr[] = {0,1,2};
  22. int firstTime =0;
  23. int prepOne = 0;
  24. int prepTwo = 0;
  25. int prepThree = 0;
  26.  
  27. String[] coffeePrep = {"iced", "with cream", "with sugar"};
  28. String[] espressoPrep = {"carmel", "chocolate", "one shot", "two shots"};
  29.  
  30.  
  31. public void getSelection()
  32. {
  33. Scanner keyboard = new Scanner(System.in);
  34. do
  35. {
  36. System.out.print("Welcome to the coffee shop. Please select the following selection: coffee, espresso, or tea.");
  37. customerSelection = keyboard.next();
  38. }
  39. while (customerSelection.equals("coffee") || customerSelection.equals("espresso") || customerSelection.equals("tea"));
  40. {
  41. System.out.println("You entered and invalid selection. Please select the following selection: coffee, espresso, or tea.");
  42. }
  43. while (customerSelection.equals("coffee"))
  44. {
  45. runningTotal = coffee;
  46. System.out.println("You selected coffee. Please select the following preparations: iced, cream, or sugar.");
  47. for (int i = 0; i < coffeePrep.length; ++ i)
  48. {
  49. System.out.println("Would you like it prepared " + i);
  50. customerSelection = keyboard.next();
  51. if (customerSelection.equals("iced"))
  52. {
  53. runningTotal = runningTotal + iced;
  54. }
  55. if (customerSelection.equals("cream"))
  56. {
  57. runningTotal = runningTotal + cream;
  58. }
  59. if (customerSelection.equals("sugar"))
  60. {
  61. runningTotal = runningTotal + sugar;
  62. }
  63. if (customerSelection.length() > 2)
  64. {
  65. System.out.println("Your coffee total is $" + runningTotal);
  66. System.out.println("\nWould you like to make another selection? (yes or no)");
  67. customerSelection = keyboard.next();
  68. while (customerSelection.equals("no"))
  69. {
  70. System.out.println("Thank you! Please come again.");
  71. System.exit(0);
  72. }
  73. }
  74.  
  75.  
  76. }
  77.  
  78. }
  79. while (customerSelection.equals("espresso"))
  80. {
  81. runningTotal = espresso;
  82. System.out.println("You selected espresso. Please select the following preparations: carmel, chocolate, one shot, or two shots.");
  83. for (int = 0; i < espressoPrep.length; ++ i)
  84. }
  85.  
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement