Advertisement
Niloy007

Rownak Vai's Assignment

Aug 30th, 2020
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.59 KB | None | 0 0
  1. package Test;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.Scanner;
  6.  
  7. class FoodeliverMenu {
  8.     String foodCode, foodName;
  9.     double price;
  10.     FoodeliverMenu(String foodCode, String foodname, double price) {
  11.         this.foodCode = foodCode;
  12.         this.foodName = foodname;
  13.         this.price = price;
  14.     }
  15. }
  16.  
  17.  
  18.  
  19. class Restaurant extends FoodeliverMenu {
  20.     Restaurant(String foodCode, String foodname, double price) {
  21.         super(foodCode, foodname, price);
  22.     }
  23. }
  24.  
  25.  
  26. class Customer extends FoodeliverMenu {
  27.     boolean isCollected = false;
  28.     void isCollected() {
  29.         isCollected = true;
  30.     }
  31.  
  32.     public Customer(String foodCode, String foodname, double price) {
  33.         super(foodCode, foodname, price);
  34.     }
  35. }
  36.  
  37.  
  38. public class Test {
  39.     Scanner scanner = new Scanner(System.in);
  40.     private static ArrayList<Restaurant> RestaurantOne = new ArrayList<Restaurant>();
  41.     private static ArrayList<Restaurant> RestaurantTwo = new ArrayList<Restaurant>();
  42.     private static ArrayList<Restaurant> RestaurantThree = new ArrayList<Restaurant>();
  43.     private static ArrayList<Customer> selectedItems = new ArrayList<Customer>();
  44.     private static ArrayList<Customer> completedItems = new ArrayList<Customer>();
  45.     private static ArrayList<Customer> receivedOrder = new ArrayList<Customer>();
  46.  
  47.  
  48.     public void ProgramMenu() {
  49.         System.out.println("Welcome to our Shop");
  50.         System.out.println("1. As Restaurant");
  51.         System.out.println("2. As Customer");
  52.         System.out.println("3. Exit");
  53.     }
  54.  
  55.  
  56.     public void Menu() {
  57.         System.out.println("Please Choose your restaurant at first");
  58.         System.out.println("1. Restaurant No One");
  59.         System.out.println("2. Restaurant No Two");
  60.         System.out.println("3. Restaurant No Three");
  61.     }
  62.  
  63.     public void RestaurantMenu() {
  64.         Menu();
  65.         System.out.println("4. Customer's Selected Items");
  66.         System.out.println("5. Product Collected List by Customer's");
  67.         System.out.println("6. Back");
  68.     }
  69.  
  70.     public void CustomerMenu() {
  71.         Menu();
  72.         System.out.println("4. Cart");
  73.         System.out.println("5. Completed Order List");
  74.         System.out.println("6. Back");
  75.     }
  76.    
  77.  
  78.     public void chooseProduct(ArrayList<Restaurant> Restaurans) {
  79.         System.out.println("Do you want to buy food from here?");
  80.         System.out.println("If 'YES' press 1 or press any key.");
  81.         int choise = scanner.nextInt();
  82.         if(choise == 1) {
  83.             boolean flag = false;
  84.             System.out.println("Please enter the food code");
  85.             String item = scanner.next();
  86.             String code = null, name = null;
  87.             double price = 0.0;
  88.             for(Restaurant restaurant : Restaurans) {
  89.                 if(restaurant.foodCode.equalsIgnoreCase(item)) {
  90.                     code = restaurant.foodCode;
  91.                     name = restaurant.foodName;
  92.                     price = restaurant.price;
  93.                     flag = true;
  94.                 }
  95.             }
  96.             if(!flag) {
  97.                 System.out.println("Invalid Code Number!");
  98.                 System.out.println();
  99.             } else {
  100.                 if(selectedItems.size() == 1) {
  101.                     fullOrder();
  102.                 } else {
  103.                     selectedItems.add(new Customer(code, name, price));
  104.                     System.out.println("Item added to your cart. Please check it!\n");
  105.                 }
  106.             }
  107.         }
  108.     }
  109.  
  110.     private void fullOrder() {
  111.         System.out.println("Please wait for confirming your order first");
  112.         System.out.println("Stay with us");
  113.         System.out.println();
  114.     }
  115.  
  116.  
  117.  
  118.     public void showItems(ArrayList<Restaurant> restaurants) {
  119.         if(restaurants.isEmpty()) {
  120.             System.out.println("There is no item available");
  121.             System.out.println("Please try again letter!\n");
  122.         } else {
  123.             for (Restaurant restaurant : restaurants) {
  124.                 System.out.println("Food Code: " + restaurant.foodCode);
  125.                 System.out.println("Food Name: " + restaurant.foodName);
  126.                 System.out.println("Food Price: " + restaurant.price);
  127.                 System.out.println();
  128.             }
  129.         }
  130.     }
  131.  
  132.  
  133.     public boolean orderList(ArrayList<Customer> customers, boolean isEmpty) {
  134.         if(customers.isEmpty()) {
  135.             System.out.println("Customer hasn't order yet!\n");
  136.             isEmpty = true;
  137.         } else {
  138.             for (Customer customer : customers) {
  139.                 System.out.println("Food Code: " + customer.foodCode);
  140.                 System.out.println("Food Name: " + customer.foodName);
  141.                 System.out.println("Food Price: " + customer.price);
  142.                 System.out.println();
  143.             }
  144.         }
  145.         return isEmpty;
  146.     }
  147.  
  148.  
  149.     public void cart(ArrayList<Customer> customers) {
  150.         if(customers.isEmpty()) {
  151.             System.out.println("There is no item available");
  152.             System.out.println("Please try again letter!\n");
  153.         } else {
  154.             System.out.println("Your Food Item List:");
  155.             double money = 0;
  156.             for (Customer restaurant : customers) {
  157.                 System.out.println("Food Code: " + restaurant.foodCode);
  158.                 System.out.println("Food Name: " + restaurant.foodName);
  159.                 System.out.println("Food Price: " + restaurant.price);
  160.                 System.out.println();
  161.                 money += restaurant.price;
  162.             }
  163.  
  164.             System.out.println("Total: " + money + "\n");
  165.         }
  166.     }
  167.  
  168.  
  169.  
  170.     public void choise(ArrayList<Restaurant> restaurant) {
  171.         System.out.println("Enter food code");
  172.         String code = scanner.next();
  173.         System.out.println("Enter food name");
  174.         String name = scanner.next();
  175.         System.out.println("Enter food price");
  176.         double price = scanner.nextDouble();
  177.         restaurant.add(new Restaurant(code, name, price));
  178.         System.out.println("Food has been added successfully!\n");
  179.     }
  180.  
  181.     public void completeOrder() {
  182.         System.out.println("Do you want to complete a order?");
  183.         System.out.println("If 'YES' press 1, for 'NO' press any key");
  184.         int temp = scanner.nextInt();
  185.         if(temp == 1) {
  186.             System.out.println("Please enter the food code");
  187.             String code = scanner.next();
  188.             Iterator<Customer> itr = selectedItems.iterator();
  189.  
  190.             boolean flag = false;
  191.             while(itr.hasNext()) {
  192.                 Customer cs = itr.next();
  193.                 if(cs.foodCode.equals(code)) {
  194.                     completedItems.add(new Customer(cs.foodCode, cs.foodName, cs.price));
  195.                     itr.remove();
  196.                     flag = true;
  197.                 }
  198.             }
  199.             if(flag) {
  200.                 System.out.println("Update successful!\n");
  201.             } else {
  202.                 System.out.println("Food code doesn't exist\n");
  203.             }
  204.             for(Customer customer: selectedItems) {
  205.                 System.out.println(customer.foodCode + " " + customer.foodName + " " + customer.price);
  206.             }
  207.         }
  208.     }
  209.  
  210.     private void showCompletedOrder() {
  211.         if(completedItems.size() == 0) {
  212.             System.out.println("No item availavle");
  213.             System.out.println();
  214.         } else {
  215.             for(Customer customer : completedItems) {
  216.                 System.out.println("Food Code: " + customer.foodCode);
  217.                 System.out.println("Food Name: " + customer.foodName);
  218.                 System.out.println("Food price: " + customer.price);
  219.                 System.out.println();
  220.             }
  221.  
  222.             System.out.println("Have you received it?");
  223.             System.out.println("If 'YES' press 1 otherwise press any key");
  224.             int choise = scanner.nextInt();
  225.             if(choise == 1) {
  226.                 Iterator<Customer> itr = completedItems.iterator();
  227.                 while(itr.hasNext()) {
  228.                     Customer cc = itr.next();
  229.                     receivedOrder.add(new Customer(cc.foodCode, cc.foodName, cc.price));
  230.                     itr.remove();
  231.                 }
  232.                 System.out.println("Update successfully");
  233.             }
  234.             System.out.println();
  235.         }
  236.     }
  237.  
  238.  
  239.     public void getCollectedItems() {
  240.         if(receivedOrder.size() == 0) {
  241.             System.out.println("No items available\n");
  242.         } else {
  243.             for(Customer customer : receivedOrder) {
  244.                 System.out.println("Food Code: " + customer.foodCode);
  245.                 System.out.println("Food Name: " + customer.foodName);
  246.                 System.out.println("Price: " + customer.price);
  247.                 System.out.println();
  248.             }
  249.             System.out.println();
  250.         }
  251.  
  252.     }
  253.  
  254.  
  255.     public static void main(String[] args) {
  256.         Test test = new Test();
  257.         Scanner scanner = new Scanner(System.in);
  258.         boolean shopOne = false, shopTwo = false, shopThree = false;
  259.  
  260.  
  261.         while(true) {
  262.             test.ProgramMenu();
  263.             int choise = scanner.nextInt();
  264.  
  265.             if(choise == 1) {
  266.                 while(true) {                                                   // Admin part
  267.                     System.out.println("Logged in as Admin");
  268.                     test.RestaurantMenu();
  269.                     int cos = scanner.nextInt();
  270.                     if (cos == 1) {                                             // Restaurant One
  271.                         test.choise(RestaurantOne);
  272.                         shopOne = true;
  273.                     } else if (cos == 2) {                                      // Restaurant Two
  274.                         test.choise(RestaurantTwo);
  275.                         shopTwo = true;
  276.                     } else if (cos == 3) {                                      // Restaurant Three
  277.                         test.choise(RestaurantThree);
  278.                         shopThree = true;
  279.                     } else if(cos == 4) {                                       // Customer's selected Item
  280.                         boolean isEmpty = false;
  281.                         isEmpty = test.orderList(selectedItems, isEmpty);
  282.                         if(!isEmpty)
  283.                             test.completeOrder();
  284.                     } else if(cos == 5) {
  285.                             test.getCollectedItems();
  286.                     } else if(cos == 6) {                                       // Back
  287.                         break;
  288.                     } else {
  289.                         System.out.println("Please choose the correct one!\n");
  290.                     }
  291.                 }
  292.             } else if(choise == 2) {                                           // Customer part
  293.                 while(true) {
  294.                     System.out.println("Logged in as Customer");
  295.                     test.CustomerMenu();
  296.                     int select = scanner.nextInt();
  297.                     if (select == 1) {                                         // Restaurant One
  298.                         test.showItems(RestaurantOne);
  299.                         if (shopOne)
  300.                             test.chooseProduct(RestaurantOne);
  301.                     } else if (select == 2) {                                  // Restaurant Two
  302.                         test.showItems(RestaurantTwo);
  303.                         if (shopTwo)
  304.                             test.chooseProduct(RestaurantTwo);
  305.                     } else if (select == 3) {                                  // Restaurant Three
  306.                         test.showItems(RestaurantThree);
  307.                         if (shopThree)
  308.                             test.chooseProduct(RestaurantThree);
  309.                     } else if(select == 4) {                                  // cart
  310.                         test.cart(selectedItems);
  311.                     } else if(select == 5) {                                  // Completed Order List
  312.                         test.showCompletedOrder();
  313.                     } else if(select == 6) {                                  // Break
  314.                         break;
  315.                     } else {
  316.                         System.out.println("Please enter a valid input!");
  317.                         System.out.println();
  318.                     }
  319.                 }
  320.             } else if(choise == 3) {            // Program Close
  321.                 break;
  322.             } else {
  323.                 System.out.println("Wrong input!! \nPlease choose the correct one!");
  324.                 System.out.println();
  325.             }
  326.         }
  327.     }
  328. }
  329.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement