IPetrov007

Untitled

Jul 2nd, 2017
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. class Car
  2. {
  3. private string model;
  4. private double fuel;
  5. private double consumption;
  6. private double distance;
  7.  
  8. public Car(string model, double fuel, double consumption)
  9. {
  10. this.model = model;
  11. this.fuel = fuel;
  12. this.consumption = consumption;
  13. }
  14. public string Model
  15. {
  16. get { return this.model; }
  17. set { this.model = value; }
  18. }
  19. public double Fuel
  20. {
  21. get { return this.fuel; }
  22. set { this.fuel = value; }
  23. }
  24. public double Consumption
  25. {
  26. get { return this.consumption; }
  27. set { this.consumption = value; }
  28. }
  29. public double Distance
  30. {
  31. get { return this.distance; }
  32. set { this.distance = value; }
  33. }
  34.  
  35. public void IsMove(int km)
  36. {
  37. var fuelNeeded = km * this.consumption;
  38. if (fuelNeeded > this.fuel)
  39. {
  40. System.Console.WriteLine("Insufficient fuel for the drive");
  41. }
  42. else
  43. {
  44. this.fuel -= fuelNeeded;
  45. this.Distance += km;
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment