Advertisement
social1986

Untitled

Feb 18th, 2018
124
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 void Move (double km)
  11.     {
  12.         if (this.fuelAmount >= this.fuelConsumption * km)
  13.         {
  14.             this.Distance += km;
  15.             this.FuelAmount -= km * this.FuelConsumption;
  16.         }
  17.         else
  18.         {
  19.             Console.WriteLine("Insufficient fuel for the drive");
  20.         }
  21.     }
  22.  
  23.     public Car(string model, double fuelAmount, double fuelConsumption)
  24.     {
  25.         this.Model = model;
  26.         this.FuelAmount = fuelAmount;
  27.         this.FuelConsumption = fuelConsumption;
  28.     }
  29.  
  30.     public double Distance
  31.     {
  32.         get { return distance; }
  33.         set { distance = value; }
  34.     }
  35.    
  36.     public double FuelConsumption
  37.     {
  38.         get { return fuelConsumption; }
  39.         set { fuelConsumption = value; }
  40.     }
  41.    
  42.     public double FuelAmount
  43.     {
  44.         get { return fuelAmount; }
  45.         set { fuelAmount = value; }
  46.     }
  47.  
  48.     public string Model
  49.     {
  50.         get { return model; }
  51.         set { model = value; }
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement