public void AddMotorcycle() { var vehicles = AddVehicle(); ui.Print("Cylinder Volume?"); double cylinderVolume = int.Parse(ui.GetInput()); var motorCycle = new MotorCycle(vehicles.RegNumber, vehicles.Color, vehicles.NrOfWheels, cylinderVolume); garageHandler.garage.Add(motorCycle); }
public void Populate() { Car c1 = new Car("SE147", "Tesla", "Black", 4, "EL"); Car c2 = new Car("FR145", "Tesla", "Beige", 4, "Diesel"); MotorCycle mt1 = new MotorCycle("XN221", "Suzuki", "Black", 2, 250); MotorCycle mt2 = new MotorCycle("XBG21", "Yamaha", "Black", 2, 1200); Boat b1 = new Boat("DR458", "Boston Whaler ", "White", 3, 8); Airplane air1 = new Airplane("CZF159", "Cessna", "White", 3, 4, 8); Airplane air2 = new Airplane("CZFK9", "Yamaha", "White", 3, 4, 8); Bus bus1 = new Bus("FZE126", "Volvo", "Red", 6, 50, 11); if (handler.garage.IsFull == false) { handler.garage.Add(c1); handler.garage.Add(c2); handler.garage.Add(mt1); //handler.garage.Add(mt2); handler.garage.Add(b1); //handler.garage.Add(air2); //handler.garage.Add(air1); //handler.garage.Add(bus1); } string strResultJson = JsonConvert.SerializeObject(handler.garage.GetEnumerator()); Console.WriteLine(strResultJson); File.WriteAllText(@"Garage.json", strResultJson); ui.Print("Stored"); strResultJson = String.Empty; strResultJson = File.ReadAllText(@"garage.json"); //jag kunde inte parsa Garage klassen jag fick error . var des = (Vehicule)Newtonsoft.Json.JsonConvert.DeserializeObject(strResultJson, typeof(Vehicule)); var resultGarage = des.ToString(); //var des2 = JsonConvert.DeserializeObject(strResultJson, typeof(Garage<Vehicule>)); //var resultGarage2 = des2.ToString(); var dictionary = JsonConvert.DeserializeObject <IDictionary>(strResultJson); foreach (DictionaryEntry entry in dictionary) { ui.Print(entry.Key + ":" + entry.Value); } }
private void AddMoto() { string regs3 = Extensions.AskForString("Registernummer", ui); bool has = garage.Any(ve => ve.RegisterNummer.EqualsInsensitive(regs3)); if (has) { ui.Print("vehicule exists already with that registernumber"); return; } string brand3 = Extensions.AskForString("Brand", ui); string color3 = Extensions.AskForString("Color", ui); int wheels3 = Extensions.AskForInt("Wheels", ui); int cylinder = Extensions.AskForInt("Cylinder Volume", ui); var motor = new MotorCycle(regs3, brand3, color3, wheels3, cylinder); garage.Add(motor); ui.Print($"You add a new Motocycle"); }