Advertisement
svetlyoek

Untitled

Jun 4th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace CarManufacturer
  5. {
  6. public class Car
  7. {
  8. public string make;
  9.  
  10. public string model;
  11.  
  12. public int year;
  13.  
  14. public double fuelQuantity;
  15.  
  16. public double fuelConsumption;
  17.  
  18. public string Make
  19. {
  20. get
  21. {
  22. return this.make;
  23. }
  24. set
  25. {
  26. this.make = value;
  27. }
  28. }
  29.  
  30. public string Model
  31. {
  32. get
  33. {
  34. return this.model;
  35. }
  36. set
  37. {
  38. this.model = value;
  39. }
  40. }
  41.  
  42. public int Year
  43. {
  44. get
  45. {
  46. return this.year;
  47. }
  48. set
  49. {
  50. this.year = value;
  51. }
  52. }
  53.  
  54. public double FuelQuantity
  55. {
  56. get
  57. {
  58. return this.fuelQuantity;
  59. }
  60. set
  61. {
  62. this.fuelQuantity = value;
  63. }
  64. }
  65.  
  66. public double FuelConsumption
  67. {
  68. get
  69. {
  70. return this.fuelConsumption;
  71. }
  72. set
  73. {
  74. this.fuelConsumption = value;
  75. }
  76. }
  77.  
  78.  
  79.  
  80. public void Drive(double distance)
  81. {
  82.  
  83. if (this.FuelQuantity - ((this.FuelConsumption * distance) / 100) >= 0)
  84. {
  85.  
  86. this.FuelQuantity -= ((distance* this.FuelConsumption) / 100);
  87.  
  88. }
  89.  
  90. else
  91. {
  92.  
  93. Console.WriteLine($"Not enough fuel to perform this trip!");
  94. }
  95. }
  96.  
  97. public string WhoAmI()
  98. {
  99. var carInfo = new StringBuilder();
  100.  
  101. carInfo.AppendLine($"Make: {this.Make}");
  102.  
  103. carInfo.AppendLine($"Model: {this.Model}");
  104.  
  105. carInfo.AppendLine($"Year: {this.Year}");
  106.  
  107. carInfo.Append($"Fuel: {this.FuelQuantity:F2}L");
  108.  
  109. return carInfo.ToString();
  110. }
  111.  
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement