public void CreateGarage() { bool testGarageSize = false; do { Console.WriteLine("How many Parking places should there be in the Garage?"); string input = Console.ReadLine(); int.TryParse(input, out int inputInt); if (inputInt >= 10) { int.TryParse(input, out int parkingCapacity); garage = new Garage <Vehicle>(numberOfParkingPlaces: parkingCapacity); Console.WriteLine($"A garage with {parkingCapacity} parking places are created.\n"); testGarageSize = true; } else { Console.WriteLine("Please enter a value bigger or equal to 10!"); testGarageSize = false; } } while (!testGarageSize); }
static void Main(string[] args) { int speed = 20; Console.WriteLine(); Console.WriteLine("Encapsulation"); ModelX modelx = new ModelX() { Year = 2019, Make = "Tesla", Model = "Model X", NumberOfWheels = 4, IsSuv = true, IsElectric = true }; Console.WriteLine($"{modelx.IsSuv}, ModelX class is instantiated"); Console.WriteLine(); Console.WriteLine("Inheritance"); modelx.Accelerate(speed); Console.WriteLine(); Console.WriteLine("Abstraction"); modelx.OpenFalconWingDoors(); Console.WriteLine(); Console.WriteLine("Polymorphism"); modelx.RegistrationFees(); Console.WriteLine(); Console.WriteLine("Garage"); Garage garage = new Garage(2, 0); garage.AddCar(modelx); garage.AddCar(modelx); garage.AddCar(modelx); }
public GarageHandler() { theGarage = null; }
public GarageHandler() { garage = new Garage <Vehicle>(GetCapacity()); }
public void CreateGarageWithSize(int capacity) { garage = new Garage <Vehicle>(capacity); }
public GaragHandler(int capacity) { CustomGarage = new Garage <Vehicle>(); Capacity = capacity; }
public static GarageHandler LoadGarage(string name) { var loadedGarage = Garage <Vehicle> .Load(name); return(new GarageHandler(loadedGarage)); }
public static bool GarageExists(int capacity) { return(Garage <Vehicle> .IsSaved(capacity)); }
private GarageHandler(Garage <Vehicle> garage) { Garage = garage; }
public GarageHandler(int capacity) { Garage = new Garage <Vehicle>(capacity); }
public void FinalizeCar(Garage garage) { Regex regex = new Regex(@"[^\d]"); parseInt parseint; char input = ' '; string inputs = ""; Console.WriteLine("0: Exit\n" + "1: Bus\n" + "2: Car\n" + "3: Motorcycle\n" + "4: Truck"); Vehicle newVehicle = null; //Set vehicle type based on vehicle type try { input = Console.ReadLine()[0]; } catch { input = ' '; } switch (input) { case '0': break; case '1': newVehicle = new Bus(); newVehicle.V = Vehicle.Vtype.Bus; break; case '2': newVehicle = new Car(); newVehicle.V = Vehicle.Vtype.Car; break; case '3': newVehicle = new Motorcycle(); newVehicle.V = Vehicle.Vtype.Motorcycle; break; case '4': newVehicle = new Truck(); newVehicle.V = Vehicle.Vtype.Truck; break; default: Console.WriteLine("You have to choose a vehicle type"); Console.ReadKey(false); return; } Console.WriteLine("Enter registration number: "); inputs = Console.ReadLine(); if (garage.RegNrExists(inputs)) { Console.WriteLine("Sorry, that seems to be an incorrect registration number."); Console.ReadKey(); } newVehicle.RegNr = inputs; Console.WriteLine("Enter brand: "); inputs = Console.ReadLine(); newVehicle.Brand = inputs; Console.WriteLine("Enter Model: "); inputs = Console.ReadLine(); newVehicle.Model = inputs; Console.WriteLine("Enter Color: "); inputs = Console.ReadLine(); newVehicle.Color = inputs; //Depending on type present additional options switch (newVehicle.V) { case Vehicle.Vtype.Bus: Console.WriteLine("Enter nr of seats: "); inputs = Console.ReadLine(); parseint = ParseInputToInt(regex.Replace(inputs, "")); if (parseint.success) { ((Bus)newVehicle).Seats = parseint.ret; } Console.WriteLine("Enter size: "); inputs = Console.ReadLine(); ((Bus)newVehicle).Size = inputs; break; case Vehicle.Vtype.Car: Console.WriteLine("Enter production year as number: "); inputs = Console.ReadLine(); regex = new Regex(@"[^\d]"); parseint = ParseInputToInt(regex.Replace(inputs, "")); if (parseint.success) { ((Car)newVehicle).ProdYear = parseint.ret; } break; case Vehicle.Vtype.Truck: Console.WriteLine("Enter size: "); inputs = Console.ReadLine(); ((Truck)newVehicle).Size = inputs; break; case Vehicle.Vtype.Motorcycle: parseint = ParseInputToInt(regex.Replace(inputs, "")); if (parseint.success) { ((Motorcycle)newVehicle).Class = parseint.ret; } break; default: break; } if (newVehicle != null) { garage.AddVehicle(newVehicle); Console.WriteLine(newVehicle.ToString() + "\nwas successfully added!"); Console.WriteLine("Press any key to acknowledge"); Console.ReadKey(); } }
public void CreateGarage(int capacity) { theGarage = new Garage <Vehicle>(capacity); }
private int vecount = 0;// public Garagehandler(int Size) { garage = new Garage <Vehicle>(Size); // dvs ett Garage<T> där T är typen för klassen, Vehicle parametern för konstruktorn är Size. dessutom }