public AbstractVsInterface() { //var icar = new ICar(); var car = new Volvo(); //var bike = new Bike(); }
private static ICar DeserializeVolvo(YamlMappingNode item) { var licencePlate = item.Children[new YamlScalarNode(value: "licensePlate")]?.ToString(); var rawHasAutomaticBreak = item.Children[new YamlScalarNode(value: "hasAutomaticBreak")]?.ToString(); bool.TryParse(rawHasAutomaticBreak, out var hasAutomaticBreak); var volvo = new Volvo { LicensePlate = licencePlate, HasAutomaticBreak = hasAutomaticBreak }; return(volvo); }
static void Main(string[] args) { var bmw1 = new BMW("E60", 2010, "WBSNB91010B559959", "Highend", "Lemans Red", "S85V10", 373, 250, 800000, CarType.Sedan); bmw1.Print(); bmw1.Showroom(); var bmw2 = new BMW("E60", 2010, "WBSNB91010B559969", "Medium", "Metallic Blue", "S85V10", 373, 250, 700000, CarType.Touring); bmw2.Print(); bmw2.Showroom(); bmw1.Compare(bmw2, "Car 1 and Car 2 "); bmw1.Garage(); bmw2.SimonSynes(); var mercedes1 = new Mercedes("C63 AMG", 2008, "WBSNB91010B559991", "Highend", "Hot Pink", "M156V8", 336, 250, 1200000, CarType.Touring); mercedes1.Print(); mercedes1.Showroom(); var mercedes2 = new Mercedes("E63 AMG", 2011, "WBSNB91010B559944", "Extreme", "Aquamarine", "M156V8", 540, 290, 1500000, CarType.Coupe); mercedes2.Print(); mercedes2.Showroom(); mercedes1.Compare(mercedes2, "Car 1 and Car 2 "); mercedes2.Garage(); mercedes1.Garage(); var audi1 = new Audi("RS4", 2006, "WBSNB91010B559959", "Lowend", "Military Green", "RS4V8", 253, 250, 650000, CarType.Sedan); audi1.Print(); audi1.Showroom(); var audi2 = new Audi("RS3", 2008, "WBSNB91010B559969", "Highend", "Pearlescent White", "RS3V8", 253, 250, 800000, CarType.Hatchback); audi2.Print(); audi2.Showroom(); audi1.Compare(audi2, "Car 1 and Car 2 "); audi2.Garage(); audi1.Garage(); var volvo1 = new Volvo("XC70", 2005, "WBSNB91010B559478", "Highend", "Matte Black", "D5244T17", 224, 250, 650000, CarType.SUV); volvo1.Print(); volvo1.Showroom(); var volvo2 = new Volvo("XC90", 2010, "WBSNB91010B559173", "Luxury", "Sun Yellow", "B6304T4", 224, 250, 700000, CarType.SUV); volvo2.Print(); volvo2.Showroom(); volvo1.Compare(volvo2, "Car 1 and Car 2 "); volvo2.Garage(); volvo1.GeirKjøper(); }
public void test_explicit_interface() { FourWheeler fourWheeler = new Volvo(); Car car = new Volvo(); car.Type().ShouldBe("car"); fourWheeler.Type.ShouldBe("fourwheeler"); car.Drive().ShouldBe("driving a car"); fourWheeler.Drive().ShouldBe("driving a four wheeler"); Volvo volvo = new Volvo(); volvo.Type().ShouldBe("car"); //drive method is not available for the derived class //volvo.Drive() }
static void Main(string[] args) { GarageConfigurator configurator = new GarageConfigurator(); var skoda = new Skoda(); var volvo = new Volvo(); var vw = new VW(); configurator.GarageHandler += skoda.Parking; configurator.GarageHandler += vw.Parking; configurator.GarageHandler += volvo.Parking; configurator.ParkAutomobile(); Console.WriteLine(); configurator.GarageHandler -= volvo.Parking; configurator.ParkAutomobile(); Console.ReadLine(); }
public void Update(Volvo car) { Update(car); }
public void Test1() { // Arrange var audi = new Audi { LicensePlate = Guid.NewGuid().ToString(), IsDiesel = true }; var merchant = new Person { FirstName = "Bill", LastName = "Bracket" }; var volvo = new Volvo { LicensePlate = Guid.NewGuid().ToString(), HasAutomaticBreak = true }; var ford = new Ford { LicensePlate = Guid.NewGuid().ToString(), HasSpareTire = true }; var factory = new Factory { Cars = { ford, audi, volvo }, Merchant = merchant }; // Act var serializer = new SerializerBuilder() .WithNamingConvention(new CamelCaseNamingConvention()) .EmitDefaults() .Build(); var rawFactoryYaml = serializer.Serialize(factory); var input = new StringReader(rawFactoryYaml); var yamlStream = new YamlStream(); yamlStream.Load(input); var deserializedFactory = FactorySerializer.Deserialize(yamlStream); // Assert Assert.NotNull(deserializedFactory); Assert.NotNull(deserializedFactory.Cars); Assert.Equal(deserializedFactory.Cars.Count, factory.Cars.Count); var deserializedAudi = (Audi)deserializedFactory.Cars.SingleOrDefault(car => car.Make == Make.Audi); Assert.NotNull(deserializedAudi); Assert.Equal(deserializedAudi.LicensePlate, audi.LicensePlate); Assert.Equal(deserializedAudi.IsDiesel, audi.IsDiesel); var deserializedFord = (Ford)deserializedFactory.Cars.SingleOrDefault(car => car.Make == Make.Ford); Assert.NotNull(deserializedFord); Assert.Equal(deserializedFord.LicensePlate, ford.LicensePlate); Assert.Equal(deserializedFord.HasSpareTire, ford.HasSpareTire); var deserializedVolvo = (Volvo)deserializedFactory.Cars.SingleOrDefault(car => car.Make == Make.Volvo); Assert.NotNull(deserializedVolvo); Assert.Equal(deserializedVolvo.LicensePlate, volvo.LicensePlate); Assert.Equal(deserializedVolvo.HasAutomaticBreak, volvo.HasAutomaticBreak); }
public void StartVolvo() { Vehicle v = new Volvo() { Name = "Volvo Normal", DriverName = "F", Fuel = FuelType.Petrol, Model = "V4" }; raceService.Start(v); //executing in thread Thread.Sleep(3400); raceService.GetAverageSpeed(v, 70, "00:22:04.05"); }
public static void Main() { JohnDoe johnDoe = new JohnDoe(firstName: "John", lastName: "Doe", socialSecurityNumber: "1234", email: "*****@*****.**", phoneNumber: "0745781254", salary: 600000); customerList.Add(johnDoe); Tesla teslaX = new Tesla(id: 0, brand: "Tesla", model: "X", color: "Red", licensePlate: "1234", price: 500000, year: 2015); carList.Add(teslaX); Tesla teslaRoadster = new Tesla(id: 1, brand: "Tesla", model: "Roadster", color: "Red", licensePlate: "1234", price: 1000000, year: 2020); carList.Add(teslaRoadster); Volvo volvoV40 = new Volvo(id: 2, brand: "Volvo", model: "V40", color: "Black", licensePlate: "4321", price: 600000, year: 2019); carList.Add(volvoV40); Ceo ceo = new Ceo(firstName: "Ceo", lastName: "Ceo", socialSecurityNumber: "19801205-1234", email: "*****@*****.**", phoneNumber: "072132132", salary: 300000, position: "CEO"); staffList.Add(ceo); bool shouldRun = true; while (shouldRun) { Clear(); WriteLine("1. List staffs"); WriteLine("2. List customers"); WriteLine("3. List cars"); WriteLine("4. Buy car"); WriteLine("5. Exit"); ConsoleKeyInfo keyPressed = ReadKey(true); Clear(); switch (keyPressed.Key) { case ConsoleKey.D1: foreach (var staff in staffList) { if (staff == null) { continue; } WriteLine("Position | Firstname | Lastname | SocialSecurityNumber"); WriteLine("---------------------------------------------------------"); WriteLine($"{staff.Position} {staff.FirstName} {staff.LastName} {staff.SocialSecurityNumber}"); ReadKey(); } break; case ConsoleKey.D2: foreach (var customer in customerList) { if (customer == null) { continue; } WriteLine("Firstname | Lastname | SocialSecurityNumber"); WriteLine("---------------------------------------------"); WriteLine($"{customer.FirstName} {customer.LastName} {customer.SocialSecurityNumber}"); ReadKey(); } break; case ConsoleKey.D3: foreach (var car in carList) { if (car == null) { continue; } WriteLine("Year | Brand | Model | License Plate | Price"); WriteLine("-------------------------------------------------"); WriteLine($"{car.Year} {car.Brand} {car.Model} {car.LicensePlate} {car.Price}"); ReadKey(); } break; case ConsoleKey.D4: WriteLine("Please enter your Social Security Number:"); SetCursorPosition(41, 0); string socialSecurityNumber = ReadLine(); foreach (var cust in customerList) { foreach (var staff in staffList) { if (cust.SocialSecurityNumber == socialSecurityNumber) { Clear(); WriteLine($"Hello {cust.FirstName} {cust.LastName}"); WriteLine($"Im {staff.FirstName} {staff.LastName} and I'm here to help you with your purchase!"); WriteLine(); WriteLine("Please enter the license plate number:"); SetCursorPosition(38, 3); string licensePlate = ReadLine(); foreach (var cars in carList) { if (cars == null) { continue; } if (cars.LicensePlate == licensePlate) { Clear(); WriteLine($"Congrats you just bought a {cars.Brand} {cars.Model}"); carList.RemoveAt(0); Thread.Sleep(2000); break; } else { Clear(); WriteLine("No vehicle got that license plate number"); Thread.Sleep(2000); break; } } } else { Clear(); WriteLine("Wrong Social Security Number / Customer dosen't exist"); Thread.Sleep(2000); break; } } } break; case ConsoleKey.D5: shouldRun = false; break; } } }