Advertisement
dobroslav-atanasov

Untitled

Mar 15th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. //CAR
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. public class Car
  7. {
  8.     private const double FUEL_TANK_CAPACITY = 160;
  9.  
  10.     private int hp;
  11.     private double fuelAmount;
  12.     private Tyre tyre;
  13.  
  14.     public Car(int hp, double fuelAmount, Tyre tyre)
  15.     {
  16.         this.Hp = hp;
  17.         this.FuelAmount = fuelAmount;
  18.         this.Tyre = tyre;
  19.     }
  20.  
  21.     public int Hp
  22.     {
  23.         get { return this.hp; }
  24.         private set { this.hp = value; }
  25.     }
  26.  
  27.     public double FuelAmount
  28.     {
  29.         get { return this.fuelAmount; }
  30.         private set
  31.         {
  32.             if (value < 0)
  33.             {
  34.                 throw new ArgumentException();
  35.             }
  36.  
  37.             if (value > FUEL_TANK_CAPACITY)
  38.             {
  39.                 this.fuelAmount = FUEL_TANK_CAPACITY;
  40.             }
  41.             else
  42.             {
  43.                 this.fuelAmount = value;
  44.             }
  45.         }
  46.     }
  47.  
  48.     public Tyre Tyre
  49.     {
  50.         get { return this.tyre; }
  51.         private set { this.tyre = value; }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement