static void Main(string[] args) { IBird[] birds = new IBird[rand.Next(10, 20)]; for (int i = 0; i < birds.Length; i++) { IBird bird = null; var nextRand = rand.Next(0, 30); if (nextRand > 20) { bird = new Eagle(); } else if (nextRand > 10) { bird = new Lark(); } else { bird = new Sparrow(); } bird.CurrentSpeed = rand.Next(10, (int)bird.MaxSpeed - 1) + rand.NextDouble(); birds[i] = bird; } foreach (IBird bird in birds) { Console.WriteLine("=============================================================================="); try { var speedAcceleration = rand.Next(1, 100); Console.WriteLine("Current speed for {0} is {1}, the wind speed is {2}", bird.Name, bird.CurrentSpeed, speedAcceleration); bird.FlyWithinWind(speedAcceleration); Console.WriteLine("After windy weather the bird is Alive"); } catch (BirdFlewAwayException ex) { Console.WriteLine(ex.Message); } } Console.ReadLine(); }
static void Main(string[] args) { ICompressor compressor = new PNG(); ImageStorage imageStorage = new ImageStorage("ALI"); imageStorage.Store(compressor); ICompressor compressor2 = new JPEG(); ImageStorage imageStorage2 = new ImageStorage("LK"); imageStorage2.Store(compressor2); IFilter larkFilter = new Lark(); imageStorage.Filter(larkFilter); imageStorage2.Filter(larkFilter); }