Advertisement
social1986

Untitled

Feb 18th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2.  
  3. public class Car
  4. {
  5.     private string model;
  6.     private double fuelAmount;
  7.     private double fuelConsumption;
  8.     private double distance;
  9.  
  10.     public Car(string model, double fuelAmount, double fuelConsumption)
  11.     {
  12.         this.Model = model;
  13.         this.FuelAmount = fuelAmount;
  14.         this.FuelConsumption = fuelConsumption;
  15.     }
  16.  
  17.  
  18.     public double Distance
  19.     {
  20.         get { return distance; }
  21.         set { distance = value; }
  22.     }
  23.    
  24.     public double FuelConsumption
  25.     {
  26.         get { return fuelConsumption; }
  27.         set { fuelConsumption = value; }
  28.     }
  29.    
  30.     public double FuelAmount
  31.     {
  32.         get { return fuelAmount; }
  33.         set { fuelAmount = value; }
  34.     }
  35.  
  36.     public string Model
  37.     {
  38.         get { return model; }
  39.         set { model = value; }
  40.     }
  41.  
  42.  
  43.     public void Move(double km)
  44.     {
  45.         if (this.fuelAmount >= this.fuelConsumption * km)
  46.         {
  47.             this.Distance += km;
  48.             this.FuelAmount -= km * this.FuelConsumption;
  49.         }
  50.         else
  51.         {
  52.             Console.WriteLine("Insufficient fuel for the drive");
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement