Advertisement
Guest User

pastac

a guest
Nov 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4.  
  5. namespace Program
  6. {
  7.     public class Car
  8.     {
  9.         public double Speed { get; protected set; } = 100;
  10.         public double Acceleration { get; protected set; } = 100;
  11.         public void Start() {
  12.             Console.WriteLine("Turning on the engine...");
  13.             Console.WriteLine($"Running at: {Speed} km/h");
  14.         }
  15.         public void Stop()
  16.         {
  17.             Console.WriteLine("Stopping the car...");
  18.         }
  19.         public void Accelerate()
  20.         {
  21.             Console.WriteLine("Accelerating...");
  22.             Speed += Acceleration;
  23.             Console.WriteLine($"Running at {Speed} km/h");
  24.         }
  25.     }
  26.     public class Truck : Car
  27.     {
  28.         public void Accelerate()
  29.         {
  30.             Speed = 5;
  31.         }
  32.     }
  33.  
  34.     public class SportCar : Car
  35.     {
  36.  
  37.     }
  38.  
  39.     public class Race
  40.     {
  41.         public void Begin()
  42.         {
  43.             SportCar sportCar = new SportCar();
  44.             Truck truck = new Truck();
  45.  
  46.             List<Car> cars = new List<Car>()
  47.             {
  48.                 sportCar, truck
  49.             };
  50.             foreach(Car car in cars)
  51.             {
  52.                 car.Start();
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement