Esempio n. 1
0
        internal static MyCustomType_Vehicle InputNewVehicle()
        {
            MyCustomType_Vehicle vehicleToAdd = null;

            string userInputVehicleName = AskUserForVehicleName();

            // If user enters anything aside from 'done' we will create a new vehicle
            if (!string.Equals(userInputVehicleName, "done", StringComparison.OrdinalIgnoreCase))
            {
                vehicleToAdd = new MyCustomType_Vehicle(userInputVehicleName);

                bool doneAddingTrips = false;
                bool showWarning     = false;
                do
                {
                    MyCustomType_Trip tripToAdd = InputNewTrip(showWarning);

                    if (tripToAdd == null && !vehicleToAdd.VehicleTrips.Any())
                    {
                        showWarning = true;
                    }
                    else if (tripToAdd == null)
                    {
                        doneAddingTrips = true;
                    }
                    else
                    {
                        showWarning = false;
                        vehicleToAdd.VehicleTrips.Add(tripToAdd);
                    }
                } while (!doneAddingTrips);
            }

            return(vehicleToAdd);
        }
Esempio n. 2
0
        public static void Main()
        {
            bool doneAddingVehicles = false;

            do
            {
                MyCustomType_Vehicle vehicleToAdd = UserPrompts.InputNewVehicle();

                if (vehicleToAdd == null)
                {
                    doneAddingVehicles = true;
                }
                else
                {
                    _myVehicles.Add(vehicleToAdd);
                }
            } while (!doneAddingVehicles);

            Console.Clear();

            if (_myVehicles.Any())
            {
                DisplaySingleBestMPGTrip();
                DisplayVehicleWithTheBestMPG();
                DumpAllData();
            }
            else
            {
                Console.WriteLine("No vehicles with trips entered");
                UserPrompts.Exit();
            }
        }
Esempio n. 3
0
        private static void DisplayVehicleWithTheBestMPG()
        {
            MyCustomType_Vehicle vehicleWithBestMPG = _myVehicles
                                                      .OrderByDescending(v => v.TotalMPGForAllTrips)
                                                      .First();

            Console.WriteLine($"The {vehicleWithBestMPG.VehicleName} had the best total MPG at {vehicleWithBestMPG.TotalMPGForAllTrips}");
        }
Esempio n. 4
0
        private static void DisplaySingleBestMPGTrip()
        {
            MyCustomType_Vehicle vehicleWithBestMPGTrip = _myVehicles
                                                          .OrderByDescending(v => v.BestMPGTrip.TripMPG)
                                                          .First();

            Console.WriteLine($"The best MPG trip was in the {vehicleWithBestMPGTrip.VehicleName} with {vehicleWithBestMPGTrip.BestMPGTrip.TripMPG}");
        }