Guest User

Car

a guest
Feb 4th, 2020
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace DefiningClasses
  6. {
  7. public class Car
  8. {
  9. public string model;
  10. public double fuelAmount;
  11. public double fuelConsumptionPerKilometer;
  12. public double travelledDistance = 0;
  13.  
  14. //{model} {fuelAmount} {fuelConsumptionFor1km};
  15.  
  16. public Car(string model, double fuelAmoount, double fuelConsumptionFor1km)
  17. {
  18. this.model = model;
  19. this.fuelAmount = fuelAmoount;
  20. this.fuelConsumptionPerKilometer = fuelConsumptionFor1km;
  21. this.travelledDistance = 0;
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. //;Drive {carModel} {amountOfKm};
  29. public void Drive(double amountOfKm)
  30. {
  31. var consumption = amountOfKm * this.fuelConsumptionPerKilometer;
  32. if (this.fuelAmount - consumption < 0)
  33. {
  34. Console.WriteLine("Insufficient fuel for the drive");
  35. }
  36. else
  37. {
  38. this.fuelAmount -= (consumption) ;
  39. this.travelledDistance += amountOfKm;
  40. }
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment