Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* **************************
- * Group project: Food ordering system
- * STIA1113: PROGRAMMING I
- *
- * Group members:
- * 1.Ibtihal Hasmad (274790)
- * 2.Rian Rashad Abdo Saeed AlAreqi (268922)
- *
- * Date last midified: 24/1/2020
- * description of the project:
- *
- *The Restaurant needs a program that helps students choosing their meals easily.
- The program will ask the user to input: Name,the choice of meal,
- additional meals if they like to add,and if they want to continue with the order.
- The data of the customer/customers will be stored within the program
- and there is 3% tax that will be charged from the customer automatically.
- Creating this application, will reduce reason for students to skip the meals,
- help them to avoid consuming ingredients that they are allergic to,
- part time for students who want to work for delivery foods, and also saving their times.
- ***************************
- *
- * User Guide:
- * 1.Choose one of the restaurants 1-3
- * 2.Choose your meal from the menu.
- * 3.If you want another meal type (yes).
- * 4.Enter your name.
- * 5.choose payment methods,pay by cash or by online banking.
- *
- ***************************
- */
- //Import the Scanner class
- import java.util.*;
- import java.time.format.DateTimeFormatter;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- public class kfcmc {
- // variable declaration
- static String extra;
- static String name;
- static String payment;
- static String student="";
- static int Kfc[] = new int[3];
- static String[] KfcMeal = {"Zinger Cheezy Combo", "Zinger Classic Wedges", "Zinger Stacker Wedges"};
- static double[] KfcPrice = {18.45, 20.00, 25.00};
- static int McDonald[] = new int[3];
- static String[] McMeal = {"McChicken Deluxe Combo", "Double Cheeseburger Combo", "Triple Cheeseburger Combo"};
- static double[] McPrice = {14.62, 16.97, 21.69};
- static int starbucks[] = new int[8];
- 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"};
- static double[] starbucksPrice = {9.55, 13.25, 11.65, 15.40, 15.35, 13.35, 14.30, 15.30};
- static int[] orders = new int[999];
- static double priceB, priceA, tax, discount, round, total, newtotal = 0;
- static int numOfOrder = 0, answer, mealChoice = 0, delete, numberChoice = 0, choice;
- static int[] toRemove = Kfc;
- static int counter = 0;
- // Create a Scanner to get user input
- static Scanner scan = new Scanner(System.in);
- public static void main(String[] args) {
- //variable declaration
- do {
- //ask user to chioce resturant
- System.out.println("* Welcome to our resturant and café * ");
- System.out.println("-----------------------------");
- System.out.print("Choose one of the restaurants (1-3):\n"
- + "1.KFC\n"
- + "2.McDonald's\n"
- + "3.Starbucks\n"
- + "4.Exit\n"
- + "-----------------------------\n"
- + "enter here: ");
- //Read user input
- choice = scan.nextInt();
- System.out.println("-----------------------------");
- // switch statement to chioce resturant
- switch (choice) {
- // values must be of same type of expression
- // check the statement if is true will display KFC's menu
- case 1:
- KFC();
- break;// break is optional
- // check the statement if is true will display McDonald's menu
- case 2:
- McDonald();
- break;// break is optional
- // check the statement if is true will display Starbuck's menu
- case 3:
- Starbucks();
- break;// break is optional
- case 4:
- break;
- // We can have any number of case statements
- // below is default statement, used when none of the cases is true.
- default:
- System.out.println("Worng input!!! please try again\n");
- System.out.println("-----------------------------");
- }
- // while choice not equil 4 will end the project
- } while (choice != 4);
- {
- System.out.println("Thank you and Bye Bye - ");
- }
- }
- // create a method KFC
- public static void KFC() {
- // method body
- // doing the loop
- // do {
- //display KFC's menu
- System.out.print("KFC menu: Choose (1-3):\n\n"
- + "-----------------------------\n");
- System.out.println("1- Zinger Cheezy Combo = 18.45\n"
- + "2- Zinger Classic Wedges = 20.00\n"
- + "3- Zinger Stacker Wedges = 25.00\n"
- + "-----------------------------");
- askUser(Kfc, answer, mealChoice);
- }
- // create a method McDonald
- public static void McDonald() {
- // method body
- // doing the loop
- //display McDonald's menu
- System.out.print("McDonald's menu: Choose (1-3):\n\n"
- + "-----------------------------\n");
- System.out.println("1- McChicken Deluxe Combo = 14.62\n"
- + "2- Double Cheeseburger Combo = 16.97\n"
- + "3- Triple Cheeseburger Combo = 21.69\n"
- + "-----------------------------");
- // display askUser
- askUser(Kfc, answer, mealChoice);
- } // create a method Starbucks
- public static void Starbucks() {
- // method body
- //doing the loop to choice drink
- //display Starbuck's menu
- System.out.println("Starbucks menu:choose your drinks\n\n"
- + "-----------------------------\n"
- + " (ESPRESSO & COFFEE)\n"
- + "-----------------------------\n"
- + "1.caffè Americano: RM9.55\n"
- + "-----------------------------\n"
- + "2.Caffe Latte Cappuccino: RM13.25\n"
- + "-----------------------------\n"
- + "(FIZZIO)\n"
- + "-----------------------------\n"
- + "3.Iced Coffee Fizzio: RM11.65\n"
- + "-----------------------------\n"
- + "4.Iced Shaken Lemon Zen Fizzio: RM15.40\n"
- + "-----------------------------\n\n"
- + "(TEA)\n"
- + "-----------------------------\n"
- + "5.Green Tea Latte: RM15.35\n"
- + "-----------------------------\n"
- + "6.Black Tea Latte: RM13.35\n"
- + "-----------------------------\n\n"
- + "(CHOCOLATE)\n"
- + "-----------------------------\n"
- + "7.Hazelnut Hot Chocolate: RM14.30\n"
- + "-----------------------------\n"
- + "8.Caramel Hot Chocolate: RM15.30\n"
- + "-----------------------------\n");
- // display askUser
- askUser(Kfc, answer, mealChoice);
- } // Create a method askUser
- public static void askUser(int[] Kfc, int answer, int mealChoice) {
- // display askUser menu
- System.out.println("1-Add,remove and display order\n"
- + "2-Search resturant\n"
- + "3-continue to calculate\n"
- + "-----------------------------");
- //Read user input
- answer = scan.nextInt();
- // Switch statment to choice askUser
- switch (answer) {
- // values must be of same type of expression
- // check the statement if is true will display addRemoveDisply menu
- case 1:
- addRemoveDisply();
- break;// break is optional
- // check the statement if is true will display SearchResturant menu
- case 2:
- SearchResturant();
- break;// break is optional
- // check the statement if is true will display SearchResturant menu
- case 3:
- calculatePrice();
- break;// break is optional
- // We can have any number of case statements
- // below is default statement, used when none of the cases is true.
- default:
- System.out.println("Sorry your choice is not in the list. Please choose again");
- }
- } // Create addRemoveDisply method
- public static void addRemoveDisply() {
- //variable declaration
- double subtotal = 0;
- char tin;
- //do loop
- do {
- // ask user to enter number of order
- System.out.println("Enter the number of your meal:");
- //user input
- mealChoice = scan.nextInt();
- //ask user to enter how many quantity does he want
- System.out.print("How many quantity do you want? ");
- // user input
- numberChoice = scan.nextInt();
- // if mealChoice more than 0 and less than 8
- for(int x=0;x<numberChoice;x++){
- if(mealChoice ==1){
- orders[x]=0;
- counter +=1;
- }
- if(mealChoice ==2){
- orders[x]=1;
- counter +=1;
- }
- if(mealChoice ==3){
- orders[x]=2;
- counter +=1;
- }
- }
- if (mealChoice > 0 && mealChoice < 8) {
- subtotal = Calculation(mealChoice);
- total = subtotal + (total);
- if (mealChoice == 1) {
- System.out.println("Your total is: RM " + total);
- System.out.println("This is what you ordered: " + ":" + KfcMeal[0] + "\t" + KfcPrice[0] + "*" + numberChoice);
- // break;
- } else if (mealChoice == 2) {
- System.out.println("Your total is: RM " + total);
- System.out.println("This is what you ordered: " + ":" + KfcMeal[1] + "\t" + KfcPrice[1] + "*" + numberChoice);
- } else if (mealChoice == 3) {
- System.out.println("Your total is: RM " + total);
- System.out.println("This is what you ordered: " + ":" + KfcMeal[2] + "\t" + KfcPrice[2] + "*" + numberChoice);
- // mealChoice = 1;
- }
- } else {
- //else error
- System.out.println("error input");
- }
- System.out.print(
- "Input y for further purchases and input n to stop and get the total due: ");
- tin = scan.next().charAt(0);
- if (tin
- == 'n') {
- break;
- }
- } while (tin
- == 'y');
- System.out.println(
- "Do you want to edit your order y for yes and n for no");
- tin = scan.next().charAt(0);
- //selection and loop for edit order
- switch (tin) {
- case 'y':
- while (tin == 'y') {
- System.out.print("Enter food number that you want to cancel:- ");
- int value = scan.nextInt();
- System.out.println(" ");
- if (value == mealChoice) {
- total = total - edit(value);
- value = mealChoice;
- System.out.print("Your new total is: Rm ");
- System.out.printf("%1.2f", total);
- System.out.println("");
- System.out.print("Do you want to remove your order y/n: ");
- } else {
- System.out.println("Wrong value try agian");
- continue;
- }
- tin = scan.next().charAt(0);
- }
- break;
- case 'n':
- System.out.println("Your total is: RM " + total);
- System.out.println("\n");
- break;
- default:
- System.out.println("Invalid Input");
- break;
- }
- // display askUser meanu
- askUser(Kfc, answer, mealChoice);
- // do loop for number of orders, quantity and calculation the meals
- do {
- System.out.println("Enter the number of your order:");
- mealChoice = scan.nextInt();
- System.out.print("How many quantity do you want? ");
- numberChoice = scan.nextInt();
- if (mealChoice > 0 && mealChoice < 8) {
- subtotal = Calculation(mealChoice);
- total = subtotal + (total);
- if (mealChoice == 1) {
- System.out.println("Your total is: RM " + total);
- System.out.println("This is what you ordered: " + ":" + McMeal[0] + "\t" + McPrice[0] + "*" + numberChoice);
- // break;
- } else if (mealChoice == 2) {
- System.out.println("Your total is: RM " + total);
- System.out.println("This is what you ordered: " + ":" + McMeal[1] + "\t" + McPrice[1] + "*" + numberChoice);
- } else if (mealChoice == 3) {
- System.out.println("Your total is: RM " + total);
- System.out.println("This is what you ordered: " + ":" + McMeal[2] + "\t" + McPrice[2] + "*" + numberChoice);
- // mealChoice = 1;
- }
- } else {
- System.out.println("error input");
- }
- System.out.print(
- "Input y for further purchases and input n to stop and get the total due: ");
- tin = scan.next().charAt(0);
- if (tin
- == 'n') {
- break;
- }
- } while (tin
- == 'y');
- System.out.println(
- "Do you want to edit your order y for yes and n for no");
- tin = scan.next().charAt(0);
- //selection and loop for edit order
- switch (tin) {
- case 'y':
- while (tin == 'y') {
- System.out.print("Enter food number that you want to cancel:- ");
- int value = scan.nextInt();
- System.out.println(" ");
- if (value == mealChoice) {
- total = total - edit(value);
- value = mealChoice;
- System.out.print("Your new total is: Rm ");
- System.out.printf("%1.2f", total);
- System.out.println("");
- System.out.print("Do you want to remove your order y/n: ");
- } else {
- System.out.println("Wrong value try agian");
- continue;
- }
- tin = scan.next().charAt(0);
- }
- break;
- case 'n':
- System.out.println("Your total is: RM " + total);
- System.out.println("\n");
- break;
- default:
- System.out.println("Invalid Input");
- break;
- }
- askUser(Kfc, answer, mealChoice);
- }
- // calculation for kfc and mc price
- public static double Calculation(int mealChoice) {
- double KfcPrice[] = {0, 18.45, 20.00, 25.00};
- double total = KfcPrice[mealChoice] * numberChoice;
- double McPrice[] = {0, 14.62, 16.97, 21.69};
- double Mctotal = McPrice[mealChoice] * numberChoice;
- return total;
- }
- // for edit the kfc meanu
- public static double edit(int num) {
- double menu[] = {0, 18.45, 20.00, 25.00};
- double value = menu[num];
- return value;
- }
- // Create method SearchResturant
- public static void SearchResturant() {
- System.out.print("-----------------------------\n");
- System.out.print("Choose one of the restaurants (1-3):\n"
- + "1.KFC\n"
- + "2.McDonald's\n"
- + "3.Starbucks\n");
- System.out.print("-----------------------------\n");
- System.out.print("Choice your resturant:");
- int resturant = scan.nextInt();
- switch (resturant) {
- // values must be of same type of expression
- // check the statement if is true will display KFC's menu
- case 1:
- KFC();
- break;// break is optional
- // check the statement if is true will display McDonald's menu
- case 2:
- McDonald();
- break;// break is optional
- // check the statement if is true will display Starbuck's menu
- case 3:
- Starbucks();
- break;// break is optional
- // We can have any number of case statements
- // below is default statement, used when none of the cases is true.
- default:
- System.out.println("Worng input!!! please try again\n");
- System.out.println("-----------------------------");
- }
- }
- // create a method for calculate price
- public static void calculatePrice() {
- // System.out.print("-----------------------------\n");
- System.out.print("Please enter your name: ");
- //Read user input
- name = scan.next();
- System.out.print("---------------------------------------------\n");
- //ask user if want to pay cash or by online
- System.out.print("Payment method [c:Cash b:ByOnline] : ");
- //Read user input
- payment = scan.next();
- System.out.print("---------------------------------------------\n");
- //Executes when the Boolean expression is true
- //checks if the user want to pay cash
- if (payment.equalsIgnoreCase("c")) {
- payment = "Cash";
- // Executes when the none of the above condition is true.
- //checks if the user want to pay by online
- }else if(payment.equalsIgnoreCase("b")){
- payment = "ByOnline";
- }
- else {
- //default by cash
- payment = "Cash";
- }
- //ask user if is student
- System.out.println();
- System.out.printf("%25s%n", "CHECK");
- System.out.println("---------------------------------------------");
- //calculate the date and the time
- DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
- LocalDateTime now = LocalDateTime.now();
- System.out.println(" " + dtf.format(now));
- // for loop to calculate meal's price
- for(int i=0;i<counter;i++){
- Object d = orders[i];
- if(d !=null){
- System.out.println( KfcMeal[orders[i]] + " x1"+ "\t" + KfcPrice[orders[i]]);
- }
- }
- // calculate the tax
- tax = priceB * (3 / 100);
- //Executes when the Boolean expression is true
- //checks if the user is student to calculate meal's price with discount
- if ("y".equals(student.toLowerCase()) && numOfOrder > 5) {
- discount = priceB * (5 / 100);
- priceA = priceB + tax - discount;
- // Executes when the none of the above condition is true.
- //checks if the user is not student to calculate meal's price without discount
- } else {
- priceA = priceB + tax;
- }
- //calculate the amount
- // and print the bill
- double feeService = 2.50;
- double priceA = total + feeService;
- round = Math.round(Math.round(total) / 10) * 10 + 10;
- System.out.print("---------------------------------------------\n");
- System.out.printf("%35s%10.2f%n", "Total", total);
- System.out.println("Item : " + counter);
- System.out.printf("Tax %.2f%n", tax);
- // System.out.printf("%-9s%.2f%22s%10.2f%n", "Fee service", "Total", priceA,feeService);
- System.out.printf("%-9s%.2f%22s%10.2f%n", "You Save", discount, "Total", priceA);
- System.out.printf("%-30s%-8s%7.2f%n", "Payment Method", payment, (total + 10));
- System.out.printf("%36s%9.2f%n", "Change", (round - Math.round(total * 100.0) / 100.0));
- System.out.println("---------------------------------------------");
- System.out.println("Thank You " + "Mr/Mrs: " + name
- + "\nPlease Come Again\nFoods Sold Are Not Returnable");
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment