Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Vehicle
- {
- private double fuelQuantity;
- private double fuelConsumptionInLitersPerKm;
- public Vehicle(double fuelQuantity, double fuelConsumption)
- {
- this.FuelQuantity = fuelQuantity;
- this.FuelConsumption = fuelConsumption;
- }
- public double FuelQuantity
- {
- get => this.fuelQuantity;
- set => this.fuelQuantity = value;
- }
- public double FuelConsumption
- {
- get => this.fuelConsumptionInLitersPerKm;
- set => this.fuelConsumptionInLitersPerKm = value;
- }
- public string Drive(double distance)
- {
- if (distance * FuelConsumption > FuelQuantity)
- {
- return $"{this.GetType().Name} needs refueling";
- }
- this.FuelQuantity -= distance * this.FuelConsumption;
- return $"{this.GetType().Name} travelled {distance} km";
- }
- public virtual void Refuel(double quantity)
- {
- this.FuelQuantity += quantity;
- }
- public override string ToString()
- {
- return $"{this.GetType().Name}: {this.FuelQuantity:f2}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement