Vehicle.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. namespace Vehicle
  3. {
  4. class Vehicle
  5. {
  6. protected string Model;
  7. protected string Manufacturer;
  8. protected string Color;
  9. // Объем двигателя (2,5)
  10. protected float EngineСapacity;
  11. // Горючее
  12. protected float Fuel;
  13. // Мощьность л/с
  14. protected int Power;
  15. // Пройденный путь
  16. protected int Distance;
  17. // 4770
  18. public void Move(int distance)
  19. {
  20. if (distance < 1)
  21. {
  22. return;
  23. }
  24. float DeltaFuel = EngineСapacity * 0.01f;
  25. int currentDistance = 0;
  26. while (currentDistance < distance)
  27. {
  28. // 0,1 0,125
  29. if (Fuel < DeltaFuel)
  30. {
  31. Console.WriteLine("Закончилось горючее у " + Manufacturer + " " + Model);
  32. break;
  33. }
  34. Fuel -= DeltaFuel;
  35. Distance++;
  36. currentDistance++;
  37. }
  38. Console.WriteLine(Manufacturer + " " + Model + " проехал " + currentDistance + " метров из " + distance);
  39. }
  40. public void FuelUp(float value)
  41. {
  42. Fuel += value;
  43. }
  44. }
  45. }