Exemple #1
0
        static void Main(string[] args)
        {
            IList <IVehicle> taxi = new List <IVehicle>
            {
                new PassengerVehicle(Guid.NewGuid(), "3334 AM-4", AutoBrand.Audi, "A6", new DateTime(2008, 10, 30), 2039498, 200, FuelType.AI95, 10.5f, 157000, 4),
                new Truck(Guid.NewGuid(), "6783 EX-4", AutoBrand.Volkswagen, "T9", new DateTime(2000, 01, 30), 67382, 130, FuelType.Diesel, 12f, 350000, 5, 4, 2, 2),
                new PassengerVehicle(Guid.NewGuid(), "7334 AM-4", AutoBrand.Audi, "A4", new DateTime(2005, 10, 30), 3039498, 170, FuelType.AI92, 8.5f, 307000, 4),
                new PassengerVehicle(Guid.NewGuid(), "2744 AM-4", AutoBrand.Mersedes, "Sprinter", new DateTime(2015, 11, 30), 56339498, 140, FuelType.Diesel, 9.5f, 57000, 14),
                new Truck(Guid.NewGuid(), "7983 EX-4", AutoBrand.Mersedes, "Sprinter", new DateTime(2003, 01, 30), 167382, 137, FuelType.Diesel, 12f, 170000, 5, 4, 2, 2),
                new Truck(Guid.NewGuid(), "3383 EX-4", AutoBrand.Volkswagen, "T9", new DateTime(2012, 01, 30), 567382, 125, FuelType.Diesel, 10f, 51030, 5, 4, 2, 2)
            };

            TaxiPark app = new TaxiPark();

            app.Vehicles = taxi;

            double totalPrice = app.GetTotalPrice();

            Console.WriteLine("Taxipark total cost : {0}", totalPrice.ToString());
            Console.WriteLine();

            Console.WriteLine("Sort by fuel consumption:");
            IList <IVehicle> sortedVehicles = app.GetSortedVehicles();

            foreach (var taxiCar in sortedVehicles)
            {
                Console.WriteLine("{0} - {1} ; {2} ; {3} ; {4}; {5}",
                                  taxiCar.Сonsumption, taxiCar.StateCarNumber, taxiCar.AutoBrand, taxiCar.Name, taxiCar.FuelType.ToString(), taxiCar.Produced.ToString());
            }

            Console.WriteLine();

            Console.WriteLine("Search by speed range.");
            int minSpeed, maxSpeed;

            do
            {
                Console.Write("Enter the minimum speed: ");
                minSpeed = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter the maximum speed: ");
                maxSpeed = Convert.ToInt32(Console.ReadLine());
            } while (minSpeed > maxSpeed);
            IList <IVehicle> findVehicleBySpeed = app.GetVehiclesBySpeed(minSpeed, maxSpeed);

            if (findVehicleBySpeed.Count > 0)
            {
                Console.WriteLine("Result:");
                foreach (var taxiCar in findVehicleBySpeed)
                {
                    Console.WriteLine("{0} - {1} ; {2} ; {3}", taxiCar.MaximumSpeed, taxiCar.StateCarNumber, taxiCar.AutoBrand, taxiCar.Name);
                }
            }
            else
            {
                Console.WriteLine("No cars found with specified parameters");
            }

            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            /**************************************************/
            ConsoleKeyInfo key;
            TaxiPark       TaxiPark = new TaxiPark("KPI_Taxi");
            bool           register = false;
            string         in_str   = string.Empty;
            double         money;
            decimal        distance;
            string         day = DateTime.Today.DayOfWeek.ToString();
            string         car = "car";


            /**************************************************/
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\t\tHello! Welcome to our KPI_Taxi");
            Console.WriteLine();
            Console.ResetColor();
            while (true)
            {
                Client client = new Client();
                Console.ForegroundColor = ConsoleColor.Magenta;

                Console.WriteLine("Press 'S' to get started with our company");
                Console.WriteLine("Press 'W' to see the list of our workers and clients");
                Console.WriteLine("Press 'Q' to quit ");
                Console.WriteLine("Press 'R' to restart ");
                Console.WriteLine("Press 'C' to clear the console");
                Console.ResetColor();

                key = Console.ReadKey();

                if (key.Key == ConsoleKey.Q)
                {
                    break;
                }
                if (key.Key == ConsoleKey.R)
                {
                    continue;
                }
                if (key.Key == ConsoleKey.C)
                {
                    Console.Clear();
                }
                /**************************************************/
                if (key.Key == ConsoleKey.W)
                {
                    Console.WriteLine();
                    TaxiPark.WorkerInfo();
                    Console.WriteLine();
                    TaxiPark.ClientInfo();
                    continue;
                }
                /**************************************************/
                if (key.Key == ConsoleKey.S)
                {
                    Console.WriteLine("\nDear client, please input your name:");
                    while (true)
                    {
                        in_str = Console.ReadLine();
                        try
                        {
                            if (in_str == string.Empty)
                            {
                                throw new ArgumentException(message: "Name is empty");
                            }
                            else
                            {
                                client.Name = in_str;
                                break;
                            }
                        }
                        catch (ArgumentException exeption)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine(exeption.Message);
                            Console.ResetColor();
                        }

                        Console.WriteLine("Please enter your name again");
                    }
                    client.Name = in_str;

                    Console.WriteLine("Are you already registered? Enter 'Yes' or 'No' ");
                    while (true)
                    {
                        in_str = Console.ReadLine();
                        if (in_str == "Yes" || in_str == "yes")
                        {
                            register = true;
                            break;
                        }
                        else if (in_str == "No" || in_str == "no")
                        {
                            register = false;
                            break;
                        }
                        Console.WriteLine("Sorry, but you entered something wrong. Try again");
                    }
                    client.Registration = register;
                    /**************************************************/
                    Console.WriteLine("Please, enter state of your account: ");
                    while (true)
                    {
                        in_str = Console.ReadLine();
                        if ((double.TryParse(in_str, out money)))
                        {
                            break;
                        }

                        Console.WriteLine("Sorry, but you entered something wrong. Try again");
                    }
                    client.Account = money;
                }

                else
                {
                    Console.WriteLine();
                    continue;
                }
                /**************************************************/
                Console.WriteLine("Press 'Enter' to order our taxi, or something else to return to menu");
                key = Console.ReadKey();
                if (key.Key == ConsoleKey.Enter)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please, input a distance of your trip:");
                    while (true)
                    {
                        in_str = Console.ReadLine();
                        if (decimal.TryParse(in_str, out distance))
                        {
                            break;
                        }
                        Console.WriteLine("Sorry, but you entered something wrong. Try again");
                    }
                    /**************************************************/
                    Console.WriteLine();
                    Console.WriteLine("Now you must choose a car. Enter a number:");
                    Console.WriteLine("1. CarX \t 2. Prime  \t 3. Bus \t 4. Green");
                    while (true)
                    {
                        int i = 0;
                        try
                        {
                            i = Convert.ToInt32(Console.ReadLine());
                        }
                        catch (FormatException)
                        {
                            Console.WriteLine("Not a number");
                        }
                        if (i >= 1 && i <= 4)
                        {
                            switch (i)
                            {
                            case 1:
                                car = "CarX";
                                break;

                            case 2:
                                car = "Prime";
                                break;

                            case 3:
                                car = "Bus";
                                break;

                            case 4:
                                car = "Green";
                                break;
                            }
                            break;
                        }
                        Console.WriteLine("Sorry, but you entered something wrong. Try again");
                    }

                    Console.WriteLine("Thanks for choosing us!");

                    client.Order(distance, day, car);
                    TaxiPark.ClientAccount(client);
                }

                else
                {
                    continue;
                }
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // Create 2 taxi parks.
            ITaxiPark taxiPark = new TaxiPark();

            // Create different engines to test.
            IEngine V6engine       = new FuelEngine(242, 9.8);
            IEngine V8engine       = new FuelEngine(479, 15.7);
            IEngine V12engine      = new FuelEngine(987, 20.8);
            IEngine electricEngine = new ElectricEngine(256, 6.4);

            //Create cars and add them to taxi parks.
            TaxiCar taxiCar4 = new TaxiCarBuilder()
                               .SetCost(6400)
                               .SetEngine(V6engine)
                               .SetSeats(5)
                               .SetWeight(1200);
            TaxiCar taxiCar1 = new TaxiCarBuilder()
                               .SetCost(6700)
                               .SetEngine(V6engine)
                               .SetSeats(5)
                               .SetWeight(1700);
            TaxiCar taxiCar2 = new TaxiCarBuilder()
                               .SetCost(16100)
                               .SetEngine(V8engine)
                               .SetSeats(5)
                               .SetWeight(1900);
            TaxiCar taxiCar3 = new TaxiCarBuilder()
                               .SetCost(26400)
                               .SetEngine(V12engine)
                               .SetSeats(5)
                               .SetWeight(2200);
            TaxiCar electricTaxiCar = new TaxiCarBuilder()
                                      .SetCost(36400)
                                      .SetEngine(electricEngine)
                                      .SetSeats(5)
                                      .SetWeight(2000);

            taxiPark.AddCar(taxiCar3);
            taxiPark.AddCar(taxiCar2);
            taxiPark.AddCar(taxiCar1);

            taxiPark.AddCar(taxiCar4);
            taxiPark.AddCar(electricTaxiCar);
            Console.WriteLine("#################################################################");
            Console.WriteLine("Searching cars by speed in range from 100 to 300...");
            Console.WriteLine("#################################################################");
            //Test methods.
            foreach (var item in
                     taxiPark.SearchBySpeed(100, 300))
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("#################################################################");
            Console.WriteLine("Searching cars by speed value equals to 142...");
            Console.WriteLine("#################################################################");
            foreach (var item in
                     taxiPark.SearchBySpeed(142))
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("#################################################################");
            Console.WriteLine("Cars of the taxi park before sorting");
            Console.WriteLine("#################################################################");
            Console.WriteLine(taxiPark);
            taxiPark.SortByConsumption();
            Console.WriteLine("#################################################################");
            Console.WriteLine("Cars of the taxi park after sorting");
            Console.WriteLine("#################################################################");
            Console.WriteLine(taxiPark);
            Console.WriteLine();
        }