public ICar viewCar(CarType carType) { ICar car; switch (carType) { case CarType.HONDA: car = new Honda(); car.view(); return(car); case CarType.KIA: car = new KiA(); car.view(); return(car); case CarType.TOYOTA: car = new Toyota(); car.view(); return(car); default: car = new Honda(); car.view(); return(car); } }
static void Main(string[] args) { // Honda Honda honda = new Honda(); VehicleFactory vehicleFactoryHonda = new VehicleFactory(honda); Bike hondaBike = vehicleFactoryHonda.GetBike(); Console.WriteLine(hondaBike.BikeName); Car hondaCar = vehicleFactoryHonda.GetCar(); Console.WriteLine(hondaCar.CarName); // Mercedes Mercedes mercedes = new Mercedes(); VehicleFactory vehicleFactoryMercedes = new VehicleFactory(mercedes); Bike MercedesBike = vehicleFactoryMercedes.GetBike(); Console.WriteLine(MercedesBike.BikeName); Car MercedesCar = vehicleFactoryMercedes.GetCar(); Console.WriteLine(MercedesCar.CarName); Console.ReadLine(); }
static void Main(string[] args) { Kawasaki motor = new Kawasaki("ZX6R", "green", 2020, 85000, 280, 0.6); //Honda motor = new Honda("cbr650r", "red", 2019, 90000, 250); //Kawasaki motor2 = new Kawasaki("ZX6R", "green", 2020, 161000, 280,0.6); string priceType = GetPriceState(motor); WriteLine($"Gerçekten {priceType}"); decimal price = GetPriceWithTax(motor); WriteLine($"Motor Son Fiyatı {price}"); //string priceType2 = GetPriceState(motor2); //WriteLine($"Gerçekten {priceType2}"); Honda honda = null; Kawasaki kawasaki = new Kawasaki("ZX6R", "green", 2020, 85000, null, 0.6); Motor vehcile = honda ?? kawasaki; WriteLine("Vehcile: " + vehcile); int?maxSpeed = vehcile is Kawasaki? ((Kawasaki)vehcile).maxSpeed ?? 0 : null; // nullable value type WriteLine("Vehcile Max Speed: " + maxSpeed); }
private Vehicle CreateVehicle(XElement element) { Vehicle vehicle = null; switch (element.Name.ToString()) { case "Benz": vehicle = new Benz(); break; case "Honda": vehicle = new Honda(); break; case "Ferrari": vehicle = new Ferrari(); break; default: break; } vehicle.Name = (string)element.Element("Name"); vehicle.Text = vehicle.Name; return(vehicle); }
static void main() { int speed = GetSpeed(); var my = new Toyota(); var myOther = new Honda(); my.Drive(speed); myOther.Drive(speed); }
static void Main(string[] args) { var car = new Honda(); var model = new Model(car); var result = model.GetType().Name(); // service.BemVindo("dev team!!"); Console.WriteLine(result); }
static void ExecuteProblem2FactoryPattern() { Honda objHonda = new Honda(); objHonda.GetCarModel(); BMW objBMW = new BMW(); objBMW.GetCarModel(); // If we want to add new class then we need to modify client code also. Nano objNano = new Nano(); objNano.GetCarModel(); }
static void Main(string[] args) { Honda car = new Honda(); Console.WriteLine("Honda base price is: {0}", car.Price); SpecialOffer offer = new SpecialOffer(car); offer.DiscountPercentage = 25; offer.Offer = "25% discount"; Console.WriteLine("{1} @ Diwali Special Offer and price is : {0}", offer.Price, offer.Offer); Console.ReadKey(); }
private void RelatedCalls() { Console.WriteLine("##RELATED CALLS:" + Environment.NewLine); Console.WriteLine("*Car Factory:"); Factory <Car> carFactory = new Factory <Car>(); // Example of using interface functions. IProduct <Car> carProduct = carFactory.Create <Toyota>(); carProduct.Operate(); //carProduct.ToyotaSpecificOperation(); // Not in interface. //IProduct<Plane> planeProduct = carFactory.Create<Honda>(); // Cannot implicitly convert "Honda" to "IProduct<Plane>". //Toyota toyota = carFactory.Create<Honda>(); // Cannot implicitly convert "Honda" to "Toyota". // Example of using a product specific function. Honda honda = carFactory.Create <Honda>(); honda.Operate(); honda.HondaSpecificOperation(); Console.WriteLine(); Console.WriteLine("*Plane Factory:"); Factory <Plane> planeFactory = new Factory <Plane>(); //IProduct<Car> bad = planeFactory.Create<Boeing>(); // Cannot implicitly convert type "Boeing" to "ICarProduct". IProduct <Plane> boeing = planeFactory.Create <Boeing>(); boeing.Operate(); Console.WriteLine(); Console.WriteLine("*Car and Plane Factory:"); //carFactory.Create<Boeing>(); // "Boeing" must be convertible to "IProduct<Car>". //planeFactory.Create<Honda>(); // "Honda" must be convertible to "IProduct<Plane>". //planeFactory.Create<Toyota>(); // "Toyota" must be convertible to "IProduct<Plane>". Saab saab1 = carFactory.Create <Saab>(); saab1.Operate(); saab1.SaabSpecificOperation(); Saab saab2 = planeFactory.Create <Saab>(); saab2.Operate(); saab2.SaabSpecificOperation(); Console.WriteLine(); }
static void Main(string[] args) { Console.WriteLine("The motorcycle"); Zero Motorcycle = new Zero(); Motorcycle.MaximumOccupancy = "2"; Console.WriteLine($"Motorcycle max occupancy: {Motorcycle.MaximumOccupancy}"); Motorcycle.ChargeBattery(); Motorcycle.Drive(); Motorcycle.Stop("motorcycle"); Console.WriteLine("The Tesla"); Tesla Car = new Tesla(); Car.MaximumOccupancy = "5"; Console.WriteLine($"Car max occupancy: {Car.MaximumOccupancy}"); Car.SelfDriving = true; Console.WriteLine($"Car self driving: {Car.SelfDriving}"); Car.ChargeBattery(); Car.Drive(); Console.WriteLine("The Ram"); Ram Truck = new Ram(); Truck.MaximumOccupancy = "2"; Console.WriteLine($"Truck max occupancy: {Truck.MaximumOccupancy}"); Truck.TowCapacity = "1 ton"; Console.WriteLine($"Truck tow capacity: {Truck.TowCapacity}"); Truck.Drive(); Truck.Turn("left"); Console.WriteLine("The Plane"); Cessna Plane = new Cessna(); Plane.MaximumOccupancy = "4"; Console.WriteLine($"Plane max occupancy: {Plane.MaximumOccupancy}"); Plane.Drive(); Plane.Stop("plane"); Console.WriteLine("The CR-V"); Honda Crv = new Honda(); Crv.MaximumOccupancy = "5"; Console.WriteLine($"CRV max occupancy: {Crv.MaximumOccupancy}"); Crv.Drive(); Crv.Turn("right"); }
static void Main(string[] args) { Honda honda = null; Kawasaki kawasaki = new("ZX6R", "green", 2020, 85000, 280, 0.6); Motor vehicle = honda ?? kawasaki; //null kontrolü Console.WriteLine("Vehicle: " + vehicle); Kawasaki kawasaki2 = new("ZX6R", "green", 2020, 85000, 0, 0.6); Motor vehicle2 = honda ?? kawasaki2; int? maxSpeed = vehicle2 is Kawasaki ? ((Kawasaki)vehicle2).maxSpeed : null; // nullable value Console.WriteLine("Vehicle Max Speed: " + maxSpeed); Console.ReadKey(); }
public ICar GetCar(Brand brand) { ICar car = null; switch (brand) { case Brand.Nissan: car = new Nissan(); break; case Brand.Honda: car = new Honda(); break; default: break; } return(car); }
public void CreateSomething() { Factory <Car> carFactory = new Factory <Car>(); Honda myNewCar = carFactory.Create <Honda>(); }
public static void Run() { var honda = new Honda(); honda.Drive(100, 80); }
public static void Main() { // TESTING THE METHOD var toyota = new Toyota(); var demhamVal = new DenhamVale(); CalulateSdt(demhamVal.DistanceInMiles, toyota.SpeedMph); Console.WriteLine("Welcome To My Program"); Console.WriteLine("Please See List and pick a car for your journey: "); Toyota t = new Toyota(); t.Intro(); t.Speed(); t.Engine(); Fiat f = new Fiat(); f.Intro(); f.Speed(); f.Engine(); Honda h = new Honda(); h.Intro(); h.Speed(); h.Engine(); string input; input = Console.ReadLine(); if (string.Equals(A, input, StringComparison.CurrentCultureIgnoreCase)) { string input2; Console.WriteLine("You have chosen to drive the toyota." + Environment.NewLine + "Please pick a route: "); List <Route> Routes = new List <Route>(); Routes.Add(new CandyLane()); Routes.Add(new BostonAvenue()); Routes.Add(new DenhamVale()); foreach (Route Route in Routes) { Route.Intro(); Route.Distance(); Route.SurfaceType(); } input2 = Console.ReadLine(); if (string.Equals(D, input2, StringComparison.CurrentCultureIgnoreCase)) { string input3; Console.WriteLine("You have chosen: Candy Lane" + Environment.NewLine + "Is it raining or sunny?"); input3 = Console.ReadLine(); if (string.Equals(R, input3, StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("You have chosen Raining. + 10 minutes..."); } } else if (string.Equals(E, input2, StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("You have chosen: Boston Avenue" + Environment.NewLine + "Is it raining or sunny?"); } else if (string.Equals(F, input2, StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("You have chosen: Denham Vale" + Environment.NewLine + "Is it raining or sunny?"); } else { Console.WriteLine("This Route Doesnt Exsist"); } } else if (string.Equals(B, input, StringComparison.CurrentCultureIgnoreCase)) { string input2; Console.WriteLine("You have chosen to drive the Fiat." + Environment.NewLine + "Please pick a route: "); List <Route> Routes = new List <Route>(); Routes.Add(new CandyLane()); Routes.Add(new BostonAvenue()); Routes.Add(new DenhamVale()); foreach (Route Route in Routes) { Route.Intro(); Route.Distance(); Route.SurfaceType(); } input2 = Console.ReadLine(); if (string.Equals(D, input2, StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("You have chosen: Candy Lane" + Environment.NewLine + "Is it raining or sunny?"); } } else if (string.Equals(C, input, StringComparison.CurrentCultureIgnoreCase)) { string input2; Console.WriteLine("You have chosen to drive the Honda." + Environment.NewLine + "Please pick a route: "); List <Route> Routes = new List <Route>(); Routes.Add(new CandyLane()); Routes.Add(new BostonAvenue()); Routes.Add(new DenhamVale()); foreach (Route Route in Routes) { Route.Intro(); Route.Distance(); Route.SurfaceType(); } input2 = Console.ReadLine(); if (string.Equals(D, input2, StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine("You have chosen: Candy Lane" + Environment.NewLine + "Is it raining or sunny?"); } } }