Last active
October 10, 2020 08:59
-
-
Save quandaso/1898a8d5259bd2d98f9766963340be1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Reflection; | |
namespace OOP2 | |
{ | |
interface Vericle | |
{ | |
public string getEngine(); | |
public void simulate(); | |
} | |
class Transport: Vericle | |
{ | |
protected string engine = "steam-engine"; | |
protected string name = "Transport"; | |
protected string toPrint = "##########"; | |
public Transport(string engine = null, string name = null, string toPrint = null) | |
{ | |
if (engine != null) | |
{ | |
this.engine = engine; | |
} | |
if (name != null) | |
{ | |
this.name = name; | |
} | |
if (toPrint != null) | |
{ | |
this.toPrint = toPrint; | |
} | |
} | |
public string getEngine() | |
{ | |
Console.WriteLine(this.name + "Engine: " + this.engine); | |
return this.engine; | |
} | |
public void simulate() | |
{ | |
this.getEngine(); | |
Console.WriteLine(this.toPrint); | |
} | |
} | |
class Car : Transport | |
{ | |
public Car(): base("four-stroke engine", "Car") | |
{ | |
} | |
public void drive() | |
{ | |
} | |
public void simulate() | |
{ | |
base.simulate(); | |
this.drive(); | |
} | |
} | |
class Aircraft : Transport | |
{ | |
public Aircraft() : base("turbofan engine", "Aircraft", ">>>>>>>>>>>>>>>") | |
{ | |
} | |
public void pilot() | |
{ | |
} | |
public void simulate() | |
{ | |
base.simulate(); | |
this.pilot(); | |
} | |
} | |
class Submarine: Transport | |
{ | |
public Submarine(): base("gasoline engine", "Submarine", "&&&&&&&&&&&&&&") | |
{ | |
} | |
public void dive() | |
{ | |
} | |
public void simulate() | |
{ | |
base.simulate(); | |
this.dive(); | |
} | |
} | |
class SuperTransport: Transport | |
{ | |
private string[] combineEngine = { "Car", "Aircraft", "Submarine" }; | |
public SuperTransport() : base("hybird", "SuperTransport", "&&&&&&&&&&&&&&") | |
{ | |
} | |
private static Vericle CreateInstance(string className) | |
{ | |
var assembly = Assembly.GetExecutingAssembly(); | |
var type = assembly.GetTypes() | |
.First(t => t.Name == className); | |
return (Vericle) Activator.CreateInstance(type); | |
} | |
public void simulate(int env) | |
{ | |
string engineName = this.combineEngine[env]; | |
var a = CreateInstance(engineName); | |
Console.WriteLine("[SuperTransport] running AS: " + engineName); | |
a.simulate(); | |
} | |
} | |
class Ferrari: Car | |
{ | |
public Ferrari() : base() | |
{ | |
this.engine = "F154"; | |
this.name = "Ferrari"; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var transport = new Transport(); | |
var car = new Car(); | |
var aircarft = new Aircraft(); | |
var submarine = new Submarine(); | |
var super = new SuperTransport(); | |
var ferrari = new Ferrari(); | |
transport.simulate(); | |
car.simulate(); | |
aircarft.simulate(); | |
submarine.simulate(); | |
ferrari.simulate(); | |
int ENV_LAND = 0; | |
int ENV_AIR = 1; | |
int ENV_WATER = 2; | |
super.simulate(ENV_LAND); | |
super.simulate(ENV_AIR); | |
super.simulate(ENV_WATER); | |
} | |
} | |
} |
Author
quandaso
commented
Oct 10, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment