private void UpdateHybridCar() { Console.Clear(); List <HybridCar> listOfHybridCars = _hybridCarList.GetHybridCar(); Console.WriteLine("Manufacturer * Model * Year * Top Speed * Acceleration * Charging Time * Nominal Range"); foreach (var item in listOfHybridCars) { Console.WriteLine($"{item.Manufacturer} * {item.Model} * {item.YearMade.Year} * {item.TopSpeed} * {item.Acceleration} * {item.ChargingTime} * {item.NominalRange}"); } Console.WriteLine($"\nWhich model of car would you like to update?"); string model = Console.ReadLine().ToLower(); HybridCar car = _hybridCarList.GetHybridCarByModel(model); Console.Clear(); Console.WriteLine($"You are editing info for the {car.Model}. Please enter the updated info:"); Console.WriteLine($"Updated Manufacturer ({car.Manufacturer}):"); car.Manufacturer = Console.ReadLine(); Console.WriteLine($"Model ({car.Model}):"); car.Model = Console.ReadLine(); Console.WriteLine($"Year Made ({car.YearMade.Year}):"); string year = Console.ReadLine(); car.YearMade = DateTime.Parse($"01/01/{year}"); Console.WriteLine($"Top Speed ({car.TopSpeed}):"); car.TopSpeed = int.Parse(Console.ReadLine()); Console.WriteLine($"Acceleration ({car.Acceleration}):"); car.Acceleration = double.Parse(Console.ReadLine()); Console.WriteLine($"Charging Time ({car.ChargingTime} hours:minutes):"); car.ChargingTime = TimeSpan.Parse(Console.ReadLine()); Console.WriteLine($"Nominal Range ({car.NominalRange}):"); car.NominalRange = int.Parse(Console.ReadLine()); _hybridCarList.UpdateHybridCar(model, car); Console.Clear(); Console.WriteLine($"You've added a new hybrid car.\n" + $"Manufacturer: {car.Manufacturer}\n" + $"Model: {car.Model}\n" + $"Year: {car.YearMade.Year}\n" + $"Top Speed: {car.TopSpeed}\n" + $"Acceleration: {car.Acceleration}\n" + $"Charging Time: {car.ChargingTime.Hours}\n" + $"Nominal Range: {car.NominalRange}"); Console.WriteLine($"\nPress any key to continue..."); Console.ReadKey(); }
//Delete public bool RemoveHybridCar(string model) { HybridCar content = GetHybridCarByModel(model); if (content == null) { return(false); } int initialCount = _listOfHybridCars.Count; _listOfHybridCars.Remove(content); if (initialCount > _listOfHybridCars.Count) { return(true); } else { return(false); } }
//UPDATE public bool UpdateHybridCar(string model, HybridCar newContent) { // Find the content HybridCar oldContent = GetHybridCarByModel(model); //Update the content if (oldContent != null) { oldContent.Manufacturer = newContent.Manufacturer; oldContent.Model = newContent.Model; oldContent.YearMade = newContent.YearMade; oldContent.TopSpeed = newContent.TopSpeed; oldContent.Acceleration = newContent.Acceleration; oldContent.ChargingTime = newContent.ChargingTime; oldContent.NominalRange = newContent.NominalRange; return(true); } else { return(false); } }
private void SeedList() { GasCar gasCar1 = new GasCar("Toyota", "Prius Eco", DateTime.Parse("01-01-2020"), 124, 9.9, TimeSpan.Parse("0"), 269); GasCar gasCar2 = new GasCar("Honda", "Insight", DateTime.Parse("01-01-2020"), 100, 9.2, TimeSpan.Parse("0"), 250); GasCar gasCar3 = new GasCar("Honda", "Accord", DateTime.Parse("01-01-2019"), 98, 8.9, TimeSpan.Parse("0"), 153); ElectricCar electricCar1 = new ElectricCar("Audi", "e-tron 55", DateTime.Parse("01-01-2018"), 124, 5.7, TimeSpan.Parse("8:30"), 269); ElectricCar electricCar2 = new ElectricCar("Volkswagon", "ID.4", DateTime.Parse("01-01-2020"), 100, 9.8, TimeSpan.Parse("9:00"), 250); ElectricCar electricCar3 = new ElectricCar("BMW", "i3", DateTime.Parse("01-01-2019"), 98, 8, TimeSpan.Parse("6:00"), 153); HybridCar hybridCar1 = new HybridCar("Volvo", "XC60 T8", DateTime.Parse("01-01-2017"), 124, 5.7, TimeSpan.Parse("3:30"), 600); HybridCar hybridCar2 = new HybridCar("Lexus", "LC500h", DateTime.Parse("01-01-2017"), 168, 4.8, TimeSpan.Parse("9:00"), 250); HybridCar hybridCar3 = new HybridCar("Toyota", "Corolla Hybrid", DateTime.Parse("01-01-2018"), 98, 8, TimeSpan.Parse("6:00"), 153); _gasCarList.AddGasCar(gasCar1); _gasCarList.AddGasCar(gasCar2); _gasCarList.AddGasCar(gasCar3); _electricCarList.AddElectricCar(electricCar1); _electricCarList.AddElectricCar(electricCar2); _electricCarList.AddElectricCar(electricCar3); _hybridCarList.AddHybridCar(hybridCar1); _hybridCarList.AddHybridCar(hybridCar2); _hybridCarList.AddHybridCar(hybridCar3); }
private void AddHybridCar() { HybridCar newHybridCar = new HybridCar(); Console.Clear(); Console.WriteLine("Manufacturer:"); newHybridCar.Manufacturer = Console.ReadLine(); Console.WriteLine("Model:"); newHybridCar.Model = Console.ReadLine(); Console.WriteLine("Year:"); string year = Console.ReadLine(); newHybridCar.YearMade = DateTime.Parse($"01/01/{year}"); Console.WriteLine("Top Speed:"); newHybridCar.TopSpeed = int.Parse(Console.ReadLine()); Console.WriteLine("Acceleration to 60mph in Seconds:"); newHybridCar.Acceleration = double.Parse(Console.ReadLine()); Console.WriteLine("Charging Time (hours:minutes):"); newHybridCar.ChargingTime = TimeSpan.Parse(Console.ReadLine()); Console.WriteLine("Nominal Range:"); newHybridCar.NominalRange = int.Parse(Console.ReadLine()); _hybridCarList.AddHybridCar(newHybridCar); Console.Clear(); Console.WriteLine($"\nYou've added a new electric car.\n" + $"Manufacturer: {newHybridCar.Manufacturer}\n" + $"Model: {newHybridCar.Model}\n" + $"Year: {newHybridCar.YearMade.Year}\n" + $"Top Speed: {newHybridCar.TopSpeed}\n" + $"Acceleration: {newHybridCar.Acceleration}\n" + $"Charging Time: {newHybridCar.ChargingTime}\n" + $"Nominal Range: {newHybridCar.NominalRange}\n"); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); }
//CREATE public void AddHybridCar(HybridCar item) { _listOfHybridCars.Add(item); }