using System; using System.Collections.Generic; using System.Linq; public class Car { public string Brand { get; set; } public int ReleaseYear { get; set; } public int Mileage { get; set; } public int Price { get; set; } public List EmergencySituations { get; set; } public int ReplacedPartsCount { get; set; } public int EmergencyCount { get; set; } public Car(string brand, int releaseYear, int mileage, int price, List emergencySituations) { Brand = brand; ReleaseYear = releaseYear; Mileage = mileage; Price = price; EmergencySituations = emergencySituations; ReplacedPartsCount = emergencySituations.Sum(); EmergencyCount = emergencySituations.Count; } public string GetDescription() { return $"Автомобиль {ReleaseYear} года выпуска, марка {Brand}.\n" + $"Пробег: {Mileage}.\n" + $"Аварий: {EmergencyCount}, " + $"из с ремонтом: {EmergencyCount - EmergencySituations.Count(x => x == 0)}.\n" + $"Стоимость автомобиля составляет {Price}р.\n"; } } public class Program { private static List carList = new List { new Car("Toyota Camry", 2018, 120000, 1800000, new List { 0, 1, 2 }), new Car("BMW 520i", 2020, 85000, 3200000, new List { 3, 0 }), new Car("Hyundai Solaris", 2015, 180000, 750000, new List { 0, 0, 1 }), new Car("Volkswagen Polo", 2019, 95000, 1200000, new List()), new Car("Audi A6", 2021, 60000, 4500000, new List { 5 }), new Car("Kia Rio", 2017, 140000, 900000, new List { 1, 1, 0, 2 }), new Car("Mercedes-Benz C-Class", 2022, 40000, 5500000, new List()), new Car("Lada Vesta", 2020, 70000, 800000, new List { 0 }), new Car("Renault Logan", 2016, 160000, 650000, new List { 2, 0, 1, 0 }), new Car("Skoda Octavia", 2018, 110000, 1500000, new List { 0, 0 }), new Car("Nissan Qashqai", 2019, 80000, 1900000, new List { 4, 1, 0 }), new Car("Ford Focus", 2014, 200000, 600000, new List { 0, 1 }), new Car("Mazda 3", 2017, 130000, 1100000, new List { 1, 2, 3, 0 }), new Car("Mitsubishi Outlander", 2021, 55000, 2800000, new List()), new Car("Chevrolet Cruze", 2013, 190000, 550000, new List { 1, 0 }) }; public static void Main(string[] args) { PrintMenu(); } static void PrintMenu() { while (true) { Console.WriteLine(@" Выберите один из пунктов меню ниже и напишите его номер ╔═══════════════════════════════════════╗ ║ Меню выбора автомобилей ║ ╠═══════════════════════════════════════╣ ║ 1 Самый дешевый автомобиль ║ ║ 2 Самый новый автомобиль ║ ║ 3 Автомобиль с меньшим кол-вом аварий ║ ║ 4 С авариями без замен деталей ║ ║ 5 Выход из программы ║ ╚═══════════════════════════════════════╝ "); string number = Console.ReadLine(); if (!int.TryParse(number, out int choice) || !new[] { 1, 2, 3, 4, 5 }.Contains(choice)) { Console.WriteLine("Ожидалось целое число: 1, 2, 3, 4 или 5"); continue; } switch (choice) { case 1: List sortedAutoByPrice = carList.OrderBy(car => car.Price).ToList(); PrintCars(sortedAutoByPrice); break; case 2: List sortedAutoByYear = carList.OrderByDescending(car => car.ReleaseYear).ThenBy(car => car.Mileage).ToList(); PrintCars(sortedAutoByYear); break; case 3: List sortedAutoByAccidents = carList.OrderBy(car => car.EmergencyCount).ToList(); PrintCars(sortedAutoByAccidents); break; case 4: List sortedAutoWithAccidents = carList.Where(car => car.EmergencyCount > 0).OrderBy(car => car.EmergencyCount).ToList(); PrintCars(sortedAutoWithAccidents); break; case 5: return; } } } static void PrintCars(List cars) { int currentCarIndex = 0; int maxCars = cars.Count; while (true) { Car car = cars[currentCarIndex]; Console.WriteLine("\n\n\n"); Console.WriteLine(car.GetDescription()); Console.WriteLine( @" Выберите один из пунктов меню ниже и напишите его номер ╔═══════════════════════════════════════╗ ║ Обзор автомобилей по фильтру ║ ╠═══════════════════════════════════════╣ ║ 1 Вернуться в главное меню x ║ ║ 2 Предыдущий автомобиль <-- ║ ║ 3 Следующий автомобиль --> ║ ╚═══════════════════════════════════════╝ " ); string number = Console.ReadLine(); if (!int.TryParse(number, out int choice) || !new[] { 1, 2, 3 }.Contains(choice)) { Console.WriteLine("Ожидалось целое число: 1, 2 или 3"); continue; } switch (choice) { case 1: return; case 2: if (currentCarIndex-1 == -1) { Console.WriteLine("Вы долистали до начала списка."); } else { currentCarIndex--; } break; case 3: if (currentCarIndex+1 == maxCars) { Console.WriteLine("Вы долистали до конца списка."); } else { currentCarIndex++; } break; } //currentCarIndex = Math.Max(0, currentCarIndex); //currentCarIndex = Math.Min(maxCars -1, currentCarIndex); } } }