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); }
private static MyCustomType_Trip InputNewTrip(bool showWarning) { MyCustomType_Trip tripToAdd = null; decimal tripLength = AskUserForTripLength(showWarning); if (tripLength > 0) { tripToAdd = new MyCustomType_Trip() { TotalMilesDriven = tripLength }; tripToAdd.TotalGallonsOfGasUsed = AskUserForGallonsOfGasUsed(); Console.WriteLine($"MPG for this trip is {tripToAdd.TripMPG}"); Console.WriteLine("Press any key to continue . . . "); Console.ReadKey(); } return(tripToAdd); }