Advertisement
Danny_Berova

10_ car

Feb 14th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System.Text;
  2.  
  3. public class Car
  4. {
  5.     private string model;
  6.     private Engine engine;
  7.     private string weight;
  8.     private string color;
  9.  
  10.     public Car(string model, Engine engine)
  11.     {
  12.         this.Model = model;
  13.         this.Engine = engine;
  14.         this.Weight = "n/a";
  15.         this.Color = "n/a";
  16.     }
  17.  
  18.     public string Model
  19.     {
  20.         get => this.model;
  21.         set => this.model = value;
  22.     }
  23.  
  24.     public Engine Engine
  25.     {
  26.         get => this.engine;
  27.         set => this.engine = value;
  28.     }
  29.  
  30.     public string Weight
  31.     {
  32.         get => this.weight;
  33.         set => this.weight = value;
  34.     }
  35.  
  36.     public string Color
  37.     {
  38.         get => this.color;
  39.         set => this.color = value;
  40.     }
  41.  
  42.     public override string ToString()
  43.     {
  44.         var builder = new StringBuilder()
  45.             .AppendLine($"{this.model}:")
  46.             .AppendLine($"  {this.Engine.Model}:")
  47.             .AppendLine($"    Power: {this.Engine.Power}")
  48.             .AppendLine($"    Displacement: {this.engine.Displacement}")
  49.             .AppendLine($"    Efficiency: {this.Engine.Efficiency}")
  50.             .AppendLine($"  Weight: {this.weight}")
  51.             .AppendLine($"  Color: {this.color}");
  52.  
  53.         return builder.ToString();
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement