Advertisement
1_9tdiMamkaMu

Truck

Apr 21st, 2021
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5.  
  6.  
  7. namespace Vehicles.Models
  8. {
  9.     public class Truck : Vehicle
  10.     {
  11.  
  12.         public Truck(double fuelQuantity, double fuelConsum, double tankCapacity) : base(fuelQuantity, fuelConsum + 1.6, tankCapacity)
  13.         {
  14.         }
  15.         public override void ReFuel(double fuel)
  16.         {
  17.             double availableSpace = this.TankCapacity - this.FuelQuantity;
  18.  
  19.             if (fuel <= 0)
  20.             {
  21.                 throw new ArgumentException("Fuel must be a positive number");
  22.             }
  23.             if (availableSpace < fuel)
  24.             {
  25.                 throw new ArgumentException($"Cannot fit {fuel} fuel in the tank");
  26.             }
  27.  
  28.             FuelQuantity += fuel * 0.95;
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement