private static void ShowProducts(ref Price[] listShop)
 {
     Console.WriteLine("Введите названия магазина, что бы узнать его товары:");
     try
     {
         string findShopName = Console.ReadLine();
         int ShowException = 0;
         for (int i = 0; i < listShop.Length; i++)
         {
             if (findShopName == listShop[i].ShopName)
             {
                 ShowException++;
                 Console.WriteLine("В данном магазине есть такие товары: {0} - Цена {1}", listShop[i].ProductName, listShop[i].ProductPrice);
             }
         }
         if (ShowException == 0)
         {
             throw new Exception("Данного магазина не существует!");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
 static void Main(string[] args)
 {
     Price[] listShop = new Price[2];
     FillListShop(ref listShop);
     SortABC(ref listShop);
     ShowProducts(ref listShop);
 }
Beispiel #3
0
        public Ball(string description, decimal amount, Currency ccy)
        {
            if (string.IsNullOrWhiteSpace(description)) throw new ArgumentException("Description must not be empty.", nameof(description));
            if (amount < 0) throw new ArgumentException("Price must not be negative.", nameof(amount));

            m_description = description;
            m_price = new Price(amount, ccy);
        }
Beispiel #4
0
        public void SetAttributes(string description, decimal amount, Currency ccy)
        {
            if (string.IsNullOrWhiteSpace(description)) throw new ArgumentException("Description must not be empty.", nameof(description));
            if (amount < 0) throw new ArgumentException("Price must not be negative.", nameof(amount));

            m_description = description;
            m_price = new Price(amount, ccy);
            Console.WriteLine("Attribute überschrieben!");
        }
 public static void FillListShop(ref Price[] listShop)
 {
     try
     {
         for (int i = 0; i < listShop.Length; i++)
         {
             Console.WriteLine("Введите название продукта:");
             listShop[i].ProductName = Console.ReadLine();
             Console.WriteLine("Введите название магазина:");
             listShop[i].ShopName = Console.ReadLine();
             Console.WriteLine("Введите цену:");
             listShop[i].ProductPrice = int.Parse(Console.ReadLine());
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
 public static void SortABC(ref Price[] shops)
 {
     bool flag = true;
     while (flag)
     {
         flag = false;
         for (int i = 0; i < shops.Length - 1; ++i)
             if (shops[i].ShopName.CompareTo(shops[i + 1].ShopName) > 0)
             {
                 string buf = shops[i].ShopName;
                 shops[i].ShopName = shops[i + 1].ShopName;
                 shops[i + 1].ShopName = buf;
                 flag = true;
             }
     }
     Console.WriteLine("Отсортированные магазины:");
     for (int i = 0; i < shops.Length; i++)
     {
         Console.WriteLine(shops[i].ShopName);
     }
 }
Beispiel #7
0
 public Ball(string description)
 {
     m_description = description;
     m_price = new Price(1, Currency.EUR);
 }
Beispiel #8
0
 public Ball()
 {
     m_description = "";
     m_price = new Price(1, Currency.EUR);
 }
Beispiel #9
0
        static void Main(string[] args)
        {
            Price[] prices = new Price[2];
            string enteredProdName;
            string enteredShopName;
            decimal enteredPrice;

            int count = 0;
            while (count < 2)
            {
                Console.WriteLine("-------------------------");
                Console.WriteLine("Enter the product name ->");
                enteredProdName = Console.ReadLine();

                Console.WriteLine("Enter the shop name ->");
                enteredShopName = Console.ReadLine();

                Console.WriteLine("Enter the price ->");
                if(!Decimal.TryParse(Console.ReadLine(),out enteredPrice))
                {
                    Console.WriteLine("Price must be a number");
                    continue;
                }

                Price price;
                try
                {
                    price = new Price(enteredProdName, enteredShopName, enteredPrice);
                }
                catch(ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }

                prices[count] = price;
                count++;
                Console.WriteLine("Price was added");
            }

            Array.Sort(prices, (x,y) => String.Compare(x.ShopName, y.ShopName, true));
            Console.WriteLine("\nALL PRODUCTS");
            foreach (var item in prices)
            {
                Console.WriteLine(item.ToString());
            }

            Console.WriteLine("\nEnter the shop name->");
            enteredShopName = Console.ReadLine();

            Price[] prisesInShop = Array.FindAll(prices, x => String.Compare(x.ShopName, enteredShopName, true) == 0);

            if (prisesInShop.Length == 0)
            {
                throw new ShopNotFoundException("Shop not found");
            }
            else
            {
                Console.WriteLine("\nPRODUCTS IN SHOP {0}", enteredShopName);
                foreach (var item in prisesInShop)
                {
                    Console.WriteLine(item.ToString());
                }
            }
            Console.ReadKey();
        }
Beispiel #10
0
 private static bool BinaryOp(Price x, Price y, Func<decimal, decimal, bool> op)
 {
     if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null)) throw new ArgumentNullException();
     if (x.Unit == y.Unit) return op(x.Amount, y.Amount);
     return op(x.Amount, y.ConvertTo(x.Unit).Amount);
 }
Beispiel #11
0
 public Fussball()
 {
     m_description = "Dummy Ball";
     m_price = new Price(0, Currency.EUR);
     m_Size = 4;
 }