/// <summary> /// Lägger till en ny bil /// </summary> /// <returns>Om bilen blev inlagd eller ej</returns> private static bool AddCar() { Console.Clear(); TextColor("Ny bil:\n", ConsoleColor.White); string color, manufacturer, regno, model, owner, year; double height, length, width, weight; int maxspeed, numberofcylinders, numberofwheels; UserInput.GeneralInfo(out color, out owner, out height, out length, out width, out manufacturer, out maxspeed, out regno, out weight); model = UserInput.AskForString("Ange modell: "); year = UserInput.AskForString("Tillverkningsår: "); numberofcylinders = UserInput.AskForInt("Antal cylindrar: "); numberofwheels = UserInput.AskForInt("Antal hjul: "); Fueltypes fuelType = UserInput.AskForFueltype(); bool succeed = garage.Add(new Car(color, owner, weight, width, height, length, maxspeed, manufacturer, regno, numberofcylinders, fuelType, numberofwheels, model, year)); ShowResponse(succeed, "Bilen har lagts till", "Åtgärden misslyckades (Har du redan registrerat angivet registreringsnummer?)"); return(succeed); }
/// <summary> /// Frågar efter en bränsletyp /// </summary> /// <returns>En bränsletyp</returns> public static Fueltypes AskForFueltype() { Fueltypes fuelType = 0; bool validInput = false; do { Console.Write("Välj bränsle (G=Bensin, D=Diesel, B=Batteri): "); char ch = Console.ReadKey().KeyChar; string choice = ch.ToString().ToUpper(); // valet får inte vara case-sensitive switch (choice) { case "G": fuelType = Fueltypes.Gasoline; validInput = true; break; case "D": fuelType = Fueltypes.Diesel; validInput = true; break; case "B": fuelType = Fueltypes.Battery; validInput = true; break; default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n\nOgiltigt val, försök igen!\n"); Console.ForegroundColor = ConsoleColor.Gray; break; } } while (!validInput); return(fuelType); }
public Car(string color, string owner, double weight, double width, double height, double length, int maxspeed, string manufacturer, string regno, int numberofcylinders, Fueltypes fueltype, int numberofwheels, string model, string year, bool parked = true) : base(color, owner, weight, width, height, length, maxspeed, manufacturer, regno, parked) { this.NumberOfCylinders = numberofcylinders; this.Fueltype = fueltype; this.NumberOfWheels = numberofwheels; this.Model = model; this.Year = year; }