static void Main() { Employee[] emp = new Employee[10]; Random r = new Random(); int inds = 0, indp = 0; for (int i = 0; i < emp.Length; i++) { if (r.Next(0, 2) == 0) { inds++; emp[i] = new SalesEmployee("saler " + inds, r.Next(20, 101), r.Next(0, 20)); } else { indp++; emp[i] = new PartTimeEmployee("part time worker " + indp, r.Next(20, 101), r.Next(1, 60)); } Console.WriteLine(emp[i]); } Console.WriteLine(); Array.Sort(emp); foreach (Employee e in emp) { Console.WriteLine(e); } }
static void Main(string[] args) { Random rnd = new Random(); Employee[] arr = new Employee[rnd.Next(1, 101)]; for (int i = 0; i < arr.Length; i++) { if (rnd.Next(0, 3) % 2 == 0) { arr[i] = new SalesEmployee(RandString(), rnd.Next(0, 201), rnd.Next(0, 10)); } else { arr[i] = new PartTimeEmployee(RandString(), rnd.Next(0, 201), rnd.Next(0, 26)); } } Array.Sort(arr, (x, y) => { if (x.CalculatePay() < y.CalculatePay()) { return(1); } else if (x.CalculatePay() > y.CalculatePay()) { return(-1); } else { return(0); } }); Console.WriteLine("С доп бонусом работник"); Array.ForEach(Array.FindAll(arr, x => x is SalesEmployee), x => Console.WriteLine(x.CalculatePay())); Console.WriteLine("\nВнештатный работник"); Array.ForEach(Array.FindAll(arr, x => x is PartTimeEmployee), x => Console.WriteLine(x.CalculatePay())); }
static Employee[] EmpArray() { int countSales = rnd.Next(0, 11); int countPartTime = rnd.Next(0, 11); Employee[] p = new Employee[countSales + countPartTime]; for (int i = 0; i < countSales; ++i) { string name = GenerateName(); p[i] = new SalesEmployee(name, rnd.Next(0, 1000), rnd.Next(0, 100)); } for (int i = countSales; i < p.Length; ++i) { string name = GenerateName(); p[i] = new PartTimeEmployee(name, rnd.Next(0, 1000), rnd.Next(0, 100)); } return(p); }