n0s3c

Untitled

Jan 24th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.69 KB | None | 0 0
  1. /* **************************
  2. * Group project: Food ordering system
  3. * STIA1113: PROGRAMMING I
  4. *
  5. * Group members:
  6. * 1.Ibtihal Hasmad (274790)
  7. * 2.Rian Rashad Abdo Saeed AlAreqi (268922)
  8. *
  9. * Date last midified: 24/1/2020
  10. * description of the project:
  11. *
  12. *The Restaurant needs a program that helps students choosing their meals easily.
  13. The program will ask the user to input: Name,the choice of meal,
  14. additional meals if they like to add,and if they want to continue with the order.
  15. The data of the customer/customers will be stored within the program
  16. and there is 3% tax that will be charged from the customer automatically.
  17. Creating this application, will reduce reason for students to skip the meals,
  18. help them to avoid consuming ingredients that they are allergic to,
  19. part time for students who want to work for delivery foods, and also saving their times.
  20. ***************************
  21. *
  22. * User Guide:
  23. * 1.Choose one of the restaurants 1-3
  24. * 2.Choose your meal from the menu.
  25. * 3.If you want another meal type (yes).
  26. * 4.Enter your name.
  27. * 5.choose payment methods,pay by cash or by online banking.
  28. *
  29. ***************************
  30. */
  31. //Import the Scanner class
  32. import java.util.*;
  33. import java.time.format.DateTimeFormatter;
  34. import java.time.LocalDateTime;
  35. import java.util.ArrayList;
  36.  
  37. public class kfcmc {
  38.  
  39. // variable declaration
  40. static String extra;
  41. static String name;
  42. static String payment;
  43. static String student="";
  44. static int Kfc[] = new int[3];
  45. static String[] KfcMeal = {"Zinger Cheezy Combo", "Zinger Classic Wedges", "Zinger Stacker Wedges"};
  46. static double[] KfcPrice = {18.45, 20.00, 25.00};
  47. static int McDonald[] = new int[3];
  48. static String[] McMeal = {"McChicken Deluxe Combo", "Double Cheeseburger Combo", "Triple Cheeseburger Combo"};
  49. static double[] McPrice = {14.62, 16.97, 21.69};
  50. static int starbucks[] = new int[8];
  51. static String[] starbucksDrink = {"caffè Americano", "Caffe Latte Cappuccino", "Iced Coffee Fizzio", "Iced Shaken Lemon Zen Fizzio", "Green Tea Latte", "Black Tea Latte", "Hazelnut Hot Chocolate", "Caramel Hot Chocolate"};
  52. static double[] starbucksPrice = {9.55, 13.25, 11.65, 15.40, 15.35, 13.35, 14.30, 15.30};
  53. static int[] orders = new int[999];
  54. static double priceB, priceA, tax, discount, round, total, newtotal = 0;
  55. static int numOfOrder = 0, answer, mealChoice = 0, delete, numberChoice = 0, choice;
  56. static int[] toRemove = Kfc;
  57. static int counter = 0;
  58.  
  59.  
  60. // Create a Scanner to get user input
  61. static Scanner scan = new Scanner(System.in);
  62.  
  63. public static void main(String[] args) {
  64.  
  65. //variable declaration
  66.  
  67. do {
  68. //ask user to chioce resturant
  69. System.out.println("* Welcome to our resturant and café * ");
  70. System.out.println("-----------------------------");
  71. System.out.print("Choose one of the restaurants (1-3):\n"
  72. + "1.KFC\n"
  73. + "2.McDonald's\n"
  74. + "3.Starbucks\n"
  75. + "4.Exit\n"
  76. + "-----------------------------\n"
  77. + "enter here: ");
  78. //Read user input
  79. choice = scan.nextInt();
  80. System.out.println("-----------------------------");
  81.  
  82. // switch statement to chioce resturant
  83. switch (choice) {
  84. // values must be of same type of expression
  85. // check the statement if is true will display KFC's menu
  86. case 1:
  87. KFC();
  88.  
  89. break;// break is optional
  90. // check the statement if is true will display McDonald's menu
  91. case 2:
  92. McDonald();
  93.  
  94. break;// break is optional
  95. // check the statement if is true will display Starbuck's menu
  96. case 3:
  97. Starbucks();
  98.  
  99. break;// break is optional
  100. case 4:
  101. break;
  102. // We can have any number of case statements
  103. // below is default statement, used when none of the cases is true.
  104. default:
  105. System.out.println("Worng input!!! please try again\n");
  106. System.out.println("-----------------------------");
  107.  
  108. }
  109. // while choice not equil 4 will end the project
  110. } while (choice != 4);
  111. {
  112. System.out.println("Thank you and Bye Bye - ");
  113. }
  114.  
  115. }
  116.  
  117. // create a method KFC
  118. public static void KFC() {
  119. // method body
  120. // doing the loop
  121.  
  122. // do {
  123. //display KFC's menu
  124. System.out.print("KFC menu: Choose (1-3):\n\n"
  125. + "-----------------------------\n");
  126. System.out.println("1- Zinger Cheezy Combo = 18.45\n"
  127. + "2- Zinger Classic Wedges = 20.00\n"
  128. + "3- Zinger Stacker Wedges = 25.00\n"
  129. + "-----------------------------");
  130. askUser(Kfc, answer, mealChoice);
  131.  
  132. }
  133.  
  134. // create a method McDonald
  135. public static void McDonald() {
  136. // method body
  137. // doing the loop
  138.  
  139. //display McDonald's menu
  140. System.out.print("McDonald's menu: Choose (1-3):\n\n"
  141. + "-----------------------------\n");
  142. System.out.println("1- McChicken Deluxe Combo = 14.62\n"
  143. + "2- Double Cheeseburger Combo = 16.97\n"
  144. + "3- Triple Cheeseburger Combo = 21.69\n"
  145. + "-----------------------------");
  146. // display askUser
  147. askUser(Kfc, answer, mealChoice);
  148.  
  149. } // create a method Starbucks
  150.  
  151. public static void Starbucks() {
  152. // method body
  153. //doing the loop to choice drink
  154.  
  155. //display Starbuck's menu
  156. System.out.println("Starbucks menu:choose your drinks\n\n"
  157. + "-----------------------------\n"
  158. + " (ESPRESSO & COFFEE)\n"
  159. + "-----------------------------\n"
  160. + "1.caffè Americano: RM9.55\n"
  161. + "-----------------------------\n"
  162. + "2.Caffe Latte Cappuccino: RM13.25\n"
  163. + "-----------------------------\n"
  164. + "(FIZZIO)\n"
  165. + "-----------------------------\n"
  166. + "3.Iced Coffee Fizzio: RM11.65\n"
  167. + "-----------------------------\n"
  168. + "4.Iced Shaken Lemon Zen Fizzio: RM15.40\n"
  169. + "-----------------------------\n\n"
  170. + "(TEA)\n"
  171. + "-----------------------------\n"
  172. + "5.Green Tea Latte: RM15.35\n"
  173. + "-----------------------------\n"
  174. + "6.Black Tea Latte: RM13.35\n"
  175. + "-----------------------------\n\n"
  176. + "(CHOCOLATE)\n"
  177. + "-----------------------------\n"
  178. + "7.Hazelnut Hot Chocolate: RM14.30\n"
  179. + "-----------------------------\n"
  180. + "8.Caramel Hot Chocolate: RM15.30\n"
  181. + "-----------------------------\n");
  182. // display askUser
  183. askUser(Kfc, answer, mealChoice);
  184.  
  185. } // Create a method askUser
  186.  
  187. public static void askUser(int[] Kfc, int answer, int mealChoice) {
  188. // display askUser menu
  189. System.out.println("1-Add,remove and display order\n"
  190. + "2-Search resturant\n"
  191. + "3-continue to calculate\n"
  192. + "-----------------------------");
  193. //Read user input
  194. answer = scan.nextInt();
  195. // Switch statment to choice askUser
  196. switch (answer) {
  197. // values must be of same type of expression
  198. // check the statement if is true will display addRemoveDisply menu
  199. case 1:
  200. addRemoveDisply();
  201. break;// break is optional
  202. // check the statement if is true will display SearchResturant menu
  203. case 2:
  204. SearchResturant();
  205. break;// break is optional
  206. // check the statement if is true will display SearchResturant menu
  207. case 3:
  208. calculatePrice();
  209. break;// break is optional
  210.  
  211. // We can have any number of case statements
  212. // below is default statement, used when none of the cases is true.
  213. default:
  214. System.out.println("Sorry your choice is not in the list. Please choose again");
  215. }
  216. } // Create addRemoveDisply method
  217.  
  218. public static void addRemoveDisply() {
  219. //variable declaration
  220. double subtotal = 0;
  221.  
  222. char tin;
  223. //do loop
  224. do {
  225. // ask user to enter number of order
  226. System.out.println("Enter the number of your meal:");
  227. //user input
  228. mealChoice = scan.nextInt();
  229. //ask user to enter how many quantity does he want
  230. System.out.print("How many quantity do you want? ");
  231. // user input
  232. numberChoice = scan.nextInt();
  233. // if mealChoice more than 0 and less than 8
  234.  
  235. for(int x=0;x<numberChoice;x++){
  236. if(mealChoice ==1){
  237. orders[x]=0;
  238. counter +=1;
  239. }
  240. if(mealChoice ==2){
  241. orders[x]=1;
  242. counter +=1;
  243. }
  244. if(mealChoice ==3){
  245. orders[x]=2;
  246. counter +=1;
  247. }
  248.  
  249. }
  250. if (mealChoice > 0 && mealChoice < 8) {
  251. subtotal = Calculation(mealChoice);
  252. total = subtotal + (total);
  253.  
  254. if (mealChoice == 1) {
  255. System.out.println("Your total is: RM " + total);
  256. System.out.println("This is what you ordered: " + ":" + KfcMeal[0] + "\t" + KfcPrice[0] + "*" + numberChoice);
  257. // break;
  258. } else if (mealChoice == 2) {
  259. System.out.println("Your total is: RM " + total);
  260. System.out.println("This is what you ordered: " + ":" + KfcMeal[1] + "\t" + KfcPrice[1] + "*" + numberChoice);
  261. } else if (mealChoice == 3) {
  262. System.out.println("Your total is: RM " + total);
  263. System.out.println("This is what you ordered: " + ":" + KfcMeal[2] + "\t" + KfcPrice[2] + "*" + numberChoice);
  264. // mealChoice = 1;
  265. }
  266.  
  267. } else {
  268. //else error
  269. System.out.println("error input");
  270. }
  271.  
  272. System.out.print(
  273. "Input y for further purchases and input n to stop and get the total due: ");
  274. tin = scan.next().charAt(0);
  275. if (tin
  276. == 'n') {
  277. break;
  278. }
  279. } while (tin
  280. == 'y');
  281. System.out.println(
  282. "Do you want to edit your order y for yes and n for no");
  283. tin = scan.next().charAt(0);
  284.  
  285. //selection and loop for edit order
  286. switch (tin) {
  287. case 'y':
  288. while (tin == 'y') {
  289. System.out.print("Enter food number that you want to cancel:- ");
  290. int value = scan.nextInt();
  291. System.out.println(" ");
  292. if (value == mealChoice) {
  293. total = total - edit(value);
  294. value = mealChoice;
  295. System.out.print("Your new total is: Rm ");
  296. System.out.printf("%1.2f", total);
  297. System.out.println("");
  298. System.out.print("Do you want to remove your order y/n: ");
  299.  
  300. } else {
  301. System.out.println("Wrong value try agian");
  302.  
  303. continue;
  304. }
  305. tin = scan.next().charAt(0);
  306. }
  307. break;
  308. case 'n':
  309. System.out.println("Your total is: RM " + total);
  310. System.out.println("\n");
  311. break;
  312. default:
  313. System.out.println("Invalid Input");
  314. break;
  315.  
  316. }
  317. // display askUser meanu
  318. askUser(Kfc, answer, mealChoice);
  319. // do loop for number of orders, quantity and calculation the meals
  320. do {
  321. System.out.println("Enter the number of your order:");
  322. mealChoice = scan.nextInt();
  323. System.out.print("How many quantity do you want? ");
  324. numberChoice = scan.nextInt();
  325.  
  326. if (mealChoice > 0 && mealChoice < 8) {
  327.  
  328. subtotal = Calculation(mealChoice);
  329. total = subtotal + (total);
  330.  
  331. if (mealChoice == 1) {
  332. System.out.println("Your total is: RM " + total);
  333. System.out.println("This is what you ordered: " + ":" + McMeal[0] + "\t" + McPrice[0] + "*" + numberChoice);
  334. // break;
  335. } else if (mealChoice == 2) {
  336. System.out.println("Your total is: RM " + total);
  337. System.out.println("This is what you ordered: " + ":" + McMeal[1] + "\t" + McPrice[1] + "*" + numberChoice);
  338. } else if (mealChoice == 3) {
  339. System.out.println("Your total is: RM " + total);
  340. System.out.println("This is what you ordered: " + ":" + McMeal[2] + "\t" + McPrice[2] + "*" + numberChoice);
  341. // mealChoice = 1;
  342. }
  343.  
  344. } else {
  345. System.out.println("error input");
  346. }
  347.  
  348. System.out.print(
  349. "Input y for further purchases and input n to stop and get the total due: ");
  350. tin = scan.next().charAt(0);
  351. if (tin
  352. == 'n') {
  353. break;
  354. }
  355. } while (tin
  356. == 'y');
  357. System.out.println(
  358. "Do you want to edit your order y for yes and n for no");
  359. tin = scan.next().charAt(0);
  360.  
  361. //selection and loop for edit order
  362. switch (tin) {
  363. case 'y':
  364. while (tin == 'y') {
  365. System.out.print("Enter food number that you want to cancel:- ");
  366. int value = scan.nextInt();
  367. System.out.println(" ");
  368. if (value == mealChoice) {
  369. total = total - edit(value);
  370. value = mealChoice;
  371. System.out.print("Your new total is: Rm ");
  372. System.out.printf("%1.2f", total);
  373. System.out.println("");
  374. System.out.print("Do you want to remove your order y/n: ");
  375.  
  376. } else {
  377. System.out.println("Wrong value try agian");
  378.  
  379. continue;
  380. }
  381. tin = scan.next().charAt(0);
  382. }
  383. break;
  384. case 'n':
  385. System.out.println("Your total is: RM " + total);
  386. System.out.println("\n");
  387. break;
  388. default:
  389. System.out.println("Invalid Input");
  390. break;
  391.  
  392. }
  393. askUser(Kfc, answer, mealChoice);
  394.  
  395. }
  396. // calculation for kfc and mc price
  397. public static double Calculation(int mealChoice) {
  398. double KfcPrice[] = {0, 18.45, 20.00, 25.00};
  399. double total = KfcPrice[mealChoice] * numberChoice;
  400. double McPrice[] = {0, 14.62, 16.97, 21.69};
  401. double Mctotal = McPrice[mealChoice] * numberChoice;
  402. return total;
  403.  
  404. }
  405. // for edit the kfc meanu
  406. public static double edit(int num) {
  407. double menu[] = {0, 18.45, 20.00, 25.00};
  408. double value = menu[num];
  409. return value;
  410. }
  411. // Create method SearchResturant
  412. public static void SearchResturant() {
  413. System.out.print("-----------------------------\n");
  414. System.out.print("Choose one of the restaurants (1-3):\n"
  415. + "1.KFC\n"
  416. + "2.McDonald's\n"
  417. + "3.Starbucks\n");
  418. System.out.print("-----------------------------\n");
  419. System.out.print("Choice your resturant:");
  420. int resturant = scan.nextInt();
  421. switch (resturant) {
  422. // values must be of same type of expression
  423. // check the statement if is true will display KFC's menu
  424. case 1:
  425. KFC();
  426.  
  427. break;// break is optional
  428. // check the statement if is true will display McDonald's menu
  429. case 2:
  430. McDonald();
  431.  
  432. break;// break is optional
  433. // check the statement if is true will display Starbuck's menu
  434. case 3:
  435. Starbucks();
  436.  
  437. break;// break is optional
  438.  
  439. // We can have any number of case statements
  440. // below is default statement, used when none of the cases is true.
  441. default:
  442. System.out.println("Worng input!!! please try again\n");
  443. System.out.println("-----------------------------");
  444.  
  445. }
  446. }
  447.  
  448. // create a method for calculate price
  449. public static void calculatePrice() {
  450. // System.out.print("-----------------------------\n");
  451. System.out.print("Please enter your name: ");
  452. //Read user input
  453. name = scan.next();
  454. System.out.print("---------------------------------------------\n");
  455. //ask user if want to pay cash or by online
  456. System.out.print("Payment method [c:Cash b:ByOnline] : ");
  457. //Read user input
  458. payment = scan.next();
  459. System.out.print("---------------------------------------------\n");
  460. //Executes when the Boolean expression is true
  461. //checks if the user want to pay cash
  462. if (payment.equalsIgnoreCase("c")) {
  463. payment = "Cash";
  464. // Executes when the none of the above condition is true.
  465. //checks if the user want to pay by online
  466. }else if(payment.equalsIgnoreCase("b")){
  467. payment = "ByOnline";
  468. }
  469. else {
  470. //default by cash
  471. payment = "Cash";
  472. }
  473. //ask user if is student
  474.  
  475. System.out.println();
  476. System.out.printf("%25s%n", "CHECK");
  477. System.out.println("---------------------------------------------");
  478. //calculate the date and the time
  479. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
  480. LocalDateTime now = LocalDateTime.now();
  481. System.out.println(" " + dtf.format(now));
  482. // for loop to calculate meal's price
  483.  
  484. for(int i=0;i<counter;i++){
  485. Object d = orders[i];
  486. if(d !=null){
  487. System.out.println( KfcMeal[orders[i]] + " x1"+ "\t" + KfcPrice[orders[i]]);
  488.  
  489. }
  490. }
  491.  
  492.  
  493. // calculate the tax
  494. tax = priceB * (3 / 100);
  495. //Executes when the Boolean expression is true
  496. //checks if the user is student to calculate meal's price with discount
  497. if ("y".equals(student.toLowerCase()) && numOfOrder > 5) {
  498. discount = priceB * (5 / 100);
  499. priceA = priceB + tax - discount;
  500. // Executes when the none of the above condition is true.
  501. //checks if the user is not student to calculate meal's price without discount
  502. } else {
  503. priceA = priceB + tax;
  504. }
  505. //calculate the amount
  506. // and print the bill
  507. double feeService = 2.50;
  508. double priceA = total + feeService;
  509. round = Math.round(Math.round(total) / 10) * 10 + 10;
  510. System.out.print("---------------------------------------------\n");
  511. System.out.printf("%35s%10.2f%n", "Total", total);
  512. System.out.println("Item : " + counter);
  513. System.out.printf("Tax %.2f%n", tax);
  514. // System.out.printf("%-9s%.2f%22s%10.2f%n", "Fee service", "Total", priceA,feeService);
  515. System.out.printf("%-9s%.2f%22s%10.2f%n", "You Save", discount, "Total", priceA);
  516. System.out.printf("%-30s%-8s%7.2f%n", "Payment Method", payment, (total + 10));
  517. System.out.printf("%36s%9.2f%n", "Change", (round - Math.round(total * 100.0) / 100.0));
  518. System.out.println("---------------------------------------------");
  519. System.out.println("Thank You " + "Mr/Mrs: " + name
  520. + "\nPlease Come Again\nFoods Sold Are Not Returnable");
  521. System.exit(0);
  522. }
  523.  
  524. }
Advertisement
Add Comment
Please, Sign In to add comment