Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.24 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class CoffeePurchasingApp
  5. {
  6. public static void main(String[] args)
  7. {
  8. int choice, quantity, beverageDecision, pastryDecision, beverageChoice, pastryChoice, beverageQuantity, pastryQuantity;
  9. String name, couponCode;
  10. String[] validCoupon = {"COFFEE1", "LATTE23", "I<3JAVA", "SCONEZ", "MUFFIN!LOLOL"};
  11. boolean validCouponCode, validChoice, validPastry, validBeverage;
  12.  
  13. Scanner kbd = new Scanner(System.in);
  14. Scanner stringScanner = new Scanner(System.in);
  15.  
  16. System.out.println("Welcome to the Java Coffee Shop!");
  17.  
  18. System.out.println("---Purchasing Menu---");
  19. System.out.println("1. Place an order");
  20. System.out.println("2. Check order status");
  21. System.out.println("3. Exit");
  22. System.out.println("Enter an action");
  23.  
  24. int input = kbd.nextInt();
  25.  
  26. boolean invalidInput = !(input == 1 || input == 2 || input == 3);
  27.  
  28.  
  29. if(invalidInput)
  30. {
  31. System.out.println("Error. Please enter a valid input");
  32. System.exit(0);
  33. }
  34.  
  35. switch(input)
  36. {
  37. case 1:
  38. printMenu();
  39.  
  40. System.out.println("Enter a name for the order: ");
  41. Scanner keyboard = new Scanner(System.in);
  42. name = keyboard.nextLine();
  43.  
  44. System.out.println("Enter the item number: ");
  45. choice = kbd.nextInt();
  46.  
  47. validChoice = (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5 || choice == 6);
  48. if(!validChoice)
  49. {
  50. System.out.println("Error, please enter a valid input.");
  51. System.exit(0);
  52. }
  53.  
  54. System.out.println("Enter the quantity: ");
  55. quantity = kbd.nextInt();
  56.  
  57. switch(choice)
  58. {
  59. case 1:
  60. System.out.println("Would you like to add a pastry? (Enter 0 for no, or 1 for no)");
  61. pastryChoice = kbd.nextInt();
  62. if(pastryChoice == 0)
  63. {
  64. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  65. couponCode = stringScanner.nextLine();
  66.  
  67. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  68.  
  69. if(validCouponCode)
  70. {
  71. System.out.println("Your code has been accepted! You will receive 20% off!");
  72.  
  73. }
  74.  
  75. }
  76.  
  77. System.out.println("Great! Which one would you like?");
  78. pastryDecision = kbd.nextInt();
  79. validPastry = (pastryDecision == 5 || pastryDecision == 6);
  80.  
  81. if(!validPastry)
  82. {
  83. System.out.println("Error. Please enter a valid input.");
  84. System.exit(0);
  85. }
  86.  
  87. System.out.println("And how many?");
  88. pastryQuantity = kbd.nextInt();
  89.  
  90. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  91. couponCode = stringScanner.nextLine();
  92.  
  93. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  94.  
  95. if(validCouponCode)
  96. {
  97. System.out.println("Your code has been accepted! You will receive 20% off!");
  98.  
  99. }
  100.  
  101. break;
  102.  
  103.  
  104. case 2:
  105. System.out.println("Would you like to add a pastry? (Enter 0 for no, or 1 for yes)");
  106. pastryChoice = kbd.nextInt();
  107.  
  108.  
  109. System.out.println("Great! Which one would you like?");
  110. pastryDecision = kbd.nextInt();
  111. validPastry = (pastryDecision == 5 || pastryDecision == 6);
  112.  
  113. if(!validPastry)
  114. {
  115. System.out.println("Error. Please enter a valid input.");
  116. System.exit(0);
  117. }
  118.  
  119. System.out.println("And how many?");
  120. pastryQuantity = kbd.nextInt();
  121.  
  122. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  123. couponCode = stringScanner.nextLine();
  124.  
  125. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  126.  
  127. if(validCouponCode)
  128. {
  129. System.out.println("Your code has been accepted! You will receive 20% off!");
  130.  
  131. }
  132.  
  133.  
  134. break;
  135.  
  136. case 3:
  137. System.out.println("Would one you like to add a pastry? (Enter 0 for no, or 1 for yes)");
  138. pastryChoice = kbd.nextInt();
  139. validChoice = (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5 || choice == 6);
  140. if(!validChoice)
  141. {
  142. System.out.println("Error, please enter a valid input.");
  143. System.exit(0);
  144. }
  145.  
  146. if(pastryChoice == 0)
  147. {
  148. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  149. couponCode = stringScanner.nextLine();
  150.  
  151. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  152.  
  153. if(validCouponCode)
  154. {
  155. System.out.println("Your code has been accepted! You will receive 20% off!");
  156.  
  157. }
  158.  
  159. }
  160.  
  161. System.out.println("Great! Which one would you like?");
  162. pastryDecision = kbd.nextInt();
  163. validPastry = (pastryDecision == 5 || pastryDecision == 6);
  164.  
  165. if(!validPastry)
  166. {
  167. System.out.println("Error. Please enter a valid input.");
  168. System.exit(0);
  169. }
  170.  
  171.  
  172. System.out.println("And how many?");
  173. pastryQuantity = kbd.nextInt();
  174.  
  175. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  176. couponCode = stringScanner.nextLine();
  177.  
  178. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  179.  
  180. if(validCouponCode)
  181. {
  182. System.out.println("Your code has been accepted! You will receive 20% off!");
  183.  
  184. }
  185.  
  186.  
  187. break;
  188.  
  189. case 4:
  190. System.out.println("Would you like to add a pastry? (Enter 0 for no, or 1 for yes)");
  191. pastryChoice = kbd.nextInt();
  192. if(pastryChoice == 0)
  193. {
  194. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  195. couponCode = stringScanner.nextLine();
  196.  
  197. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  198.  
  199. if(validCouponCode)
  200. {
  201. System.out.println("Your code has been accepted! You will receive 20% off!");
  202.  
  203. }
  204.  
  205. }
  206.  
  207. System.out.println("Great! Which one would you like?");
  208. pastryDecision = kbd.nextInt();
  209. validPastry = (pastryDecision == 5 || pastryDecision == 6);
  210.  
  211. if(!validPastry)
  212. {
  213. System.out.println("Error. Please enter a valid input.");
  214. System.exit(0);
  215. }
  216.  
  217. System.out.println("And how many?");
  218. pastryQuantity = kbd.nextInt();
  219.  
  220. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  221. couponCode = stringScanner.nextLine();
  222.  
  223. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  224.  
  225. if(validCouponCode)
  226. {
  227. System.out.println("Your code has been accepted! You will receive 20% off!");
  228.  
  229. }
  230.  
  231.  
  232. break;
  233.  
  234. case 5:
  235. System.out.println("Would you like to add a beverage? (Enter 0 for no, or 1 for yes)");
  236. beverageChoice = kbd.nextInt();
  237. if(beverageChoice == 0)
  238. {
  239. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  240. couponCode = stringScanner.nextLine();
  241.  
  242. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  243.  
  244. if(validCouponCode)
  245. {
  246. System.out.println("Your code has been accepted! You will receive 20% off!");
  247.  
  248. }
  249.  
  250. }
  251.  
  252. System.out.println("Great! Which one would you like?");
  253. beverageDecision = kbd.nextInt();
  254. validBeverage = (beverageDecision == 1 || beverageDecision == 2 || beverageDecision == 3 || beverageDecision == 4);
  255.  
  256. if(!validBeverage)
  257. {
  258. System.out.println("Error. Please enter a valid input.");
  259. System.exit(0);
  260. }
  261.  
  262. System.out.println("And how many?");
  263. beverageQuantity = kbd.nextInt();
  264.  
  265. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  266. couponCode = stringScanner.nextLine();
  267.  
  268. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  269.  
  270. if(validCouponCode)
  271. {
  272. System.out.println("Your code has been accepted! You will receive 20% off!");
  273.  
  274. }
  275.  
  276.  
  277. break;
  278.  
  279. case 6:
  280. System.out.println("Would you like to add a beverage? (Enter 0 for no, or 1 for yes)");
  281. beverageChoice = kbd.nextInt();
  282. if(beverageChoice == 0)
  283. {
  284. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  285. couponCode = stringScanner.nextLine();
  286.  
  287. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  288.  
  289. if(validCouponCode)
  290. {
  291. System.out.println("Your code has been accepted! You will receive 20% off!");
  292.  
  293. }
  294.  
  295. }
  296.  
  297. System.out.println("Great! Which one would you like?");
  298. beverageDecision = kbd.nextInt();
  299. validBeverage = (beverageDecision == 1 || beverageDecision == 2 || beverageDecision == 3 || beverageDecision == 4);
  300.  
  301. if(!validBeverage)
  302. {
  303. System.out.println("Error. Please enter a valid input.");
  304. System.exit(0);
  305. }
  306.  
  307.  
  308. System.out.println("And how many?");
  309. beverageQuantity = kbd.nextInt();
  310.  
  311. System.out.println("Enter a coupon code (or press ENTER to skip): ");
  312. couponCode = stringScanner.nextLine();
  313.  
  314. validCouponCode = (couponCode.equals(validCoupon[0]) || couponCode.equals(validCoupon[1]) || couponCode.equals(validCoupon[2]) || couponCode.equals(validCoupon[3]) || couponCode.equals(validCoupon[4]) );
  315.  
  316. if(validCouponCode)
  317. {
  318. System.out.println("Your code has been accepted! You will receive 20% off!");
  319.  
  320. }
  321.  
  322.  
  323. break;
  324. }
  325.  
  326.  
  327. }
  328.  
  329. }
  330.  
  331. public static void printMenu()
  332. {
  333. System.out.println("Here is our menu: ");
  334. System.out.println("Item Number\t Item \t\t Cost ");
  335. System.out.println("1.\t\t Coffee \t $1.50");
  336. System.out.println("2.\t\t Latte \t\t $3.50");
  337. System.out.println("3.\t\t Cappuccino \t $3.25");
  338. System.out.println("4.\t\t Espresso \t $2.00");
  339. System.out.println("5.\t\t Scone \t\t $2.50");
  340. System.out.println("6.\t\t Muffin \t $3.00");
  341. }
  342.  
  343.  
  344. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement