Example #1
0
        public void run()
        {
            string[] createPlazaimplMenu = { "1) to create a new plaza.",
                                             "2) to exit." };

            string[] plazaImplMenu = { "1) to list all shops.",
                                       "2) to add a new shop.",
                                       "3) to remove an existing shop.",
                                       "4) enter a shop by name.",
                                       "5) to open the plaza.",
                                       "6) to close the plaza.",
                                       "7) to check if the plaza is open or not.",
                                       "8) leave the plaza" };

            string[] shopMenu = { "1) to list available products.",
                                  "2) to find products by name.",
                                  "3) to display the shop's owner.",
                                  "4) to open the shop.",
                                  "5) to close the shop.",
                                  "6) to add new product to the shop.",
                                  "7) to add existing products to the shop.",
                                  "8) to buy a product by barcode.",
                                  "9) check price by barcode.",
                                  "10) go back to plaza." };

            while (true)
            {
                try
                {
                    Console.WriteLine("There are no plaza created yet! Press");
                    ListingMenuPoints(createPlazaimplMenu);
                    string answ = Console.ReadLine();

                    if (answ == "1")
                    {
                        Console.Write("Give me the plaza name: ");
                        PlazaImpl plaza = new PlazaImpl(Console.ReadLine());
                        while (true)
                        {
                            try
                            {
                                Console.WriteLine($"Welcome to the {plaza.Name}! Press ");
                                ListingMenuPoints(plazaImplMenu);
                                string plazansw = Console.ReadLine();

                                if (plazansw == "1")
                                {
                                    foreach (IShop element in plaza.GetShops())
                                    {
                                        Console.WriteLine(element.ToString());
                                    }
                                }
                                else if (plazansw == "2")
                                {
                                    string[]      shopquestions = { "Give me the shop Name: ",
                                                                    "Give me the shop Owner: " };
                                    List <string> shopanswer = new List <string>();
                                    foreach (string element in shopquestions)
                                    {
                                        Console.Write(element);
                                        shopanswer.Add(Console.ReadLine());
                                    }
                                    plaza.AddShop(new ShopImpl(shopanswer[0], shopanswer[1]));
                                }
                                else if (plazansw == "3")
                                {
                                    Console.Write("Give me the shop Name what you want to remove: ");
                                    string removingPlaza = Console.ReadLine();
                                    if (plaza.GetShops().Count == 0)
                                    {
                                        Console.WriteLine("Create a shop first please");
                                    }
                                    foreach (IShop element in plaza.GetShops())
                                    {
                                        if (element.Name == removingPlaza)
                                        {
                                            plaza.RemoveShop(element);
                                            break;
                                        }
                                    }
                                }
                                else if (plazansw == "4")
                                {
                                    Console.Write("Give me the soph you want to enter! : ");
                                    string entryshop = Console.ReadLine();
                                    if (plaza.GetShops().Count == 0)
                                    {
                                        Console.WriteLine("Create a shop first please");
                                        return;
                                    }
                                    foreach (IShop element in plaza.GetShops())
                                    {
                                        if (element.Name == entryshop)
                                        {
                                            while (true)
                                            {
                                                try
                                                {
                                                    Console.WriteLine($"Welcome to the {element.Name} Shop!Press: ");
                                                    ListingMenuPoints(shopMenu);
                                                    string shopansw = Console.ReadLine();
                                                    if (shopansw == "1")
                                                    {
                                                        if (element.GetProducts().Count == 0)
                                                        {
                                                            Console.WriteLine("Create a product first please");
                                                        }
                                                        else
                                                        {
                                                            foreach (Product product in element.GetProducts())
                                                            {
                                                                Console.WriteLine(product.ToString());
                                                            }
                                                        }
                                                    }
                                                    else if (shopansw == "2")
                                                    {
                                                        Console.Write("Give me the product name what you: ");
                                                        Console.WriteLine(element.FindByName(Console.ReadLine()).ToString());
                                                    }
                                                    else if (shopansw == "3")
                                                    {
                                                        Console.WriteLine($"The shop's owner is {element.Owner}");
                                                    }
                                                    else if (shopansw == "4")
                                                    {
                                                        element.Open();
                                                        Console.WriteLine("The shop has been opened");
                                                    }
                                                    else if (shopansw == "5")
                                                    {
                                                        element.Close();
                                                        Console.WriteLine("The shop has been closed");
                                                    }
                                                    else if (shopansw == "6")
                                                    {
                                                        Console.Write("What kind of product you want to create: ");
                                                        string productType = Console.ReadLine().ToLower();
                                                        if (productType == "foodproduct" || productType == "food product")
                                                        {
                                                            string[] foodData = { "Give me the barcode : ",
                                                                                  "Give me the food name: ",
                                                                                  "Give me the manufacturer: ",
                                                                                  "Give me the food's calories: " };

                                                            string[]      Datetime = { "Give me the warranty year: ",
                                                                                       "Give me the warranty month: ",
                                                                                       "Give me the warranty day: " };
                                                            List <string> DatetimeAnsw = new List <string>();
                                                            List <string> foodDataAnsw = new List <string>();
                                                            foreach (string data in foodData)
                                                            {
                                                                Console.Write(data);
                                                                foodDataAnsw.Add(Console.ReadLine());
                                                            }
                                                            foreach (string datatime in Datetime)
                                                            {
                                                                Console.Write(datatime);
                                                                DatetimeAnsw.Add(Console.ReadLine());
                                                            }
                                                            FoodProduct foodProduct = new FoodProduct(Convert.ToInt64(foodDataAnsw[0]),
                                                                                                      foodDataAnsw[1],
                                                                                                      foodDataAnsw[2],
                                                                                                      Convert.ToInt32(foodDataAnsw[3]),
                                                                                                      new DateTime(Convert.ToInt32(DatetimeAnsw[0]),
                                                                                                                   Convert.ToInt32(DatetimeAnsw[1]),
                                                                                                                   Convert.ToInt32(DatetimeAnsw[2])));
                                                            string[]      quantityPrice = { "Give me the quantity: ",
                                                                                            "Give me the Price: " };
                                                            List <string> quantityPriceansw = new List <string>();
                                                            foreach (string data in quantityPrice)
                                                            {
                                                                Console.Write(data);
                                                                quantityPriceansw.Add(Console.ReadLine());
                                                            }
                                                            element.AddNewProduct(foodProduct, Convert.ToInt32(quantityPriceansw[0]), float.Parse(quantityPriceansw[1]));
                                                        }
                                                        else if (productType == "clothingproduct" || productType == "clothing product")
                                                        {
                                                            string[]      clothdata = { "Give me the barcode : ",
                                                                                        "Give me the cloth name: ",
                                                                                        "Give me the manufacturer: ",
                                                                                        "Give me the material: ",
                                                                                        "Give me the type: " };
                                                            List <string> clothDataAnsw = new List <string>();
                                                            foreach (string data in clothdata)
                                                            {
                                                                Console.Write(data);
                                                                clothDataAnsw.Add(Console.ReadLine());
                                                            }
                                                            ClothingProduct clothing = new ClothingProduct(Convert.ToInt64(clothDataAnsw[0]),
                                                                                                           clothDataAnsw[1],
                                                                                                           clothDataAnsw[2],
                                                                                                           clothDataAnsw[3],
                                                                                                           clothDataAnsw[4]);
                                                            string[]      quantityPrice = { "Give me the quantity: ",
                                                                                            "Give me the Price: " };
                                                            List <string> quantityPriceansw = new List <string>();
                                                            foreach (string data in quantityPrice)
                                                            {
                                                                Console.Write(data);
                                                                quantityPriceansw.Add(Console.ReadLine());
                                                            }
                                                            element.AddNewProduct(clothing, Convert.ToInt32(quantityPriceansw[0]), float.Parse(quantityPriceansw[1]));
                                                        }
                                                    }
                                                    else if (shopansw == "7")
                                                    {
                                                        Console.WriteLine("Product barcode and name: ");
                                                        foreach (Product product in element.GetProducts())
                                                        {
                                                            Console.WriteLine(product.Barcode + " " + product.Name);
                                                        }
                                                        Console.Write("Give me the barcode: ");
                                                        long barcodeansw = Convert.ToInt64(Console.ReadLine());
                                                        Console.Write("Give me the quantity: ");
                                                        int quantityansw = Convert.ToInt32(Console.ReadLine());
                                                        element.AddProduct(barcodeansw, quantityansw);
                                                    }
                                                    else if (shopansw == "8")
                                                    {
                                                        Console.WriteLine("Product barcode and name: ");
                                                        foreach (Product product in element.GetProducts())
                                                        {
                                                            Console.WriteLine(product.Barcode + " " + product.Name);
                                                        }
                                                        Console.Write("Give me the product's barcode which you want to buy: ");
                                                        long barcodeansw = Convert.ToInt64(Console.ReadLine());
                                                        Console.Write($"How many product you want to buy? : ");
                                                        int quantityansw = Convert.ToInt32(Console.ReadLine());
                                                        if (quantityansw == 1)
                                                        {
                                                            cart.Add(element.BuyProduct(barcodeansw));
                                                            prices.Add(element.GetPrice(barcodeansw));
                                                        }
                                                        else if (quantityansw > 1)
                                                        {
                                                            List <Product> buyedProduct = element.BuyProducts(barcodeansw, quantityansw);
                                                            foreach (Product product in buyedProduct)
                                                            {
                                                                cart.Add(product);
                                                                prices.Add(element.GetPrice(barcodeansw));
                                                            }
                                                        }
                                                    }
                                                    else if (shopansw == "9")
                                                    {
                                                        Console.Write("Product barcode and name: ");
                                                        foreach (Product product in element.GetProducts())
                                                        {
                                                            Console.WriteLine(product.Barcode + " " + product.Name);
                                                        }
                                                        Console.Write("Give me the barcode: ");
                                                        long barcodeansw = Convert.ToInt64(Console.ReadLine());
                                                        Console.WriteLine($"The product's price is {element.GetPrice(barcodeansw)}");
                                                    }
                                                    else if (shopansw == "10")
                                                    {
                                                        float finalPrice = 0;
                                                        foreach (float price in prices)
                                                        {
                                                            finalPrice += price;
                                                        }
                                                        Console.WriteLine("The product(s) you want to buy: ");
                                                        foreach (Product product in cart)
                                                        {
                                                            Console.WriteLine(product.ToString());
                                                        }
                                                        Console.WriteLine($"It will be {finalPrice}FT altogether");
                                                        Console.Write("You want to buy this product(s)? : ");

                                                        string buyansw = Console.ReadLine().ToLower();
                                                        if (buyansw == "yes" || buyansw == "y")
                                                        {
                                                            Console.WriteLine("Thank you for your visit");
                                                            cart.Clear();
                                                            prices.Clear();
                                                            break;
                                                        }
                                                        if (buyansw == "no" || buyansw == "n")
                                                        {
                                                            Console.WriteLine("Then please continue the purchase");
                                                        }
                                                    }
                                                }
                                                catch (Exception ex)
                                                { Console.WriteLine(ex.Message); }
                                            }
                                        }
                                    }
                                }
                                else if (plazansw == "5")
                                {
                                    plaza.Open();
                                    Console.WriteLine("The plaza has been opened");
                                }
                                else if (plazansw == "6")
                                {
                                    plaza.Close();
                                    Console.WriteLine("The plaza has been closed");
                                }
                                else if (plazansw == "7")
                                {
                                    if (plaza.IsOpen())
                                    {
                                        Console.WriteLine("The plaza is open");
                                    }
                                    else
                                    {
                                        Console.WriteLine("The plaza is closed");
                                    }
                                }
                                else if (plazansw == "8")
                                {
                                    Console.WriteLine("you are leaving the plaza");
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                    else if (answ == "2")
                    {
                        Console.WriteLine("Thank you for your visit,bye");
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Example #2
0
        public void Run()
        {
            PlazaImpl plaza = null;

            string firstMenu = "There are no plaza created yet! Press\n" +
                               "1) to create a new plaza.\n" +
                               "2) to exit.\n";

            Console.Write(firstMenu);
            var inputFirstMenu = Console.ReadKey(true);

            switch (inputFirstMenu.Key)
            {
            case ConsoleKey.D1:
                Console.Write("Enter the name of the Plaza here: ");
                string plazaName = Console.ReadLine();
                plaza = new PlazaImpl(plazaName);
                Console.Clear();
                string secondMenu =
                    $"Welcome to the {plaza.ToString()}! Press\n" +
                    "1) to list all shops.\n" +
                    "2) to add a new shop.\n" +
                    "3) to remove an existing shop.\n" +
                    "4) find a shop by name.\n" +
                    "5) to check if the plaza is open or not.\n" +
                    "6) to open the plaza.\n" +
                    "7) to close the plaza.\n" +
                    "...\n" +
                    "N) leave plaza.\n";
                while (true)
                {
                    Console.Clear();
                    Console.Write(secondMenu);
                    var inputSecondMenu = Console.ReadKey(true);
                    switch (inputSecondMenu.Key)
                    {
                    case ConsoleKey.D1:
                        foreach (Shop shop in plaza.GetShops())
                        {
                            Console.WriteLine(shop.ToString());
                        }
                        Console.ReadLine();
                        break;

                    case ConsoleKey.D2:
                        Console.Write("Enter the name of the store here: ");
                        string storeName = Console.ReadLine();
                        Console.Write("Enter the name of the owner of the store here: ");
                        string   storeOwner = Console.ReadLine();
                        ShopImpl shopImpl   = new ShopImpl(storeName, storeOwner);
                        plaza.AddShop(shopImpl);
                        break;

                    case ConsoleKey.D3:
                        Console.Write("Enter the name of the store you want to remove here: ");
                        string storeToBeRemoved = Console.ReadLine();
                        plaza.RemoveShop(plaza.FindShopByName(storeToBeRemoved));
                        break;

                    case ConsoleKey.D4:
                        Console.Write("Enter the name of the store you want to go into: ");
                        string   storeToBeUsed = Console.ReadLine();
                        ShopImpl currentShop   = (ShopImpl)plaza.FindShopByName(storeToBeUsed);
                        string   thirdMenu     =
                            "Hi! This is the {currentShop.ToString()} , welcome! Press\n" +
                            "1) to list available products.\n" +
                            "2) to find products by name.\n" +
                            "3) to display the shop's owner.\n" +
                            "4) to open the shop.\n" +
                            "5) to close the shop.\n" +
                            "6) to add new product to the shop.\n" +
                            "7) to add existing products to the shop.\n" +
                            "8) to buy a product by barcode.\n" +
                            "9) check price by barcode.\n" +
                            "...\n" +
                            "N) go back to plaza.\n";
                        while (true)
                        {
                            Console.Clear();
                            Console.Write(thirdMenu);
                            var inputThirdMenu = Console.ReadKey(true);
                            switch (inputThirdMenu.Key)
                            {
                            case ConsoleKey.D1:
                                foreach (Product product in currentShop.GetProducts())
                                {
                                    Console.WriteLine(product.ToString());
                                }
                                Console.ReadLine();
                                break;

                            case ConsoleKey.D2:
                                Console.Write("Enter the name of the product you want to find");
                                string productToBeFound = Console.ReadLine();
                                currentShop.FindByName(productToBeFound);
                                break;

                            case ConsoleKey.D3:
                                Console.WriteLine(currentShop.GetOwner());
                                Console.ReadLine();
                                break;

                            case ConsoleKey.D4:
                                currentShop.Open();
                                break;

                            case ConsoleKey.D5:
                                currentShop.Close();
                                break;

                            case ConsoleKey.D6:
                                Console.Write("What kind of product would you like to add? (clothing/food)");
                                string whatProductToAdd = Console.ReadLine();
                                if (whatProductToAdd == "clothing")
                                {
                                    Console.Write("Enter barcode here:");
                                    long barcodeToAddClothing = long.Parse(Console.ReadLine());
                                    Console.Write("Enter name here:");
                                    string nameToAddClothing = Console.ReadLine();
                                    Console.Write("Enter manufacturer here:");
                                    string manufacturerToAddClothing = Console.ReadLine();
                                    Console.Write("Enter material here:");
                                    string materialToAddClothing = Console.ReadLine();
                                    Console.Write("Enter type here:");
                                    string  typeToAddClothing    = Console.ReadLine();
                                    Product clothingProductToAdd = new ClothingProduct(barcodeToAddClothing, nameToAddClothing, manufacturerToAddClothing, materialToAddClothing, typeToAddClothing);
                                    currentShop.AddNewProduct(clothingProductToAdd, 10, 230);
                                    break;
                                }
                                else if (whatProductToAdd == "food")
                                {
                                    Console.Write("Enter barcode here:");
                                    long barcodeToAddFood = long.Parse(Console.ReadLine());
                                    Console.Write("Enter name here:");
                                    string nameToAddFood = Console.ReadLine();
                                    Console.Write("Enter manufacturer here:");
                                    string manufacturerToAddFood = Console.ReadLine();
                                    Console.Write("Enter calories here:");
                                    int      caloriesToAddFood = int.Parse(Console.ReadLine());
                                    DateTime date             = new DateTime(2020, 1, 1);
                                    Product  foodProductToAdd = new FoodProduct(barcodeToAddFood, nameToAddFood, manufacturerToAddFood, caloriesToAddFood, date);
                                    currentShop.AddNewProduct(foodProductToAdd, 110, 2300);
                                    break;
                                }

                                break;

                            case ConsoleKey.D7:
                                Console.Write("Enter barcode here:");
                                int barcodeToAdd = int.Parse(Console.ReadLine());
                                Console.Write("Enter amount here:");
                                int amountToAdd = int.Parse(Console.ReadLine());
                                currentShop.AddProduct(barcodeToAdd, amountToAdd);
                                break;

                            case ConsoleKey.D8:
                                Console.Write("Enter barcode here:");
                                int     barcodeToBuy  = int.Parse(Console.ReadLine());
                                Product boughtProduct = currentShop.BuyProduct(barcodeToBuy);
                                cart.Add(boughtProduct);
                                prices.Add(currentShop.GetPrice(barcodeToBuy));
                                break;

                            case ConsoleKey.D9:
                                Console.Write("Enter barcode here:");
                                int barcodeToGetThePriceOf = int.Parse(Console.ReadLine());
                                currentShop.GetPrice(barcodeToGetThePriceOf);
                                break;

                            case ConsoleKey.N:
                                break;
                            }
                        }

                    case ConsoleKey.D5:
                        Console.WriteLine(plaza.IsOpen());
                        Console.ReadLine();
                        break;

                    case ConsoleKey.D6:
                        plaza.Open();
                        break;

                    case ConsoleKey.D7:
                        plaza.Close();
                        break;

                    case ConsoleKey.N:
                        Environment.Exit(0);
                        break;

                    default:
                        throw new ArgumentException("Invalid input");
                    }
                }

            case ConsoleKey.D2:
                Environment.Exit(0);
                break;

            default:
                throw new ArgumentException("Invalid input");
            }
        }
Example #3
0
        public void Run()
        {
            Console.WriteLine("There are no plaza created yet! Press\n" +
                              "1) to create a new plaza.\n" +
                              "2) to exit.");

            string userInput = Console.ReadLine();

            if (userInput.Equals("1"))
            {
                PlazaImpl plaza = new PlazaImpl();

                while (true)
                {
                    Console.WriteLine("Welcome to the Programming PLAZA! Press\n\t" +
                                      "1) to list all shops.\n\t" +
                                      "2) to add a new shop.\n\t" +
                                      "3) to remove an existing shop.\n\t" +
                                      "4) enter a shop by name.\n\t" +
                                      "5) to open the plaza.\n\t" +
                                      "6) to close the plaza.\n\t" +
                                      "7) to check if the plaza is open or not.\n\t" +
                                      "8) leave plaza.");

                    userInput = Console.ReadLine();
                    if (userInput.Equals("1"))
                    {
                        ListAllShops(plaza);
                    }

                    else if (userInput.Equals("2"))
                    {
                        AddNewShop(plaza);
                    }

                    else if (userInput.Equals("3"))
                    {
                        ToRemoveShop(plaza);
                    }

                    else if (userInput.Equals("4"))
                    {
                        FindShopByName(plaza);
                    }

                    else if (userInput.Equals("5"))
                    {
                        if (plaza.IsOpen())
                        {
                            Console.WriteLine("Plaza already OPEN.");
                        }
                        else
                        {
                            plaza.Open();
                        }
                    }

                    else if (userInput.Equals("6"))
                    {
                        if (!plaza.IsOpen())
                        {
                            Console.WriteLine("Plaza already CLOSED.");
                        }
                        else
                        {
                            plaza.Close();
                        }
                    }

                    else if (userInput.Equals("7"))
                    {
                        if (plaza.IsOpen())
                        {
                            Console.WriteLine("Plaza is OPEN");
                        }
                        else
                        {
                            Console.WriteLine("Plaza is CLOSED");
                        }
                    }
                    else if (userInput.Equals("8"))
                    {
                        Console.WriteLine("\nIn your cart:");
                        float needToPay = 0;
                        if (this.cart.Count > 0)
                        {
                            foreach (var item in this.cart)
                            {
                                Console.WriteLine("\t-" + item.GetName());
                            }

                            foreach (var item in this.prices)
                            {
                                needToPay += item;
                            }
                        }
                        Console.WriteLine("You need to pay: " + needToPay + "\n");
                        break;
                    }

                    else
                    {
                        throw new Exception("There was no option like that!");
                    }
                    Console.WriteLine("\n");
                }
            }
            else if (userInput.Equals("2"))
            {
                System.Environment.Exit(1);
            }
            else
            {
                throw new Exception("No choice like that!");
            }
        }