static void Main(string[] args) { Zero fxs = new Zero(); Zero fx = new Zero(); Tesla modelS = new Tesla(); List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>() { fx, fxs, modelS }; Console.WriteLine("------------------------"); Console.WriteLine("Electric Vehicles"); foreach (IElectricVehicle ev in electricVehicles) { Console.WriteLine($"The Vehivle is {ev.CurrentChargePercentage}% charged"); } foreach (IElectricVehicle ev in electricVehicles) { // This should charge the vehicle to 100% ev.ChargeBattery(); } foreach (IElectricVehicle ev in electricVehicles) { Console.WriteLine($"The vehicle is now {ev.CurrentChargePercentage}% charged!"); } /***********************************************/ Ram ram = new Ram(); Cessna cessna150 = new Cessna(); List <IGasVehicle> gasVehicles = new List <IGasVehicle>() { ram, cessna150 }; Console.WriteLine("------------------------"); Console.WriteLine("Gas Vehicles"); foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"The tank is {gv.CurrentTankPercentage}% full"); } foreach (IGasVehicle gv in gasVehicles) { // This should completely refuel the gas tank gv.RefuelTank(); } foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"The tank is now {gv.CurrentTankPercentage}% full!"); } }
static void Main(string[] args) { /* * Create some electric vehicles, add them to a List * and then iterate the List to charge all of their * batteries. */ Zero fxs = new Zero(); Zero fx = new Zero(); Tesla modelS = new Tesla(); // List<IElectricPowered> electricVehicles = new List<IElectricPowered>() // { // fx, // fxs, // modelS // }; /* * This can only hold individual motorcycles. You can't * add the Tesla to this list. It's a different type. * This is invalid code. The `modelS` is not of type Zero. */ // this is the old code that wont allow separate classes in one list // List<Zero> electricVehicles = new List<Zero>() { fx, fxs, modelS }; List <IElectricPowered> electricVehicles = new List <IElectricPowered>(); electricVehicles.Add(fx); electricVehicles.Add(fxs); electricVehicles.Add(modelS); Console.WriteLine($" {electricVehicles}"); electricVehicles.ForEach(ev => ev.ChargeBattery()); /* * Create some gas vehicles, add them to a List * and then iterate the List to fill all of their * fuel tanks. */ Ram ram = new Ram(); Cessna cessna150 = new Cessna(); List <IGasPowered> gasVehicles = new List <IGasPowered>(); gasVehicles.Add(ram); gasVehicles.Add(cessna150); // ram, // cessna150 gasVehicles.ForEach(gv => gv.RefuelTank()); }
static void Main(string[] args) { Zero fxs = new Zero(); Zero fx = new Zero(); Tesla modelS = new Tesla(); List <ICharging> electricVehicles = new List <ICharging>() { fx, fxs, modelS }; Console.WriteLine("Electric Vehicles"); // foreach (ICharging ev in electricVehicles) // { // Console.WriteLine($"{ev.CurrentChargePercentage}"); // } foreach (ICharging ev in electricVehicles) { // This should charge the vehicle to 100% ev.ChargeBattery(); } // foreach (ICharging ev in electricVehicles) // { // Console.WriteLine($"{ev.CurrentChargePercentage}"); // } /***********************************************/ Ram ram = new Ram(); Cessna cessna150 = new Cessna(); List <IGassinUp> gasVehicles = new List <IGassinUp>() { ram, cessna150 }; Console.WriteLine("Gas Vehicles"); // foreach (IGassinUp gv in gasVehicles) // { // Console.WriteLine($"{gv.CurrentTankPercentage}"); // } foreach (IGassinUp gv in gasVehicles) { // This should completely refuel the gas tank gv.RefuelTank(); } // foreach (IGassinUp gv in gasVehicles) // { // Console.WriteLine($"{gv.CurrentTankPercentage}"); // } }
static void Main(string[] args) { // Move all common properties in your vehicles to a new Vehicle class. // Create an instance of each vehicle. // Define a different value for each vehicle's properties. // Create a Drive() method in the Vehicle class. // Override the Drive() method in all the other vehicle classes. Include the vehicle's color in the message (i.e. "The blue Ram drives past. RRrrrrrummbbble!"). Ram ram = new Ram("Sunset Blue", 19.13, 7); Tesla tesla = new Tesla("Toilet Water Gray", 78.0, 8); ram.Drive(); tesla.Drive(); tesla.Stop(); tesla.Turn(); Console.WriteLine(); }
static void Main(string[] args) { Zero fxs = new Zero(); Zero fx = new Zero(); Tesla modelS = new Tesla(); List <IElectricPowered> electricVehicles = new List <IElectricPowered>(); electricVehicles.Add(fx); electricVehicles.Add(fxs); electricVehicles.Add(modelS); Ram ram = new Ram(); Cessna cessna150 = new Cessna(); List <IGasPowered> gasVehicles = new List <IGasPowered>() { ram, cessna150 }; gasVehicles.ForEach(gv => gv.RefuelTank()); electricVehicles.ForEach(ev => ev.ChargeBattery()); }
static void Main(string[] args) { Zero fxs = new Zero(); Tesla modelS = new Tesla(); Cessna mx410 = new Cessna(); Ram bigTruck = new Ram(); fxs.MainColor = "red"; fxs.MaximumOccupancy = "4"; modelS.MainColor = "grey"; modelS.MaximumOccupancy = "5"; mx410.MainColor = "white"; mx410.MaximumOccupancy = "2"; bigTruck.MainColor = "blue"; bigTruck.MaximumOccupancy = "3"; fxs.Drive(); fxs.Turn("right"); fxs.Stop(); Console.WriteLine(" "); modelS.Drive(); modelS.Turn("left"); modelS.Stop(); Console.WriteLine(" "); mx410.Drive(); mx410.Turn("right"); mx410.Stop(); Console.WriteLine(" "); bigTruck.Drive(); bigTruck.Turn("left"); bigTruck.Stop(); Console.WriteLine(" "); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Tesla mkz = new Tesla(); VolksWagen Arteon = new VolksWagen(); LandRover Defender = new LandRover(); mkz.MainColor = "White"; Arteon.MainColor = "Kurkuma Yellow"; Defender.MainColor = "Smoke Grey"; Arteon.Drive(); Arteon.Turn(); Arteon.Stop(); Console.WriteLine(); mkz.Drive(); mkz.Turn(); mkz.Stop(); Console.WriteLine(); Defender.Drive(); Defender.Turn(); Defender.Stop(); }
static void Main(string[] args) { /* INHERITANCE */ Zero fxs = new Zero() { MainColor = "Red" }; Tesla modelS = new Tesla() { MainColor = "Black" }; Cessna mx410 = new Cessna() { MainColor = "White" }; Ram fifteenHundred = new Ram() { MainColor = "Blue" }; fxs.Drive(); fxs.Turn("left"); fxs.Stop(); modelS.Drive(); modelS.Turn("left"); modelS.Stop(); mx410.Drive(); mx410.Turn("right"); mx410.Stop(); fifteenHundred.Drive(); fifteenHundred.Turn("right"); fifteenHundred.Stop(); /***********************************************/ /* INTERFACE */ Zero sr = new Zero() { CurrentChargePercentage = "67%" }; Zero ds = new Zero() { CurrentChargePercentage = "42%" }; Tesla modelX = new Tesla() { CurrentChargePercentage = "86%" }; List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>() { sr, ds, modelX }; Console.WriteLine("Electric Vehicles"); foreach (IElectricVehicle ev in electricVehicles) { Console.WriteLine($"{ev.CurrentChargePercentage}"); } foreach (IElectricVehicle ev in electricVehicles) { // This should charge the vehicle to 100% ev.ChargeBattery(); } foreach (IElectricVehicle ev in electricVehicles) { Console.WriteLine($"{ev.CurrentChargePercentage}"); } /***********************************************/ Ram ram = new Ram() { CurrentTankPercentage = "32%" }; Cessna cessna150 = new Cessna() { CurrentTankPercentage = "50%" }; List <IGasVehicle> gasVehicles = new List <IGasVehicle>() { ram, cessna150 }; Console.WriteLine("Gas Vehicles"); foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage}"); } foreach (IGasVehicle gv in gasVehicles) { // This should completely refuel the gas tank gv.RefuelTank(); } foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage}"); } }
static void Main(string[] args) { // Electric Powered Rides Zero fx = new Zero(); Tesla modelS = new Tesla(); // List of electric vehicles List <ElectricVehicle> electricVehicles = new List <ElectricVehicle>() { fx, modelS }; electricVehicles.ForEach(ev => ev.ChargeBattery()); // Gas Powered Rides //(fuelCap, gasLev) Cessna myCessna = new Cessna(120, 50); Ram myRam = new Ram(10, 3); Console.WriteLine($"The Ram is entering the fueling station with {myRam.gasLevel} gallons in the tank"); Console.WriteLine($"The Cessna is entering the fueling station {myCessna.gasLevel} gallons in the tank"); // List of gas vehicles List <GasVehicle> gasVehicles = new List <GasVehicle>() { myCessna, myRam }; // Battery station instance BatteryStation batteryStation = new BatteryStation(); // Gas station instance and pass the new instance capacity at the gas station GasStation gasStation = new GasStation(3); // refuel all gas vehicles as the gas station if there is room. Capacity is (3)--see line 37 if (gasStation.Refuel(gasVehicles) != null) { Console.WriteLine("Lets Fuel Em Up!"); } else { Console.WriteLine("Too many vehicles, get the hell out!"); } Console.WriteLine($"The Ram is leaving the fueling station with {myRam.gasLevel} gallons in the tank. Ahhh, a full tank!"); Console.WriteLine($"The Ram is leaving the fueling station with {myCessna.gasLevel} gallons in the tank. Ahhh, a full tank!"); // Output // System.Console.WriteLine("-------------"); // myRam.Drive(); // myRam.Turn("left"); // myRam.Stop(); // System.Console.WriteLine("-------------"); // myCessna.Drive(); // myCessna.Turn("right"); // myCessna.Stop(); // System.Console.WriteLine("-------------"); // fx.Drive(); // fx.Turn("right"); // fx.Stop(); // System.Console.WriteLine("-------------"); // modelS.Drive(); // modelS.Turn("left"); // modelS.Stop(); // System.Console.WriteLine("-------------"); }
static void Main(string[] args) { Zero fxs = new Zero(); // Tesla modelS = new Tesla(); Cessna mx410 = new Cessna(); Tesla electric = new Tesla() { Name = "Fancy Tesla", BatteryKWh = 200.00, MainColor = "red", MaximumOccupancy = "4", CurrentChargePercentage = 15.0 }; Cessna sedan = new Cessna() { Name = "Cessna Sedan", MainColor = "green", MaximumOccupancy = "6", FuelCapacity = 18.50, CurrentTankPercentage = 25, }; List <IElectric> electricVehicles = new List <IElectric>() { electric }; Console.WriteLine("Electric Vehicles List:"); foreach (IElectric ev in electricVehicles) { Console.WriteLine($"{ev.Name}"); Console.WriteLine($"Battery level before charge was at {ev.CurrentChargePercentage}%"); } foreach (IElectric ev in electricVehicles) { // This should charge the vehicle to 100% ev.ChargeBattery(); break; } foreach (IElectric ev in electricVehicles) { Console.WriteLine($"After Charge: {ev.CurrentChargePercentage}%"); } Console.WriteLine("/***********************************************/"); // Ram ram = new Ram(); // Cessna cessna150 = new Cessna(); List <IGasVehicle> gasVehicles = new List <IGasVehicle>() { sedan, }; Console.WriteLine("Gas Vehicles List :"); foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"{gv.Name}"); Console.WriteLine($"Should we fill up? Tank level:{gv.CurrentTankPercentage}%"); } foreach (IGasVehicle gv in gasVehicles) { // This should completely refuel the gas tank gv.RefuelTank(); Console.WriteLine($"We got gas"); } foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage}"); } }
static void Main(string[] args) { //instanstiating new classes Zero fxs = new Zero(); fxs.BatteryKwh = 300.00; fxs.CurrentChargePercentage = 20; Zero fx = new Zero(); fx.BatteryKwh = 100.00; fx.CurrentChargePercentage = 50; Tesla modelS = new Tesla(); modelS.BatteryKwh = 60; modelS.CurrentChargePercentage = 30; List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>() { fx, fxs, modelS }; Console.WriteLine("Electric Vehicles"); foreach (IElectricVehicle ev in electricVehicles) { Console.WriteLine($"{ev.CurrentChargePercentage}"); } //iterating through the list of electric vehicles foreach (IElectricVehicle ev in electricVehicles) { // This should charge the vehicle to 100% ev.ChargeBattery(); } foreach (IElectricVehicle ev in electricVehicles) { Console.WriteLine($"{ev.CurrentChargePercentage}"); } /***********************************************/ Ram ram = new Ram(); ram.FuelCapacity = 60.20; ram.CurrentTankPercentage = 70; Cessna cessna150 = new Cessna(); cessna150.FuelCapacity = 90.21; cessna150.CurrentTankPercentage = 20; List <IGasVehicle> gasVehicles = new List <IGasVehicle>() { ram, cessna150 }; Console.WriteLine("Gas Vehicles"); foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage}"); } foreach (IGasVehicle gv in gasVehicles) { // This should completely refuel the gas tank gv.RefuelTank(); } foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage}"); } }
static void Main(string[] args) { Zero fxs = new Zero() { MainColor = "Chartreuse", MaximumOccupancy = "1-2 bodies.", CurrentBatteryKWh = 0.70 }; Zero fx = new Zero() { MainColor = "Dark Salmon", MaximumOccupancy = "1-2 bodies", CurrentBatteryKWh = 0.80 }; Tesla modelS = new Tesla() { MainColor = "Tan", MaximumOccupancy = "5 bodies", CurrentBatteryKWh = 0.89 }; List <IBatteryPowered> electricVehicles = new List <IBatteryPowered>() { fx, fxs, modelS }; Console.WriteLine("Electric Vehicles"); foreach (IBatteryPowered ev in electricVehicles) { Console.WriteLine($"{ev.CurrentChargePercentage()}"); } foreach (IBatteryPowered ev in electricVehicles) { // This should charge the vehicle to 100% ev.ChargeBattery(); } Console.WriteLine(""); foreach (IBatteryPowered ev in electricVehicles) { Console.WriteLine($"{ev.CurrentChargePercentage()}"); } Console.WriteLine(""); /***********************************************/ Ram ram = new Ram() { MainColor = "Cadet Blue", MaximumOccupancy = "3 bodies", CurrentFuel = 0.40 }; Cessna cessna150 = new Cessna() { MainColor = "Light Cyan", MaximumOccupancy = "8 bodies", CurrentFuel = 0.42 }; List <IGasPowered> gasVehicles = new List <IGasPowered>() { ram, cessna150 }; Console.WriteLine("Gas Vehicles"); foreach (IGasPowered gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage()}"); } foreach (IGasPowered gv in gasVehicles) { // This should completely refuel the gas tank gv.RefuelTank(); } Console.WriteLine(""); foreach (IGasPowered gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage()}"); } }
static void Main(string[] args) { Tesla car = new Tesla() { MainColor = "black", MaximumOccupancy = "20", BatteryKWh = 10.0 }; Zero motorcycle = new Zero() { MainColor = "black", MaximumOccupancy = "20", BatteryKWh = 15.0 }; List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>() { motorcycle, car }; Console.WriteLine("Electric Vehicles"); foreach (IElectricVehicle ev in electricVehicles) { Console.WriteLine($"{ev.CurrentChargePercentage:N2}"); } foreach (IElectricVehicle ev in electricVehicles) { // This should charge the vehicle to 100% ev.ChargeBattery(); } foreach (IElectricVehicle ev in electricVehicles) { Console.WriteLine($"{ev.CurrentChargePercentage:N2}"); } /***********************************************/ Cessna plane = new Cessna() { MainColor = "blue", MaximumOccupancy = "6", FuelCapacity = 30.0 }; Ram truck = new Ram() { MainColor = "red", MaximumOccupancy = "20", FuelCapacity = 20.0 }; List <IGasVehicle> gasVehicles = new List <IGasVehicle>() { truck, plane }; Console.WriteLine("Gas Vehicles"); foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage:N2}"); } foreach (IGasVehicle gv in gasVehicles) { // This should completely refuel the gas tank gv.RefuelTank(); } foreach (IGasVehicle gv in gasVehicles) { Console.WriteLine($"{gv.CurrentTankPercentage:N2}"); } }
static void Main(string[] args) { Zero fxs = new Zero() { MainColor = "Midnight Blue", CurrentChargePercentage = 50 }; Tesla modelS = new Tesla() { MainColor = "Burgundy", CurrentChargePercentage = 20 }; Cessna mx410 = new Cessna() { MainColor = "White", CurrentTankPercentage = 22 }; Ram truck = new Ram() { MainColor = "Silver", CurrentTankPercentage = 12 }; List <Vehicle> allVehicles = new List <Vehicle>() { fxs, modelS, truck, mx410 }; allVehicles.ForEach(vehicle => { vehicle.Drive(); vehicle.Turn("right"); vehicle.Stop(); Console.WriteLine(); }); List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>() { fxs, modelS }; Console.WriteLine("Electric Vehicles:"); electricVehicles.ForEach(ev => { Console.WriteLine($"{ev.CurrentChargePercentage}"); // This should charge the vehicle to 100% ev.ChargeBattery(); Console.WriteLine($"{ev.CurrentChargePercentage}"); Console.WriteLine(); }); List <IGasVehicle> gasVehicles = new List <IGasVehicle>() { truck, mx410 }; Console.WriteLine("Gas Vehicles:"); gasVehicles.ForEach(gv => { Console.WriteLine($"{gv.CurrentTankPercentage}"); // This should completely refuel the gas tank gv.RefuelTank(); Console.WriteLine($"{gv.CurrentTankPercentage}"); Console.WriteLine(); }); }