static void Main(string[] args) { Vehicle BasicVehicle = new Vehicle(); BasicVehicle.Move(); AirVehicle Helicopter = new AirVehicle(); Helicopter.Move(); WaterVehicle Boat = new WaterVehicle(); Boat.Move(); LandVehicle Tank = new LandVehicle(); Tank.Move(); Weapon BasicWeapon = new Weapon(); BasicWeapon.Shoot(); SmallCaliberWeapon M9 = new SmallCaliberWeapon(); M9.Shoot(); IndirectFireWeapon M203 = new IndirectFireWeapon(); M203.Shoot(); DirectFireWeapon M82 = new DirectFireWeapon(); M82.Shoot(); }
static void Main(string[] args) { LandVehicle myCar = new LandVehicle(); myCar.maker = "Toyota"; myCar.model = "Corolla"; myCar.year = "2015"; myCar.numDoors = 4; Person me = new Person(); me.name = "Cary"; Person passenger1 = new Person(); passenger1.name = "William Shakespeare"; Person passenger2 = new Person(); passenger2.name = "Elvis Presley"; Trip myTrip = new Trip(); myTrip.startLocation = "Los Angeles"; myTrip.endLocation = "Toronto"; myTrip.driver = me; myTrip.passengerList.Add(passenger1); myTrip.passengerList.Add(passenger2); myTrip.vehicle = myCar; string outputStr = string.Format("{0} is taking a trip from {1} to {2} in his {3} {4} {5}." , myTrip.driver.name, myTrip.startLocation, myTrip.endLocation, myTrip.vehicle.year, myTrip.vehicle.maker, myTrip.vehicle.model); Console.WriteLine(outputStr); Console.ReadKey(); }
private void SkapaMC() { LandVehicle temp = SkapaLandVehicle("Motorcycle", 2); Console.WriteLine("Input brand:"); string brand = Console.ReadLine(); Console.WriteLine("Input category of bike:"); string cat = Console.ReadLine(); garage.Add(new Motorcycle(temp.REG_NR, temp.Color, temp.NumberofWheels, temp.ConstructionYear, temp.Mileage, temp.LicenseRequirement, brand, cat)); SetToMainMenu(); }
static void Main(string[] args) { //LandVehicle myCar = new LandVehicle(); //myCar.maker = "Toyota"; //myCar.model = "Corolla"; //myCar.year = 2015; //myCar.topSpeed = 80; //myCar.color = "green"; //myCar.numWheels = 4; LandVehicle myCar = new LandVehicle("Toyota", "Corolla", 2015); Person driver = new Person(); driver.Name = "Cary Baer"; Person passenger1 = new Person(); passenger1.Name = "Drake"; Person passenger2 = new Person(); passenger2.Name = "Madonna"; Trip myTrip = new Trip(); myTrip.vehicle = myCar; myTrip.driver = driver; myTrip.passengerList.Add(passenger1); myTrip.passengerList.Add(passenger2); myTrip.startLocation = "Los Angeles"; myTrip.endLocation = "Connecticut"; //string outString = myTrip.driver.Name + " is taking a trip from " + myTrip.startLocation + " to " + myTrip.endLocation + " in his " + myTrip.vehicle.model + "."; string outString = string.Format("{0} is taking a trip from {1} to {2} in his {3}.", myTrip.driver.Name, myTrip.startLocation, myTrip.endLocation, myTrip.vehicle.model); Console.WriteLine(outString); foreach (Person p in myTrip.passengerList) { Console.WriteLine(p.Name); } Console.ReadKey(); }
private void SkapaBil() { LandVehicle temp = SkapaLandVehicle("Car", 4); Console.WriteLine("Input baggage volume:"); double bagvol = 0; while (double.TryParse(Console.ReadLine(), out bagvol)) { Console.SetCursorPosition(0, Console.CursorTop - 1); Console.WriteLine("Input a double!"); } Console.WriteLine("Input fuel type:"); string fuel = Console.ReadLine(); garage.Add(new Car(temp.REG_NR, temp.Color, temp.NumberofWheels, temp.ConstructionYear, temp.Mileage, temp.LicenseRequirement, bagvol, fuel)); SetToMainMenu(); }
private void SkapaBuss() { LandVehicle temp = SkapaLandVehicle("Buss", 8); Console.WriteLine("Input number of seats:"); int noseats = 0; while (!int.TryParse(Console.ReadLine(), out noseats)) { Console.SetCursorPosition(0, Console.CursorTop - 1); Console.WriteLine("Input an integer!"); } Console.WriteLine("Input line number:"); int line = 0; while (!int.TryParse(Console.ReadLine(), out line)) { Console.SetCursorPosition(0, Console.CursorTop - 1); Console.WriteLine("Input an integer!"); } garage.Add(new Buss(temp.REG_NR, temp.Color, temp.NumberofWheels, temp.ConstructionYear, temp.Mileage, temp.LicenseRequirement, noseats, line)); SetToMainMenu(); }
static void Main(string[] args) { LandVehicle myCar = new LandVehicle(); Person me = new Person(); Person passenger1 = new Person(); Person passenger2 = new Person(); Trip myTrip = new Trip(); myCar.maker = "Toyota"; myCar.model = "Corolla"; me.name = "Cary Baer"; passenger1.name = "John Smith"; passenger2.name = "Jane Doe"; myTrip.vehicle = myCar; myTrip.controller = me; myTrip.startLocation = "Los Angeles"; myTrip.endLocation = "Houston"; myTrip.passengerList.Add(passenger1); myTrip.passengerList.Add(passenger2); Console.Write(me.name + " is taking the " + myCar.maker + " " + myCar.model + " on a trip from " + myTrip.startLocation + " to " + myTrip.endLocation + ".\r\n"); string passengerList = string.Empty; foreach (Person p in myTrip.passengerList) { passengerList = passengerList + p.name + "\r\n"; } Console.Write("These passengers also going: \r\n" + passengerList); Console.ReadKey(); }
static void MyTripMethod2() { LandVehicle myCar = new LandVehicle("Toyota", "Corolla", "2015", "White"); Person me = new Person("Cary Baer"); Trip myTrip = new Trip("Los Angeles", "Toronto", myCar, me); myTrip.passengerList.Add(new Person("William Shakespeare")); myTrip.passengerList.Add(new Person("Captain Kirk")); string outputStr = string.Format("{0} is taking a trip from {1} to {2} in his {3} {4} {5} {6}." , myTrip.driver.name, myTrip.startLocation, myTrip.endLocation, myTrip.vehicle.year, (myTrip.vehicle as LandVehicle).Color, myTrip.vehicle.maker, myTrip.vehicle.model); Console.WriteLine(outputStr); Console.WriteLine("Also going on the trip are:"); foreach (Person p in myTrip.passengerList) { Console.WriteLine(p.name); } Console.ReadKey(); }
static void Main(string[] args) { var airplane = new AirVehicle { Wheels = 10, Doors = 9, PassengerCapacity = 50, Winged = true, MaxAirSpeed = 500 }; var cessna = new AirVehicle { Wheels = 3, Doors = 3, PassengerCapacity = 2, Winged = true, MaxAirSpeed = 300, MaxWaterSpeed = 200 }; var motorcycle = new LandVehicle { Wheels = 2, PassengerCapacity = 2, MaxLandSpeed = 150, }; var bus = new LandVehicle { Wheels = 6, Doors = 4, PassengerCapacity = 50, MaxLandSpeed = 80, TransmissionType = "automatic", }; var jetski = new WaterVehicle { PassengerCapacity = 2, MaxWaterSpeed = 60, }; var yacht = new WaterVehicle { Doors = 25, PassengerCapacity = 100, TransmissionType = "manual", MaxWaterSpeed = 100, EngineVolume = 50 }; // Build a collection of all vehicles that operate on water var airVehicles = new List <AirVehicle>(); airVehicles.Add(airplane); airVehicles.Add(cessna); // Build a collection of all vehicles that operate on roads var landVehicles = new List <LandVehicle>(); landVehicles.Add(motorcycle); landVehicles.Add(bus); // Build a collection of all vehicles that fly var waterVehicles = new List <WaterVehicle>(); waterVehicles.Add(jetski); waterVehicles.Add(yacht); // With a single `foreach`, have each water vehicle Drive() foreach (var waterThing in waterVehicles) { waterThing.Start(); waterThing.Drive(); } // With a single `foreach`, have each vehicle Fly() foreach (var airThing in airVehicles) { airThing.Start(); airThing.Fly(); } // With a single `foreach`, have each road vehicle Drive() foreach (var landThing in landVehicles) { landThing.Start(); landThing.Drive(); } Console.ReadLine(); }
static void Main(string[] args) { var jumbojet = new AirVehicle { Name = "747", Wheels = 3, Doors = 4, PassengerCapacity = 200, Winged = true, MaxAirSpeed = 300 }; var airforceone = new AirVehicle { Name = "Air Force One", Wheels = 3, Doors = 4, PassengerCapacity = 20, Winged = true, MaxAirSpeed = 400 }; var ferrari = new LandVehicle { Name = "Ferrari", Wheels = 4, Doors = 2, PassengerCapacity = 2, TransmissionType = "Manual", MaxLandSpeed = 120 }; var minivan = new LandVehicle { Name = "Mini Van", Wheels = 4, Doors = 4, PassengerCapacity = 7, TransmissionType = "Auotmatic", MaxLandSpeed = 50 }; var jetski = new WaterVehicle { Name = "Jetski", PassengerCapacity = 2, MaxWaterSpeed = 60.2 }; var speedboat = new WaterVehicle { Name = "Speedboat", PassengerCapacity = 6, MaxWaterSpeed = 86.3 }; // Build a collection of all vehicles that fly var flyingthings = new List <AirVehicle>(); flyingthings.Add(jumbojet); flyingthings.Add(airforceone); // With a single `foreach`, have each vehicle Fly() foreach (var aircraft in flyingthings) { aircraft.Fly(); } // Build a collection of all vehicles that operate on roads var landvehicles = new List <LandVehicle>(); landvehicles.Add(ferrari); landvehicles.Add(minivan); // With a single `foreach`, have each road vehicle Drive() foreach (var car in landvehicles) { car.Drive(); } // Build a collection of all vehicles that operate on water var watervehicles = new List <WaterVehicle>(); watervehicles.Add(jetski); watervehicles.Add(speedboat); // With a single `foreach`, have each water vehicle Drive() foreach (var vehicle in watervehicles) { vehicle.Drive(); } Console.ReadLine(); }
private void SparaTillDisk() { var document = new XDocument(); var allagarage = new XElement("Garages"); foreach (var gar in garages) { var garra = new XElement("Garage"); garra.Add(new XAttribute("Name", gar.Name)); garra.Add(new XAttribute("Capacity", gar.Max)); foreach (var vehicle in gar) { var reg = new XElement("REG_NR", vehicle.REG_NR); var col = new XElement("Color", vehicle.Color); var nowhels = new XElement("NumberofWheels", vehicle.NumberofWheels); var conyear = new XElement("ConstructionYear", vehicle.ConstructionYear); if (vehicle is LandVehicle) { LandVehicle landvehicle = vehicle as LandVehicle; var mil = new XElement("Mileage", landvehicle.Mileage); var lic = new XElement("LicenseRequirement", landvehicle.LicenseRequirement); if (vehicle is Buss) { Buss buss = vehicle as Buss; var noseats = new XElement("NumberofSeats", buss.NumberofSeats); var line = new XElement("Line", buss.Line); garra.Add(new XElement(vehicle.Type, reg, col, nowhels, conyear, mil, lic, noseats, line)); } else if (vehicle is Car) { Car car = vehicle as Car; var bagvol = new XElement("BaggageVolume", car.BaggageVolume); var fuel = new XElement("FuelType", car.FuelType); garra.Add(new XElement(vehicle.Type, reg, col, nowhels, conyear, mil, lic, bagvol, fuel)); } else if (vehicle is Motorcycle) { Motorcycle motorcycle = vehicle as Motorcycle; var brand = new XElement("Brand", motorcycle.Brand); var cat = new XElement("Category", motorcycle.Category); garra.Add(new XElement(vehicle.Type, reg, col, nowhels, conyear, mil, lic, brand, cat)); } } else if (vehicle is Boat) { Boat boat = vehicle as Boat; var buoy = new XElement("Buoyancy", boat.Buoyancy); var len = new XElement("Length", boat.Length); garra.Add(new XElement(vehicle.Type, reg, col, nowhels, conyear, buoy, len)); } else if (vehicle is Airplane) { Airplane airplane = vehicle as Airplane; var max = new XElement("MaxAltitude", airplane.MaxAltitude); var line = new XElement("AirLine", airplane.AirLine); garra.Add(new XElement(vehicle.Type, reg, col, nowhels, conyear, max, line)); } } allagarage.Add(garra); } document.Add(allagarage); document.Save("vehicles.xml"); }