Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- Car[] Cars = new Car[5];
- Cars[0] = new ElectronicCar(132000, "Tesla Model S", 3200, 300, 40000, 28000);
- Cars[1] = new ElectronicCar(178000, "BMW i8", 4300, 330, 47000, 12000);
- Cars[2] = new Car(240000, "Aston Martin Vanquish", 5200);
- Cars[3] = new Car(68000, "BMW 530d", 2200);
- Cars[4] = new Car(1000000, "Bugatti Veyron Super Sport", 8000);
- for (int i = 0; i < Cars.Length; i++)
- {
- if (Cars[i] is ElectronicCar)
- {
- ElectronicCar Car = Cars[i] as ElectronicCar;
- Car.charge();
- Cars[i] = Car;
- }
- }
- for (int i = 0; i < Cars.Length; i++)
- {
- Console.WriteLine("Car Number "+(i+1) + ": ");
- if (Cars[i] is ElectronicCar)
- {
- ElectronicCar Car = Cars[i] as ElectronicCar;
- Car.print();
- }
- else
- {
- Cars[i].print();
- }
- Console.WriteLine();
- }
- }
- }
- class Car
- {
- int price;
- string type;
- int cc;
- public Car(int price, string type, int cc)
- {
- this.price = price;
- this.type = type;
- this.cc = cc;
- }
- public void print()
- {
- Console.WriteLine("Price: " + price);
- Console.WriteLine("type: " + type);
- Console.WriteLine("cc: " + cc);
- }
- }
- class ElectronicCar : Car
- {
- int ElectricityUse;
- int MaxKWH;
- int CurrentKWH;
- public ElectronicCar(int price, string type, int cc,int ElectricityUse, int MaxKWH, int CurrentKWH) : base(price, type, cc)
- {
- this.ElectricityUse = ElectricityUse;
- this.MaxKWH = MaxKWH;
- this.CurrentKWH = CurrentKWH;
- }
- public void charge()
- {
- this.CurrentKWH = MaxKWH;
- }
- public void print()
- {
- base.print();
- Console.WriteLine("Electricity Use: " + ElectricityUse);
- Console.WriteLine("Max KWH: " + MaxKWH);
- Console.WriteLine("Current KWH: " + CurrentKWH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement