private void AddGasCar() { GasCar newGasCar = new GasCar(); Console.Clear(); Console.WriteLine("Manufacturer:"); newGasCar.Manufacturer = Console.ReadLine(); Console.WriteLine("Model:"); newGasCar.Model = Console.ReadLine(); Console.WriteLine("Year:"); string year = Console.ReadLine(); newGasCar.YearMade = DateTime.Parse($"01/01/{year}"); Console.WriteLine("Top Speed:"); newGasCar.TopSpeed = int.Parse(Console.ReadLine()); Console.WriteLine("Acceleration to 60mph in Seconds:"); newGasCar.Acceleration = double.Parse(Console.ReadLine()); _gasCarList.AddGasCar(newGasCar); Console.Clear(); Console.WriteLine($"\nYou've added a new gas car.\n" + $"Manufacturer: {newGasCar.Manufacturer}\n" + $"Model: {newGasCar.Model}\n" + $"Year: {newGasCar.YearMade.Year}\n" + $"Top Speed: {newGasCar.TopSpeed}\n" + $"Acceleration: {newGasCar.Acceleration}\n"); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); }
private void UpdateGasCar() { Console.Clear(); List <GasCar> listOfGasCars = _gasCarList.GetGasCar(); Console.WriteLine("Manufacturer * Model * Year * Top Speed * Acceleration"); foreach (var item in listOfGasCars) { Console.WriteLine($"{item.Manufacturer} * {item.Model} * {item.YearMade.Year} * {item.TopSpeed} * {item.Acceleration}"); } Console.WriteLine($"\nWhich model of car would you like to update?"); string model = Console.ReadLine().ToLower(); GasCar car = _gasCarList.GetGasCarByModel(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()); _gasCarList.UpdateGasCar(model, car); Console.Clear(); Console.WriteLine($"You've added a new electric car.\n" + $"Manufacturer: {car.Manufacturer}\n" + $"Model: {car.Model}\n" + $"Year: {car.YearMade.Year}\n" + $"Top Speed: {car.TopSpeed}\n" + $"Acceleration: {car.Acceleration}\n"); Console.WriteLine($"\nPress any key to continue..."); Console.ReadKey(); }
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); }
//Delete public bool RemoveGasCar(string model) { GasCar content = GetGasCarByModel(model); if (content == null) { return(false); } int initialCount = _listOfGasCars.Count; _listOfGasCars.Remove(content); if (initialCount > _listOfGasCars.Count) { return(true); } else { return(false); } }
//UPDATE public bool UpdateGasCar(string model, GasCar newContent) { // Find the content GasCar oldContent = GetGasCarByModel(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); } }
//CREATE public void AddGasCar(GasCar item) { _listOfGasCars.Add(item); }