Advertisement
dobroslav-atanasov

Untitled

Mar 15th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. //TYRE
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6.  
  7. public abstract class Tyre
  8. {
  9.     private string name;
  10.     private double hardness;
  11.     private double degradation;
  12.  
  13.     protected Tyre(string name, double hardness)
  14.     {
  15.         this.Name = name;
  16.         this.Hardness = hardness;
  17.         this.Degradation = 100;
  18.     }
  19.  
  20.     public string Name
  21.     {
  22.         get { return this.name; }
  23.         private set { this.name = value; }
  24.     }
  25.  
  26.     public double Hardness
  27.     {
  28.         get { return this.hardness; }
  29.         private set { this.hardness = value; }
  30.     }
  31.  
  32.     public virtual double Degradation
  33.     {
  34.         get { return this.degradation; }
  35.         protected set
  36.         {
  37.             if (value < 0)
  38.             {
  39.                 throw new ArgumentException();
  40.             }
  41.  
  42.             this.degradation = value;
  43.         }
  44.     }
  45. }
  46.  
  47. //-------------------------------------------------------------------------
  48. using System;
  49. using System.Collections.Generic;
  50. using System.Text;
  51.  
  52. public class UltrasoftTyre : Tyre
  53. {
  54.     private double grip;
  55.     private double degradation;
  56.  
  57.     public UltrasoftTyre(double hardness) : base("Ultrasoft", hardness) { }
  58.  
  59.     public double Grip
  60.     {
  61.         get { return this.grip; }
  62.         private set { this.grip = value; }
  63.     }
  64.  
  65.     public override double Degradation
  66.     {
  67.         get { return base.Degradation; }
  68.         protected set
  69.         {
  70.             if (value < 30)
  71.             {
  72.                 throw new ArgumentException("Blown Tyre");
  73.             }
  74.  
  75.             this.degradation = value;
  76.         }
  77.     }
  78. }
  79.  
  80. //------------------------------------------------------------------------------
  81. using System;
  82. using System.Collections.Generic;
  83. using System.Text;
  84.  
  85. public class HardTyre : Tyre
  86. {
  87.     public HardTyre(double hardness) : base("Hard", hardness) { }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement