Exemple #1
0
        static void Main(string[] args)
        {
            Worker[] workers = new Worker[10];
            Random   random  = new Random();

            for (int i = 0; i < workers.Length; i++)
            {
                if (i % 2 == 0)
                {
                    workers[i] = new FixedPayWorker($"Тес{i}ов{random.Next(i, i * i)}", $"Мих{random.Next(i, i * i)}ил{i}", (random.NextDouble() * 75000) + 15000);
                }
                else
                {
                    workers[i] = new HourlyWorker($"Сми{i}ов{random.Next(i, i * i)}", $"Ви{random.Next(i, i * i)}тор{i}", (random.NextDouble() * 350) + 200);
                }
            }
            Array.Sort(workers);
            ArrayWorkers arrayWorkers = new ArrayWorkers(workers);

            foreach (var worker in arrayWorkers)
            {
                Console.WriteLine($"Сотрудник: {worker.LastName} {worker.FirstName}. Среднемесячная заработная плата: {worker.WagesPerMonth}");
            }
            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Workers.ArrayWorkers = new BaseWorker[30];
            for (var i = 0; i < Workers.ArrayWorkers.Length; i++)
            {
                var        rnd = new Random();
                BaseWorker worker;
                Thread.Sleep(30);
                var rndResult = rnd.Next(0, 2);
                switch (rndResult)
                {
                case 0:
                    worker = new FixedPayWorker($"Работник {i}", 20000);
                    break;

                case 1:
                    worker = new HourlyPayWorker($"Работник {i}", 150 + rnd.Next(1, 5));
                    break;

                default:
                    worker = new FixedPayWorker($"Работник {i}", 20000);
                    break;
                }
                Workers.ArrayWorkers[i] = worker;
            }

            //использовал интерфейс Icomparer, так как не удалось в сортировке использовать метод WhatSalary
            Array.Sort(Workers.ArrayWorkers, new WorkerComparer());

            Console.WriteLine(Workers.ToString());
            Console.ReadLine();
        }
Exemple #3
0
        public ArrayWorkers(Worker[] sourceArray)
        {
            Lenght  = sourceArray.Length;
            workers = new Worker[Lenght];

            for (int i = 0; i < sourceArray.Length; i++)
            {
                if (sourceArray[i] is FixedPayWorker)
                {
                    this[i] = new FixedPayWorker(sourceArray[i].LastName, sourceArray[i].FirstName, sourceArray[i].Salary);
                }
                else if (sourceArray[i] is HourlyWorker)
                {
                    this[i] = new HourlyWorker(sourceArray[i].LastName, sourceArray[i].FirstName, sourceArray[i].Salary);
                }
            }
        }
Exemple #4
0
        public ArrayWorkers(int lenght)
        {
            Lenght  = lenght;
            workers = new Worker[Lenght];

            for (int i = 0; i < workers.Length; i++)
            {
                if (i % 2 == 0)
                {
                    workers[i] = new FixedPayWorker($"Тес{i}ов{random.Next(i, i * i)}", $"Мих{random.Next(i, i * i)}ил{i}", (random.NextDouble() * 75000) + 15000);
                }
                else
                {
                    workers[i] = new HourlyWorker($"Сми{i}ов{random.Next(i, i * i)}", $"Ви{random.Next(i, i * i)}тор{i}", (random.NextDouble() * 350) + 200);
                }
            }
        }