Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace IMJunior
- {
- class Program
- {
- static void Main(string[] args)
- {
- int money = 1000;
- string[] bag = new string[0];
- string[] finalBag = new string[0];
- string[][] arrayOfFinalBags = new string[0][];
- int sum = 0;
- bool exit = true;
- Vegetables[] vegetables = { new Vegetables("Картофель", 30, 20), new Vegetables("Помидоры", 100, 20), new Vegetables("Огурцы", 70, 30)};
- Salesman salesman = new Salesman();
- while (exit)
- {
- MainMenu(ref money);
- Console.Write("Выбрать пункт: ");
- int chose1 = Convert.ToInt32(Console.ReadLine());
- if (chose1 == 1)
- {
- Console.Clear();
- for (int i = 0; i < vegetables.Length; i++)
- {
- vegetables[i].ShowInfo();
- }
- Console.Write("Выберите продукт: ");
- int chose2 = Convert.ToInt32(Console.ReadLine());
- if (chose2 == 1)
- {
- Vegetables(vegetables, ref bag, 0, ref sum);
- }
- else if (chose2 == 2)
- {
- Vegetables(vegetables, ref bag, 1, ref sum);
- }
- else if (chose2 == 3)
- {
- Vegetables(vegetables, ref bag, 2, ref sum);
- }
- else Console.WriteLine("Ошибка ввода!");
- }
- else if (chose1 == 2)
- {
- BagInfo(ref money, ref bag);
- Console.ReadLine();
- Console.Clear();
- }
- else if (chose1 == 3)
- {
- BagInfo(ref money, ref bag);
- Console.SetCursorPosition(70, 0);
- Console.Write("Какой товар убрать: ");
- int chose4 = Convert.ToInt32(Console.ReadLine());
- if (chose4 < 0 || chose4 > bag.Length)
- {
- Console.WriteLine("Неверный ввод!");
- }
- else
- {
- string[] temp = new string[bag.Length - 1];
- string[] temp2 = new string[bag.Length];
- temp2 = bag;
- string tempString = temp2[chose4 - 1];
- temp2[chose4 - 1] = temp2[temp2.Length - 1];
- temp2[temp2.Length - 1] = tempString;
- sum -= Convert.ToInt32(temp2[temp2.Length - 1].Split(' ')[7]);
- for(int i = 0; i < temp.Length; i++)
- {
- if(i < temp2.Length - 1)
- {
- temp[i] = temp2[i];
- }
- }
- bag = temp;
- }
- Console.Clear();
- }
- else if (chose1 == 4)
- {
- BagInfo(ref money, ref bag);
- Console.SetCursorPosition(70, 0);
- Console.WriteLine($"Всего получилось - {sum} рублей");
- Console.SetCursorPosition(70, 1);
- Console.Write("Желаете оплатить? Да/Нет: ");
- string answer = Console.ReadLine().ToLower();
- if (answer == "да")
- {
- if (money >= sum)
- {
- money -= sum;
- sum = 0;
- salesman.BuyProducts(ref finalBag, ref bag, ref arrayOfFinalBags);
- }
- else
- {
- Console.SetCursorPosition(70, 2);
- Console.WriteLine("У вас недостаточно денег!");
- }
- }
- else if (answer == "нет")
- {
- Console.SetCursorPosition(70, 2);
- Console.WriteLine("Хорошо.");
- }
- else
- {
- Console.SetCursorPosition(70, 2);
- Console.WriteLine("Неверный ввод!");
- }
- Console.ReadLine();
- Console.Clear();
- }
- else if (chose1 == 5)
- {
- Console.Clear();
- Console.WriteLine("Купленные продукты: ");
- for (int i = 0; i < arrayOfFinalBags.Length; i++)
- {
- for (int j = 0; j < arrayOfFinalBags[i].Length; j++)
- {
- Console.WriteLine(i + ") " + arrayOfFinalBags[i][j]);
- }
- Console.WriteLine();
- }
- Console.ReadLine();
- Console.Clear();
- }
- else if (chose1 == 6)
- {
- Console.Clear();
- Console.WriteLine("Всего доброго!");
- exit = false;
- }
- else Console.WriteLine("Неверный ввод!");
- }
- }
- static void MainMenu(ref int money)
- {
- Console.WriteLine("1) Овощной отдел");
- Console.WriteLine("2) Корзина");
- Console.WriteLine("3) Убрать из корзины");
- Console.WriteLine("4) Продавец");
- Console.WriteLine("5) Купленные товары");
- Console.WriteLine("6) Уйти из магазина");
- Console.WriteLine($"Ваши деньги: {money} рублей");
- }
- static void Vegetables(Vegetables[] vegetables, ref string[] bag, int j, ref int sum)
- {
- Console.Write("Сколько кг: ");
- int chose3 = Convert.ToInt32(Console.ReadLine());
- if (chose3 < 0 || chose3 > vegetables[j].AmountInKg)
- {
- Console.WriteLine("Ошибка ввода!");
- Console.ReadLine();
- Console.Clear();
- }
- else
- {
- vegetables[j].AmountInKg -= chose3;
- int localPrice = chose3 * vegetables[j].Price;
- string message = $"{vegetables[j].Name} в количестве {chose3} кг, стоимость - {localPrice}";
- string[] tempBag = new string[bag.Length + 1];
- sum += localPrice;
- for (int i = 0; i < bag.Length; i++)
- {
- tempBag[i] = bag[i];
- }
- tempBag[tempBag.Length - 1] = message;
- bag = tempBag;
- }
- Console.Clear();
- }
- static void BagInfo(ref int money, ref string[] bag)
- {
- Console.Clear();
- Console.WriteLine($"У вас денег: {money}. Ваша корзина: ");
- for (int i = 0; i < bag.Length; i++)
- {
- Console.WriteLine(bag[i]);
- }
- }
- }
- class Shop
- {
- private int _price;
- public Shop(int price)
- {
- _price = price;
- }
- }
- class Salesman
- {
- public void BuyProducts(ref string[] finalBag, ref string[] curBag, ref string[][] arrayOfFinalBags)
- {
- string[] newBag = new string[0];
- string[] tempBag = new string[curBag.Length];
- string[][] tempArrayOfFinalBags = new string[arrayOfFinalBags.Length + 1][];
- for (int i = 0; i < curBag.Length; i++)
- {
- tempBag[i] = curBag[i];
- }
- finalBag = tempBag;
- for (int i = 0; i < arrayOfFinalBags.Length; i++)
- {
- tempArrayOfFinalBags[i] = arrayOfFinalBags[i];
- for(int j = 0; j < arrayOfFinalBags[i].Length; j++)
- {
- tempArrayOfFinalBags[i][j] = arrayOfFinalBags[i][j];
- }
- }
- tempArrayOfFinalBags[tempArrayOfFinalBags.Length - 1] = finalBag;
- arrayOfFinalBags = tempArrayOfFinalBags;
- curBag = newBag;
- }
- }
- class Vegetables : Shop
- {
- private int _price;
- public int AmountInKg;
- private string _name;
- public string Name
- {
- get
- {
- return _name;
- }
- set
- {
- _name = value;
- }
- }
- public int Price
- {
- get
- {
- return _price;
- }
- set
- {
- _price = value;
- }
- }
- public Vegetables(string name, int price, int amountInKg) : base(price)
- {
- _name = name;
- _price = price;
- AmountInKg = amountInKg;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"{_name}: всего: {AmountInKg} кг, цена за 1 килограм: {_price}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement