Exemplo n.º 1
0
        static void Main(string[] args)
        {
            List <CVehicle>         vehiclesList      = GetTestDataForCheckingCommonProperties();
            List <ISeatingCapacity> seatingCapacities = GetTestDataForCheckingSeatingCapacity();

            Console.WriteLine("We have the next list of vehicles (3 Plane, 3 CShip, 3, CCar) below:");
            Console.WriteLine(new string('-', 50));
            foreach (var veh in vehiclesList)
            {
                Console.WriteLine(veh);
            }

            string textOfVariants =
                @"You can choose the next filters:
            1.  Get the highest price
            2.  Get the lowest price
            3.  Get the newest one
            4.  Get the oldest one
            5.  Get the fastest one
            6.  Get the slowest one
            7.  Get all in Northern hemisphere
            8.  Get all in Southern hemisphere
            9.  Get all in Western hemisphere
            10. Get all in Eastern hemisphere
            11. Get all at Equator
            12. Get all at Prime Meridian
            13. Get the biggest seating capacity
            14. Get the smallest seating capacity
            15. Get the biggest seating capacity among plane
            16. Get the vehicle by any condition
        If you gonna leave press button 'q'";

            CVehicle         vehicle         = null;
            List <CVehicle>  vehicles        = null;
            ISeatingCapacity seatingCapacity = null;
            string           answer          = null;
            char             firstLetter;

            do
            {
                Console.WriteLine(new string('-', 50));
                Console.WriteLine(textOfVariants);
                Console.Write("Answer:\t");

                answer      = Console.ReadLine();
                firstLetter = answer.ToUpper().First();

                //int option;
                int.TryParse(answer, out int option);

                if (option > 0 && option <= 16)
                {
                    switch (option)
                    {
                    case 1:
                        vehicle = CVehiclesUtil.GetTheHighestPrice(vehiclesList);
                        break;

                    case 2:
                        vehicle = CVehiclesUtil.GetTheLowestPrice(vehiclesList);
                        break;

                    case 3:
                        vehicle = CVehiclesUtil.GetTheNewest(vehiclesList);
                        break;

                    case 4:
                        vehicle = CVehiclesUtil.GetTheOldest(vehiclesList);
                        break;

                    case 5:
                        vehicle = CVehiclesUtil.GetTheFastest(vehiclesList);
                        break;

                    case 6:
                        vehicle = CVehiclesUtil.GetTheSlowest(vehiclesList);
                        break;

                    case 7:
                        vehicles = CVehiclesUtil.GetAllInNorthernHemisphere(vehiclesList);
                        break;

                    case 8:
                        vehicles = CVehiclesUtil.GetAllInSouthernHemisphere(vehiclesList);
                        break;

                    case 9:
                        vehicles = CVehiclesUtil.GetAllInWesternHemisphere(vehiclesList);
                        break;

                    case 10:
                        vehicles = CVehiclesUtil.GetAllInEasternHemisphere(vehiclesList);
                        break;

                    case 11:
                        vehicles = CVehiclesUtil.GetAllAtEquator(vehiclesList);
                        break;

                    case 12:
                        vehicles = CVehiclesUtil.GetAllAtPrimeMeridian(vehiclesList);
                        break;

                    case 13:
                        seatingCapacity = CVehiclesUtil.GetTheBiggestSeatingCapacity(seatingCapacities);
                        break;

                    case 14:
                        seatingCapacity = CVehiclesUtil.GetTheSmallestSeatingCapacity(seatingCapacities);
                        break;

                    case 15:
                        seatingCapacity = CVehiclesUtil.GetTheBiggestSeatingCapacityAmongPlane(seatingCapacities);
                        break;

                    case 16:
                        vehicles = CVehiclesUtil.GetAllAtAnyCondition(vehiclesList, PredicatesForConditions.Predicate);
                        break;
                    }

                    Console.WriteLine("Result:");

                    if (vehicle == null && vehicles == null && seatingCapacity == null)
                    {
                        Console.WriteLine("We've found nothing!");
                    }
                    else
                    {
                        if (vehicle != null)
                        {
                            Console.WriteLine(vehicle);
                            vehicle = null;
                        }
                        if (vehicles != null)   //list of vehicles
                        {
                            foreach (var veh in vehicles)
                            {
                                Console.WriteLine(veh);
                            }
                            vehicles = null;
                        }
                        if (seatingCapacity != null)
                        {
                            Console.WriteLine(seatingCapacity);
                            seatingCapacity = null;
                        }
                    }
                }
                else if (firstLetter != 'Q')
                {
                    Console.WriteLine("This option is unavailable. Try again with choosing from list.");
                }
            }while (firstLetter != 'Q');
        }