static void Main(string[] args) { Random rng = new Random(); Employee[] arr = new Employee[rng.Next(0, 11)]; for (int i = 0; i < arr.Length; i++) { string name = ""; name += (char)rng.Next('A', 'Z'); for (int j = 0; j < 5; j++) { name += (char)rng.Next('a', 'z'); } if (rng.Next(0, 2) == 0) { arr[i] = new PartTimeEmployee(name, (decimal)rng.NextDouble() * 5000 + 220, rng.Next(5, 25)); } else { arr[i] = new SalesEmployee(name, (decimal)rng.NextDouble() * 5000 + 220, (decimal)rng.NextDouble() * 500); } } Array.Sort(arr, new EmployeeComparer()); foreach (Employee x in arr) { x.ViewInfo(); Console.WriteLine(); } }
static void Main() { Random rnd = new Random(); Employee[] array = new Employee[6]; array[0] = new PartTimeEmployee("Гена", rnd.Next(200000, 400000), 10); array[1] = new SalesEmployee("Виктор", rnd.Next(90000, 200000), rnd.Next(30000, 80000)); array[2] = new SalesEmployee("Ирина", rnd.Next(90000, 200000), rnd.Next(30000, 80000)); array[3] = new SalesEmployee("Николай", rnd.Next(90000, 200000), rnd.Next(30000, 80000)); array[4] = new PartTimeEmployee("Нюхач", rnd.Next(400000, 600000), 10); array[5] = new SalesEmployee("Максим", rnd.Next(90000, 200000), rnd.Next(30000, 80000)); Array.Sort(array, (x, y) => - x.CalculatePay().CompareTo(y.CalculatePay())); Array.ForEach(array, x => { if (x is SalesEmployee) { Console.WriteLine($"{x.name}: {x.CalculatePay()}"); } }); Array.ForEach(array, x => { if (x is PartTimeEmployee) { Console.WriteLine($"{x.name}: {x.CalculatePay()}"); } }); }
static void Main(string[] args) { Employee[] employees = new Employee[10]; for (int i = 0; i < employees.Length; i++) { if (random.Next(0, 11) < 5) { employees[i] = new SalesEmployee("name", random.Next(10, 1000), random.Next(10, 1000)); } else { employees[i] = new PartTimeEmployee("name", random.Next(10, 1000), random.Next(10, 40)); } } Array.Sort(employees, (e1, e2) => e2.CalculatePay().CompareTo(e1.CalculatePay())); foreach (Employee employee in employees) { if (employee is SalesEmployee) { Console.WriteLine(employee.CalculatePay()); } } Console.WriteLine("***"); foreach (Employee employee in employees) { if (employee is PartTimeEmployee) { Console.WriteLine(employee.CalculatePay()); } } Console.ReadKey(); }
static void Main(string[] args) { Random r = new Random(); Employee[] s = new Employee[r.Next(3, 12)]; for (int i = 0; i < s.Length; i++) { if (r.Next(0, 2) == 1) { s[i] = new SalesEmployee("anton", r.Next(2, 232535), r.Next(2, 232535)); } else { s[i] = new PartTimeEmployee("dima", r.Next(2, 232535), r.Next(1, 25)); } } Array.Sort(s); Console.WriteLine("PartTimeEmployee:"); foreach (var a in s) { if (a is PartTimeEmployee) { Console.WriteLine($"{a.name} {a.CalculatePay()}"); } } Console.WriteLine("SalesEmployee:"); foreach (var a in s) { if (a is SalesEmployee) { Console.WriteLine($"{a.name} {a.CalculatePay()}"); } } }
static void Main() { Random rnd = new Random(); // Create some new employees. var employee1 = new SalesEmployee("Alice", 1000, 500); var employee3 = new PartTimeEmployee("Charlie", 1000, 10); var employee2 = new Employee("Bob", 1200); Console.WriteLine($"Employee1 {employee1.name} earned: {employee1.CalculatePay()}"); Console.WriteLine($"Employee2 {employee2.name} earned: {employee2.CalculatePay()}"); Console.WriteLine($"Employee3 {employee2.name} earned: {employee3.CalculatePay()}"); Employee[] employees = new Employee[10]; for (int i = 0; i < 10; ++i) { if (rnd.Next(3) == 0) { employees[i] = new PartTimeEmployee("Smith", rnd.Next(2000), rnd.Next(30)); } else { employees[i] = new SalesEmployee("Smith", rnd.Next(2000), rnd.Next(1000)); } } Array.Sort(employees, (x, y) => (x.CalculatePay()).CompareTo(y.CalculatePay())); Array.Reverse(employees); for (int i = 0; i < 10; ++i) { Console.WriteLine($"Employee {employees[i].name} earned: {employees[i].CalculatePay()}"); } }
static void Main(string[] args) { do { Console.Clear(); int n; Console.Write("Enter n = "); int.TryParse(Console.ReadLine(), out n); Employee[] empls = new Employee[n]; string name = RandomString(rnd.Next(10000, 15000)); for (int i = 0; i < empls.Length; i++) { if (rnd.Next(0, 2) == 1) { empls[i] = new SalesEmployee(RandomString(rnd.Next(3, 7)), rnd.Next(10, 1000), rnd.Next(10, 1000)); } else { empls[i] = new PartTimeEmployee(RandomString(rnd.Next(3, 7)), rnd.Next(10, 1000), rnd.Next(10, 40)); } } for (int i = 0; i < empls.Length; i++) { Console.WriteLine(empls[i]); } Array.Sort(empls, (e1, e2) => e1.CalculatePay().CompareTo(e2.CalculatePay())); Console.WriteLine("***"); for (int i = 0; i < empls.Length; i++) { Console.WriteLine(empls[i]); } Console.WriteLine("***"); foreach (Employee employee in empls) { if (employee is SalesEmployee) { Console.WriteLine(employee.CalculatePay()); } } Console.WriteLine("***"); foreach (Employee employee in empls) { if (employee is PartTimeEmployee) { Console.WriteLine(employee.CalculatePay()); } } } while (Console.ReadKey().Key != ConsoleKey.Escape); }
static void Main(string[] args) { List <string> names = new List <string>() { "Alexey", "Ivan", "Dmitry", "Vladimir", "Oleg", "Andrey", "Maxim", "Victor", "Alexandr", "Vyacheslav" }; Random rand = new Random(); Employee[] employees = new Employee[10]; decimal[] arr = new decimal[10]; for (int i = 0; i < employees.Length; i++) { if (rand.Next(0, 2) == 0) { employees[i] = new SalesEmployee(names[rand.Next(0, names.Count)], (decimal)(rand.Next(10, 30) + rand.NextDouble()), (decimal)(rand.Next(10, 30) + rand.NextDouble())); names.Remove(employees[i].name); } else { employees[i] = new PartTimeEmployee(names[rand.Next(0, names.Count)], (decimal)(rand.Next(10, 30) + rand.NextDouble()), rand.Next(10, 30)); names.Remove(employees[i].name); } arr[i] = employees[i].CalculatePay(); } Array.Sort(arr, employees); Console.WriteLine("SaleEmployee:"); for (int i = employees.Length - 1; i >= 0; i--) { if (employees[i] is SalesEmployee) { Console.WriteLine(employees[i].name + " " + employees[i].CalculatePay().ToString("f3")); } } Console.WriteLine("PartTimeEmployee:"); for (int i = employees.Length - 1; i >= 0; i--) { if (employees[i] is PartTimeEmployee) { Console.WriteLine(employees[i].name + " " + employees[i].CalculatePay().ToString("f3")); } } }