Advertisement
MeGaDeTH_91

Car

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