/// <summary> /// Add a specific car to inventory /// </summary> /// <param name="brand">Car brand</param> /// <param name="model">Car model</param> /// <param name="nbGearRatio">Number of speed on gearbox</param> /// <param name="nbDoors">Number of doors (trunk count has one)</param> /// <param name="horsePower">Motor horse power</param> /// <param name="trunk">Trunk type</param> private void AddCar(string brand, string model, int nbGearRatio, int nbDoors, int horsePower, Car.TrunkType trunk) { inventory.Add(new Car(brand, model, nbGearRatio, nbDoors, horsePower, trunk)); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Véhicule ajouté"); }
/// <summary> /// Get all car data necessary to add it in the inventory /// </summary> /// <returns>Boolean to indicate that data is ok</returns> /// <param name="brand">Car brand</param> /// <param name="model">Car model</param> /// <param name="nbGearRatio">Number of speed on gearbox</param> /// <param name="nbDoors">Number of doors (trunk count has one)</param> /// <param name="horsePower">Motor horse power</param> /// <param name="trunk">Trunk type</param> private bool GetCarDatas(out string brand, out string model, out int nbGearRatio, out int nbDoors, out int horsePower, out Car.TrunkType trunk) { bool ok = true; bool stop = false; nbGearRatio = 0; nbDoors = 0; horsePower = 0; string readData = ""; trunk = Car.TrunkType.None; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Veuillez saisir la marque de la voiture"); Console.ForegroundColor = ConsoleColor.White; brand = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Veuillez saisir le modèle de la voiture"); Console.ForegroundColor = ConsoleColor.White; model = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Veuillez saisir le nombre de vitesses"); Console.ForegroundColor = ConsoleColor.White; try { nbGearRatio = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { ok = false; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Veuillez saisir le nombre de portes"); Console.ForegroundColor = ConsoleColor.White; try { nbDoors = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { ok = false; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Veuillez saisir la puissance du véhicule"); Console.ForegroundColor = ConsoleColor.White; try { horsePower = Convert.ToInt32(Console.ReadLine()); } catch (FormatException) { ok = false; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Veuillez donner le type de coffre : 0 pas de coffre, 1 coffre ou 2 hayon"); do { Console.ForegroundColor = ConsoleColor.White; readData = Console.ReadLine(); switch (readData) { case "0": trunk = Car.TrunkType.None; stop = true; break; case "1": trunk = Car.TrunkType.Hatch; stop = true; break; case "2": trunk = Car.TrunkType.Tailgate; stop = true; break; default: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Veuillez donner un type de coffre valide : 0 pas de coffre, 1 coffre ou 2 hayon"); stop = false; break; } } while (!stop); return ok; }