Advertisement
social1986

Untitled

Feb 27th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. public interface ICar
  2. {
  3. string Start();
  4. string Stop();
  5. }
  6.  
  7. public abstract class Car : ICar
  8. {
  9.  
  10. public Car(string model, string color)
  11. {
  12. this.Model = model;
  13. this.Color = color;
  14. }
  15.  
  16. public string Model { get; private set; }
  17. public string Color { get; private set; }
  18.  
  19. public virtual string Start()
  20. {
  21. return "Engine start";
  22. }
  23.  
  24. public virtual string Stop()
  25. {
  26. return "Breaaak!";
  27. }
  28.  
  29. public override string ToString()
  30. {
  31. return $"{this.Color} {this.GetType().Name} {this.Model}";
  32. }
  33. }
  34.  
  35. public abstract class ElectricCar : Car
  36. {
  37. public ElectricCar(string model, string color, int batteries)
  38. :base(model, color)
  39. {
  40. this.Battery = batteries;
  41. }
  42. public int Battery { get; private set; }
  43. }
  44.  
  45. using System;
  46. using System.Text;
  47.  
  48. public class Seat : Car
  49. {
  50. public Seat(string model, string color)
  51. : base(model, color)
  52. {
  53. }
  54.  
  55. public override string ToString()
  56. {
  57. var sb = new StringBuilder(base.ToString() + Environment.NewLine);
  58. sb.AppendLine(Start());
  59. sb.AppendLine(Stop());
  60. return sb.ToString();
  61. }
  62. }
  63.  
  64. using System.Text;
  65.  
  66. public class Tesla : ElectricCar
  67. {
  68. public Tesla(string model, string color, int batteries)
  69. :base(model, color, batteries)
  70. {
  71. }
  72.  
  73. public override string ToString()
  74. {
  75. var sb = new StringBuilder();
  76. sb.AppendLine($"{base.ToString()} with {this.Battery} Batteries");
  77. sb.AppendLine(Start());
  78. sb.AppendLine(Stop());
  79. return sb.ToString().TrimEnd();
  80. }
  81. }
  82.  
  83. using System;
  84.  
  85. public class StartUp
  86. {
  87. public static void Main()
  88. {
  89.  
  90. Car seat = new Seat("Leon", "Grey");
  91. Car tesla = new Tesla("Model 3", "Red", 2);
  92.  
  93. Console.WriteLine(seat);
  94. Console.WriteLine(tesla);
  95.  
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement