//SRP What? static void Main(string[] args) { Dictionary<int, string> dictionary = new Dictionary<int, string>(); dictionary.Add(1, "Unicycle"); dictionary.Add(2, "Car"); dictionary.Add(3, "Motorbike"); dictionary.Add(4, "Truck"); dictionary.Add(5, "Bicycle"); Console.WriteLine("Enter 1 = unicycle, 2 = car, 3 = motorbike, 4 = truck"); int chosenValue = 0; do { string UserInput = Console.ReadLine(); chosenValue = Convert.ToInt32(UserInput); } while (chosenValue >4 || chosenValue < 1); Console.WriteLine("Hoe wil je je voertuig noemen?"); string naam = Console.ReadLine(); //IVehicle vehicle = VehicleFactory.Build(chosenValue); dictionary.TryGetValue(chosenValue, out string value); IVehicle vehicle = VehicleFactory.Build(value, naam); Console.WriteLine($"You've build a {vehicle.GetType().Name}"); Console.Read(); }
static void Main(string[] args) { int wheelCount; bool input = false; do { Console.WriteLine("Enter the amount of wheels for the vehicle you want:"); input = int.TryParse(Console.ReadLine(), out wheelCount); }while(!input); var vehicle = VehicleFactory.GetVehicle(wheelCount); vehicle.Drive(); }
static void Main(string[] args) { int wheelCount; bool input = false; do { Console.WriteLine("Enter the amount of tires for the vehicle you want to create:"); input = int.TryParse(Console.ReadLine(), out wheelCount); } while (input == false); //how do you call GetVehicle? var vehicle = VehicleFactory.GetVehicle(wheelCount); vehicle.Drive(); }
static void Main(string[] args) { VehicleFactory vehicle = new VehicleFactory(); var motorVehicle = vehicle.GetVehicle(1250); motorVehicle.Info(); motorVehicle.Move(); motorVehicle = vehicle.GetVehicle("Truck"); motorVehicle.Info(); motorVehicle.Move(); motorVehicle = vehicle.GetVehicle(100); motorVehicle.Info(); motorVehicle.Move(); Console.ReadKey(); }
static void Main(string[] args) { bool finished = true; string anotherVehicle; List <IVehicle> vehicles = new List <IVehicle>(); while (finished == true) { Console.WriteLine("What type of vehicle do you want to make? Car or Motorcycle?"); Console.WriteLine(); Console.WriteLine($"Type 1 for: Car"); Console.WriteLine($"Type 2 for: Motorcyle"); Console.WriteLine(); var userInput = int.Parse(Console.ReadLine()); if (userInput == 1) { vehicles.Add(VehicleFactory.CreateVehicle(1)); } else { vehicles.Add(VehicleFactory.CreateVehicle(2)); } for (int i = 0; i < vehicles.Count; i++) { vehicles[i].Drive(); } Console.WriteLine("Would you like to create another vehicle? Please answer 'yes' or 'no'"); anotherVehicle = Console.ReadLine().ToLower(); if (anotherVehicle == "yes") { } else { Console.WriteLine("See you next time then!"); finished = false; } } }