Advertisement
joro_thexfiles

Problem_6_Speed_Racing

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