Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Test;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.Scanner;
- class FoodeliverMenu {
- String foodCode, foodName;
- double price;
- FoodeliverMenu(String foodCode, String foodname, double price) {
- this.foodCode = foodCode;
- this.foodName = foodname;
- this.price = price;
- }
- }
- class Restaurant extends FoodeliverMenu {
- Restaurant(String foodCode, String foodname, double price) {
- super(foodCode, foodname, price);
- }
- }
- class Customer extends FoodeliverMenu {
- boolean isCollected = false;
- void isCollected() {
- isCollected = true;
- }
- public Customer(String foodCode, String foodname, double price) {
- super(foodCode, foodname, price);
- }
- }
- public class Test {
- Scanner scanner = new Scanner(System.in);
- private static ArrayList<Restaurant> RestaurantOne = new ArrayList<Restaurant>();
- private static ArrayList<Restaurant> RestaurantTwo = new ArrayList<Restaurant>();
- private static ArrayList<Restaurant> RestaurantThree = new ArrayList<Restaurant>();
- private static ArrayList<Customer> selectedItems = new ArrayList<Customer>();
- private static ArrayList<Customer> completedItems = new ArrayList<Customer>();
- private static ArrayList<Customer> receivedOrder = new ArrayList<Customer>();
- public void ProgramMenu() {
- System.out.println("Welcome to our Shop");
- System.out.println("1. As Restaurant");
- System.out.println("2. As Customer");
- System.out.println("3. Exit");
- }
- public void Menu() {
- System.out.println("Please Choose your restaurant at first");
- System.out.println("1. Restaurant No One");
- System.out.println("2. Restaurant No Two");
- System.out.println("3. Restaurant No Three");
- }
- public void RestaurantMenu() {
- Menu();
- System.out.println("4. Customer's Selected Items");
- System.out.println("5. Product Collected List by Customer's");
- System.out.println("6. Back");
- }
- public void CustomerMenu() {
- Menu();
- System.out.println("4. Cart");
- System.out.println("5. Completed Order List");
- System.out.println("6. Back");
- }
- public void chooseProduct(ArrayList<Restaurant> Restaurans) {
- System.out.println("Do you want to buy food from here?");
- System.out.println("If 'YES' press 1 or press any key.");
- int choise = scanner.nextInt();
- if(choise == 1) {
- boolean flag = false;
- System.out.println("Please enter the food code");
- String item = scanner.next();
- String code = null, name = null;
- double price = 0.0;
- for(Restaurant restaurant : Restaurans) {
- if(restaurant.foodCode.equalsIgnoreCase(item)) {
- code = restaurant.foodCode;
- name = restaurant.foodName;
- price = restaurant.price;
- flag = true;
- }
- }
- if(!flag) {
- System.out.println("Invalid Code Number!");
- System.out.println();
- } else {
- if(selectedItems.size() == 1) {
- fullOrder();
- } else {
- selectedItems.add(new Customer(code, name, price));
- System.out.println("Item added to your cart. Please check it!\n");
- }
- }
- }
- }
- private void fullOrder() {
- System.out.println("Please wait for confirming your order first");
- System.out.println("Stay with us");
- System.out.println();
- }
- public void showItems(ArrayList<Restaurant> restaurants) {
- if(restaurants.isEmpty()) {
- System.out.println("There is no item available");
- System.out.println("Please try again letter!\n");
- } else {
- for (Restaurant restaurant : restaurants) {
- System.out.println("Food Code: " + restaurant.foodCode);
- System.out.println("Food Name: " + restaurant.foodName);
- System.out.println("Food Price: " + restaurant.price);
- System.out.println();
- }
- }
- }
- public boolean orderList(ArrayList<Customer> customers, boolean isEmpty) {
- if(customers.isEmpty()) {
- System.out.println("Customer hasn't order yet!\n");
- isEmpty = true;
- } else {
- for (Customer customer : customers) {
- System.out.println("Food Code: " + customer.foodCode);
- System.out.println("Food Name: " + customer.foodName);
- System.out.println("Food Price: " + customer.price);
- System.out.println();
- }
- }
- return isEmpty;
- }
- public void cart(ArrayList<Customer> customers) {
- if(customers.isEmpty()) {
- System.out.println("There is no item available");
- System.out.println("Please try again letter!\n");
- } else {
- System.out.println("Your Food Item List:");
- double money = 0;
- for (Customer restaurant : customers) {
- System.out.println("Food Code: " + restaurant.foodCode);
- System.out.println("Food Name: " + restaurant.foodName);
- System.out.println("Food Price: " + restaurant.price);
- System.out.println();
- money += restaurant.price;
- }
- System.out.println("Total: " + money + "\n");
- }
- }
- public void choise(ArrayList<Restaurant> restaurant) {
- System.out.println("Enter food code");
- String code = scanner.next();
- System.out.println("Enter food name");
- String name = scanner.next();
- System.out.println("Enter food price");
- double price = scanner.nextDouble();
- restaurant.add(new Restaurant(code, name, price));
- System.out.println("Food has been added successfully!\n");
- }
- public void completeOrder() {
- System.out.println("Do you want to complete a order?");
- System.out.println("If 'YES' press 1, for 'NO' press any key");
- int temp = scanner.nextInt();
- if(temp == 1) {
- System.out.println("Please enter the food code");
- String code = scanner.next();
- Iterator<Customer> itr = selectedItems.iterator();
- boolean flag = false;
- while(itr.hasNext()) {
- Customer cs = itr.next();
- if(cs.foodCode.equals(code)) {
- completedItems.add(new Customer(cs.foodCode, cs.foodName, cs.price));
- itr.remove();
- flag = true;
- }
- }
- if(flag) {
- System.out.println("Update successful!\n");
- } else {
- System.out.println("Food code doesn't exist\n");
- }
- for(Customer customer: selectedItems) {
- System.out.println(customer.foodCode + " " + customer.foodName + " " + customer.price);
- }
- }
- }
- private void showCompletedOrder() {
- if(completedItems.size() == 0) {
- System.out.println("No item availavle");
- System.out.println();
- } else {
- for(Customer customer : completedItems) {
- System.out.println("Food Code: " + customer.foodCode);
- System.out.println("Food Name: " + customer.foodName);
- System.out.println("Food price: " + customer.price);
- System.out.println();
- }
- System.out.println("Have you received it?");
- System.out.println("If 'YES' press 1 otherwise press any key");
- int choise = scanner.nextInt();
- if(choise == 1) {
- Iterator<Customer> itr = completedItems.iterator();
- while(itr.hasNext()) {
- Customer cc = itr.next();
- receivedOrder.add(new Customer(cc.foodCode, cc.foodName, cc.price));
- itr.remove();
- }
- System.out.println("Update successfully");
- }
- System.out.println();
- }
- }
- public void getCollectedItems() {
- if(receivedOrder.size() == 0) {
- System.out.println("No items available\n");
- } else {
- for(Customer customer : receivedOrder) {
- System.out.println("Food Code: " + customer.foodCode);
- System.out.println("Food Name: " + customer.foodName);
- System.out.println("Price: " + customer.price);
- System.out.println();
- }
- System.out.println();
- }
- }
- public static void main(String[] args) {
- Test test = new Test();
- Scanner scanner = new Scanner(System.in);
- boolean shopOne = false, shopTwo = false, shopThree = false;
- while(true) {
- test.ProgramMenu();
- int choise = scanner.nextInt();
- if(choise == 1) {
- while(true) { // Admin part
- System.out.println("Logged in as Admin");
- test.RestaurantMenu();
- int cos = scanner.nextInt();
- if (cos == 1) { // Restaurant One
- test.choise(RestaurantOne);
- shopOne = true;
- } else if (cos == 2) { // Restaurant Two
- test.choise(RestaurantTwo);
- shopTwo = true;
- } else if (cos == 3) { // Restaurant Three
- test.choise(RestaurantThree);
- shopThree = true;
- } else if(cos == 4) { // Customer's selected Item
- boolean isEmpty = false;
- isEmpty = test.orderList(selectedItems, isEmpty);
- if(!isEmpty)
- test.completeOrder();
- } else if(cos == 5) {
- test.getCollectedItems();
- } else if(cos == 6) { // Back
- break;
- } else {
- System.out.println("Please choose the correct one!\n");
- }
- }
- } else if(choise == 2) { // Customer part
- while(true) {
- System.out.println("Logged in as Customer");
- test.CustomerMenu();
- int select = scanner.nextInt();
- if (select == 1) { // Restaurant One
- test.showItems(RestaurantOne);
- if (shopOne)
- test.chooseProduct(RestaurantOne);
- } else if (select == 2) { // Restaurant Two
- test.showItems(RestaurantTwo);
- if (shopTwo)
- test.chooseProduct(RestaurantTwo);
- } else if (select == 3) { // Restaurant Three
- test.showItems(RestaurantThree);
- if (shopThree)
- test.chooseProduct(RestaurantThree);
- } else if(select == 4) { // cart
- test.cart(selectedItems);
- } else if(select == 5) { // Completed Order List
- test.showCompletedOrder();
- } else if(select == 6) { // Break
- break;
- } else {
- System.out.println("Please enter a valid input!");
- System.out.println();
- }
- }
- } else if(choise == 3) { // Program Close
- break;
- } else {
- System.out.println("Wrong input!! \nPlease choose the correct one!");
- System.out.println();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement