コード例 #1
0
        /// <summary>
        /// Execute method for average price type command.
        /// </summary>
        public void Execute()
        {
            Console.WriteLine("Enter the type.");
            string type = Console.ReadLine();

            Console.WriteLine($"{RepositoryOfItems.GetListOfItems().GetAveragePriceType(type)}");
        }
コード例 #2
0
 /// <summary>
 /// Checks if repository has been created yet.
 /// </summary>
 /// <returns>New repository if it hasn't been created yet; already existing repository if it has been created.</returns>
 public static RepositoryOfItems GetListOfItems()
 {
     if (listOfItems == null)
     {
         listOfItems = new RepositoryOfItems();
     }
     return(listOfItems);
 }
コード例 #3
0
        /// <summary>
        /// Calculates amount of items.
        /// </summary>
        /// <returns>Amount of items.</returns>
        public int GetNumberOfAllItems()
        {
            int counter          = 0;
            int numberOfAllItems = 0;

            foreach (Item newitem in RepositoryOfItems.GetListOfItems().items)
            {
                int number = newitem.Amount;
                counter++;
                numberOfAllItems += number;
            }
            return(numberOfAllItems);
        }
コード例 #4
0
        /// <summary>
        /// Calculates average price.
        /// </summary>
        /// <returns>Average price.</returns>
        public float GetAveragePrice()
        {
            float averagePrice = 0;
            int   counter      = 0;

            foreach (Item newitem in RepositoryOfItems.GetListOfItems().items)
            {
                float cost = newitem.Cost;
                averagePrice += cost;
                counter++;
            }
            averagePrice /= counter;
            return(averagePrice);
        }
コード例 #5
0
        /// <summary>
        /// Calculates number of types.
        /// </summary>
        /// <returns>Number of types</returns>
        public int GetNumberOfTypes()
        {
            int           counter = 0;
            List <string> types   = new List <string>();

            foreach (Item newitem in RepositoryOfItems.GetListOfItems().items)
            {
                string type = newitem.Type;
                if (!types.Contains(type))
                {
                    counter++;
                }
            }
            return(counter);
        }
コード例 #6
0
        /// <summary>
        /// Calculates average price of items with one type.
        /// </summary>
        /// <param name="neededType"></param>
        /// <returns>Average price of items with one type.</returns>
        public float GetAveragePriceType(string neededType)
        {
            float averagePrice = 0;
            int   counter      = 0;

            foreach (Item newitem in RepositoryOfItems.GetListOfItems().items)
            {
                float  cost = newitem.Cost;
                string type = newitem.Type;
                if (neededType == type)
                {
                    averagePrice += cost;
                    counter++;
                }
            }
            averagePrice /= counter;
            return(averagePrice);
        }
コード例 #7
0
ファイル: RepositoryAddItem.cs プロジェクト: NikaMakovik/TAT
        /// <summary>
        /// Execute method for add item command.
        /// </summary>
        public void Execute()
        {
            Console.WriteLine("Enter the type of an item.");
            string type = Console.ReadLine();

            Console.WriteLine("Enter the name of an item.");
            string name = Console.ReadLine();

            Console.WriteLine("Enter the amount of an item.");
            int amount = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter the cost of an item.");
            float cost = float.Parse(Console.ReadLine());
            Item  item = new Item(type, name, amount, cost);

            RepositoryOfItems.GetListOfItems().AddItem(item);
            Console.WriteLine("Item added.");
        }
コード例 #8
0
 /// <summary>
 /// Execute method for count types command.
 /// </summary>
 public void Execute()
 {
     Console.WriteLine($"Number of types: {RepositoryOfItems.GetListOfItems().GetNumberOfTypes()}");
 }
コード例 #9
0
 /// <summary>
 /// Execute method for average price command.
 /// </summary>
 public void Execute()
 {
     Console.WriteLine($"Average price of all items: {RepositoryOfItems.GetListOfItems().GetAveragePrice()}");
 }