Advertisement
Guest User

Untitled

a guest
Apr 19th, 2021
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using System;
  2. using Vehicles.Interfaces;
  3.  
  4. namespace Vehicles.Models
  5. {
  6. public abstract class Vehicle : IVehicle
  7. {
  8. public double FuelQuantity { get; protected set; }
  9.  
  10. public abstract double FuelConsumption { get; protected set; }
  11.  
  12. public string Drive(double distance)
  13. {
  14. double checkerForFuel = this.FuelConsumption * distance;
  15. if(this.FuelQuantity >= checkerForFuel)
  16. {
  17. this.FuelQuantity -= checkerForFuel;
  18. return String.Format("{0} travelled {1} km", this.GetType().Name, distance);
  19. }
  20.  
  21. else
  22. {
  23. return string.Format("{0} needs refueling", this.GetType().Name);
  24. }
  25. }
  26.  
  27. public virtual void Refuel(double liters)
  28. {
  29. this.FuelQuantity += liters;
  30. }
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement