Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1.  
  2.     abstract class ParrotGenerator
  3.     {
  4.         public static Parrot AfricanParrot(int numberOfCoconuts)
  5.         {
  6.             return new AfricanParrot(numberOfCoconuts);
  7.         }
  8.  
  9.         public static Parrot EuropeanParrot()
  10.         {
  11.             return new EuropeanParrot();
  12.         }
  13.  
  14.         public static Parrot NorvegianBlueParrot(bool isNailed, double voltage)
  15.         {
  16.             return new NorwegianBlueParrot(isNailed, voltage);
  17.         }
  18.     }
  19.  
  20.    public abstract class Parrot
  21.     {
  22.         protected const double BaseSpeed = 12.0;
  23.  
  24.         public abstract double GetSpeed();
  25.     }
  26.  
  27.  class NorwegianBlueParrot : Parrot
  28.     {
  29.         private readonly bool _isNailed;
  30.         private readonly double _voltage;
  31.  
  32.         public NorwegianBlueParrot(bool isNailed, double voltage)
  33.         {
  34.             _isNailed = isNailed;
  35.             _voltage = voltage;
  36.         }
  37.  
  38.         public override double GetSpeed()
  39.         {
  40.             return (_isNailed) ? 0 : GetBaseSpeed(_voltage);
  41.         }
  42.  
  43.         private double GetBaseSpeed(double voltage)
  44.         {
  45.             return Math.Min(24.0, voltage * BaseSpeed);
  46.         }
  47.     }
  48.  
  49.  class AfricanParrot : Parrot
  50.     {
  51.         private readonly int _numberOfCoconuts;
  52.  
  53.         protected const double LoadFactor = 9.0;
  54.  
  55.         public AfricanParrot(int numberOfCoconuts)
  56.         {
  57.             _numberOfCoconuts = numberOfCoconuts;
  58.         }
  59.  
  60.         public override double GetSpeed()
  61.         {
  62.             return Math.Max(0, BaseSpeed - LoadFactor * _numberOfCoconuts);
  63.         }
  64.     }
  65.  
  66.  public abstract class Parrot
  67.     {
  68.         protected const double BaseSpeed = 12.0;
  69.  
  70.         public abstract double GetSpeed();
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement