Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class ParrotGenerator
- {
- public static Parrot AfricanParrot(int numberOfCoconuts)
- {
- return new AfricanParrot(numberOfCoconuts);
- }
- public static Parrot EuropeanParrot()
- {
- return new EuropeanParrot();
- }
- public static Parrot NorvegianBlueParrot(bool isNailed, double voltage)
- {
- return new NorwegianBlueParrot(isNailed, voltage);
- }
- }
- public abstract class Parrot
- {
- protected const double BaseSpeed = 12.0;
- public abstract double GetSpeed();
- }
- class NorwegianBlueParrot : Parrot
- {
- private readonly bool _isNailed;
- private readonly double _voltage;
- public NorwegianBlueParrot(bool isNailed, double voltage)
- {
- _isNailed = isNailed;
- _voltage = voltage;
- }
- public override double GetSpeed()
- {
- return (_isNailed) ? 0 : GetBaseSpeed(_voltage);
- }
- private double GetBaseSpeed(double voltage)
- {
- return Math.Min(24.0, voltage * BaseSpeed);
- }
- }
- class AfricanParrot : Parrot
- {
- private readonly int _numberOfCoconuts;
- protected const double LoadFactor = 9.0;
- public AfricanParrot(int numberOfCoconuts)
- {
- _numberOfCoconuts = numberOfCoconuts;
- }
- public override double GetSpeed()
- {
- return Math.Max(0, BaseSpeed - LoadFactor * _numberOfCoconuts);
- }
- }
- public abstract class Parrot
- {
- protected const double BaseSpeed = 12.0;
- public abstract double GetSpeed();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement