Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface ICar
- {
- string Start();
- string Stop();
- }
- public abstract class Car : ICar
- {
- public Car(string model, string color)
- {
- this.Model = model;
- this.Color = color;
- }
- public string Model { get; private set; }
- public string Color { get; private set; }
- public virtual string Start()
- {
- return "Engine start";
- }
- public virtual string Stop()
- {
- return "Breaaak!";
- }
- public override string ToString()
- {
- return $"{this.Color} {this.GetType().Name} {this.Model}";
- }
- }
- public abstract class ElectricCar : Car
- {
- public ElectricCar(string model, string color, int batteries)
- :base(model, color)
- {
- this.Battery = batteries;
- }
- public int Battery { get; private set; }
- }
- using System;
- using System.Text;
- public class Seat : Car
- {
- public Seat(string model, string color)
- : base(model, color)
- {
- }
- public override string ToString()
- {
- var sb = new StringBuilder(base.ToString() + Environment.NewLine);
- sb.AppendLine(Start());
- sb.AppendLine(Stop());
- return sb.ToString();
- }
- }
- using System.Text;
- public class Tesla : ElectricCar
- {
- public Tesla(string model, string color, int batteries)
- :base(model, color, batteries)
- {
- }
- public override string ToString()
- {
- var sb = new StringBuilder();
- sb.AppendLine($"{base.ToString()} with {this.Battery} Batteries");
- sb.AppendLine(Start());
- sb.AppendLine(Stop());
- return sb.ToString().TrimEnd();
- }
- }
- using System;
- public class StartUp
- {
- public static void Main()
- {
- Car seat = new Seat("Leon", "Grey");
- Car tesla = new Tesla("Model 3", "Red", 2);
- Console.WriteLine(seat);
- Console.WriteLine(tesla);
- }
- }
Add Comment
Please, Sign In to add comment