Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1.  
  2. using System.Text;
  3. using P02_CarsSalesman;
  4.  
  5. class Car
  6. {
  7. private const string offset = " ";
  8.  
  9. //public int MyProperty
  10. //{
  11. // get { return myVar; }
  12. // set { myVar = value; }
  13. //}
  14.  
  15. public string model;
  16. public Engine engine;
  17. public int weight;
  18. public string color;
  19.  
  20. public Car(string model, Engine engine)
  21. {
  22. this.model = model;
  23. this.engine = engine;
  24. this.weight = -1;
  25. this.color = "n/a";
  26. }
  27.  
  28. public Car(string model, Engine engine, int weight)
  29. {
  30. this.model = model;
  31. this.engine = engine;
  32. this.weight = weight;
  33. this.color = "n/a";
  34. }
  35.  
  36. public Car(string model, Engine engine, string color)
  37. {
  38. this.model = model;
  39. this.engine = engine;
  40. this.weight = -1;
  41. this.color = color;
  42. }
  43.  
  44. public Car(string model, Engine engine, int weight, string color)
  45. {
  46. this.model = model;
  47. this.engine = engine;
  48. this.weight = weight;
  49. this.color = color;
  50. }
  51.  
  52.  
  53. public override string ToString()
  54. {
  55. StringBuilder sb = new StringBuilder();
  56. sb.AppendFormat("{0}:\n", this.model);
  57. sb.Append(this.engine.ToString());
  58. sb.AppendFormat("{0}Weight: {1}\n", offset, this.weight == -1 ? "n/a" : this.weight.ToString());
  59. sb.AppendFormat("{0}Color: {1}", offset, this.color);
  60.  
  61. return sb.ToString();
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement