static void Main(string[] args)
        {
            var myTank      = new Tank(68000, 70);
            var myWarship   = new Warship(35000, 80);
            var myAmphibian = new Amphibian(23000, 40);

            Console.WriteLine("Greetings!\nI see you're in need of " +
                              "troop transport!\n");
            do
            {
                Console.WriteLine("Please enter the number of soldiers you need " +
                                  "to transport:");

                var peopleToTransport = 0;
                while (!int.TryParse(Console.ReadLine(), out peopleToTransport))
                {
                    Console.WriteLine("That is not a valid input, please try again:");
                }

                Console.WriteLine("Enter the distance the TANK " +
                                  "needs to overcome in kilometers:");

                var distanceTank = 0;
                while (!int.TryParse(Console.ReadLine(), out distanceTank))
                {
                    Console.WriteLine("That is not a valid input, please try again:");
                }

                Console.WriteLine("Enter the distance the WARSHIP " +
                                  "needs to overcome in kilometers:");

                var distanceWarship = 0;
                while (!int.TryParse(Console.ReadLine(), out distanceWarship))
                {
                    Console.WriteLine("That is not a valid input, please try again:");
                }


                var distanceAmphibianByLand = 0;
                var distanceAmphibianBySea  = 0;

                while (true)
                {
                    Console.WriteLine("Enter the distance the AMPHIBIAN " +
                                      "needs to overcome by SEA in kilometers:");

                    while (!int.TryParse(Console.ReadLine(), out distanceAmphibianBySea))
                    {
                        Console.WriteLine("That is not a valid input, please try again:");
                    }

                    Console.WriteLine("Enter the distance the AMPHIBIAN " +
                                      "needs to overcome by LAND in kilometers:");

                    while (!int.TryParse(Console.ReadLine(), out distanceAmphibianByLand))
                    {
                        Console.WriteLine("That is not a valid input, please try again:");
                    }

                    if (distanceAmphibianBySea + distanceAmphibianByLand > distanceTank ||
                        distanceAmphibianBySea + distanceAmphibianByLand > distanceWarship)
                    {
                        Console.WriteLine("\n\nThe distance the amphibian has to travel MUST be " +
                                          "shorter than the ones the tank and warship have to cross!\n\n");
                    }
                    else
                    {
                        break;
                    }
                }

                var totalDistanceTank      = myTank.Move(distanceTank);
                var totalDistanceWarship   = myWarship.Swim(distanceWarship);
                var totalDistanceAmphibian = myAmphibian.Move(distanceAmphibianByLand) +
                                             myAmphibian.Swim(distanceAmphibianBySea);

                var totalFuelConsumptionTank = myTank.FuelConsumptionTotal
                                                   (totalDistanceTank, peopleToTransport);
                var totalFuelConsumptionWarship = myWarship.FuelConsumptionTotal
                                                      (totalDistanceWarship, peopleToTransport);
                var totalFuelConsumptionAmphibian = myWarship.FuelConsumptionTotal
                                                        (totalDistanceAmphibian, peopleToTransport);

                var bestTransport = Utility.LeastFuelSpent(totalFuelConsumptionTank,
                                                           totalFuelConsumptionWarship, totalFuelConsumptionAmphibian);

                Console.WriteLine($"\nThe best option for transport is: {bestTransport}");

                switch (bestTransport)
                {
                case ("Tank"):
                    Console.WriteLine(myTank.Print(totalDistanceTank, peopleToTransport));
                    break;

                case ("Warship"):
                    Console.WriteLine(myWarship.Print(totalDistanceWarship, peopleToTransport));
                    break;

                case ("Amphibian"):
                    Console.WriteLine(myAmphibian.Print(totalDistanceAmphibian, peopleToTransport));
                    break;
                }

                Console.WriteLine("\nWould you like to make another shipment?");
                Console.WriteLine(" ___________________________");
                Console.WriteLine("|                           |");
                Console.WriteLine("|Press Y            for Yes |");
                Console.WriteLine("|Press anything else for No |");
                Console.WriteLine("|___________________________|");
            }while (Console.ReadKey().Key == ConsoleKey.Y);
        }
Exemple #2
0
        private static void Main()
        {
            var exampleTank      = new Tank(25000, 40);
            var exampleWarship   = new Warship(75000, 50);
            var exampleAmphibian = new Amphibian(10000, 30);

            int tankDistance;
            int warshipDistance;
            int amphibianDriveDistance;
            int amphibianSwimDistance;

            do
            {
                Console.WriteLine("Enter the tank's driving distance:");
                tankDistance = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter the warship's swimming distance:");
                warshipDistance = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter the amphibian's driving distance:");
                amphibianDriveDistance = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter the amphibian swimming distance:");
                amphibianSwimDistance = int.Parse(Console.ReadLine());

                if (amphibianDriveDistance + amphibianSwimDistance > tankDistance ||
                    amphibianDriveDistance + amphibianSwimDistance > warshipDistance)
                {
                    Console.WriteLine("Error! Amphibian needs to have the shortest path!");
                }
            } while (amphibianDriveDistance + amphibianSwimDistance > tankDistance ||
                     amphibianDriveDistance + amphibianSwimDistance > warshipDistance);

            Console.WriteLine("Enter the number of soldiers:");
            var numberOfSoldiers = int.Parse(Console.ReadLine());

            tankDistance           = tankDistance * exampleTank.NumberOfDistancesCovered(numberOfSoldiers);
            amphibianDriveDistance = amphibianDriveDistance * exampleTank.NumberOfDistancesCovered(numberOfSoldiers);
            amphibianSwimDistance  = amphibianSwimDistance * exampleTank.NumberOfDistancesCovered(numberOfSoldiers);
            warshipDistance        = warshipDistance * exampleTank.NumberOfDistancesCovered(numberOfSoldiers);

            exampleTank.Move(ref tankDistance);
            exampleAmphibian.Move(ref amphibianDriveDistance);
            exampleAmphibian.Swim(ref amphibianSwimDistance, exampleAmphibian.AverageSpeed);
            var fullAmphibianDistance = amphibianSwimDistance + amphibianDriveDistance;

            exampleWarship.Swim(ref warshipDistance, exampleWarship.AverageSpeed);

            exampleTank.Print(tankDistance);
            exampleAmphibian.Print(fullAmphibianDistance);
            exampleWarship.Print(warshipDistance);

            var tankFuelConsumed      = exampleTank.FuelConsumed(tankDistance);
            var amphibianFuelConsumed = exampleAmphibian.FuelConsumed(fullAmphibianDistance);
            var warshipFuelConsumed   = exampleWarship.FuelConsumed(warshipDistance);

            Console.WriteLine();

            if (tankFuelConsumed < amphibianFuelConsumed && tankFuelConsumed < warshipFuelConsumed)
            {
                Console.WriteLine("The optimal vehicle is the tank.");
            }
            else if (amphibianFuelConsumed < tankFuelConsumed && amphibianFuelConsumed < warshipFuelConsumed)
            {
                Console.WriteLine("The optimal vehicle is the amphibian.");
            }
            else if (warshipFuelConsumed < amphibianFuelConsumed && warshipFuelConsumed < tankFuelConsumed)
            {
                Console.WriteLine("The optimal vehicle is the warship.");
            }
        }