Advertisement
Guest User

Speed Racing class

a guest
Jun 9th, 2020
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Problem_6._Speed_Racing
  6. {
  7.     public class Car
  8.     {
  9.         private string model;
  10.         private double fuelAmount;
  11.         private double fuelConsumptionPerKilometer;
  12.         private double travelledDistance;
  13.  
  14.         public Car(string model, double fuelAmount, double fuelConsumptionPerKilometer)
  15.         {
  16.             this.Model = model;
  17.             this.FuelAmount = fuelAmount;
  18.             this.FuelConsumptionPerKilometer = fuelConsumptionPerKilometer;
  19.             this.TravelledDistance = 0; //не е в конструктора, но е дефолтна
  20.         }
  21.  
  22.         public string Model
  23.         {
  24.             get
  25.             {
  26.                 return this.model;
  27.             }
  28.             set
  29.             {
  30.                 this.model = value;
  31.             }
  32.         }
  33.  
  34.         public double FuelAmount
  35.         {
  36.             get
  37.             {
  38.                 return this.fuelAmount;
  39.             }
  40.             set
  41.             {
  42.                 this.fuelAmount = value;
  43.             }
  44.         }
  45.  
  46.         public double FuelConsumptionPerKilometer
  47.         {
  48.             get
  49.             {
  50.                 return this.fuelConsumptionPerKilometer;
  51.             }
  52.             set
  53.             {
  54.                 this.fuelConsumptionPerKilometer = value;
  55.             }
  56.         }
  57.  
  58.         public double TravelledDistance
  59.         {
  60.             get
  61.             {
  62.                 return this.travelledDistance;
  63.             }
  64.             set
  65.             {
  66.                 this.travelledDistance = value;
  67.             }
  68.         }
  69.  
  70.         public void CanDriveTheDistance(double amountOfKm)
  71.         {
  72.  
  73.             double neededFuel = amountOfKm * this.FuelConsumptionPerKilometer;
  74.             if (neededFuel <= this.FuelAmount)
  75.             {
  76.                 this.FuelAmount -= neededFuel;
  77.                 this.TravelledDistance += amountOfKm;
  78.             }
  79.             else
  80.             {
  81.                 Console.WriteLine("Insufficient fuel for the drive");
  82.             }          
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement