static void Main(string[] args) { Cage <Ape> apeCage = new Cage <Ape>(CageType.Glass); Cage <Tiger> tigerCage = new Cage <Tiger>(CageType.Gitter); Ape ape = GenericObject.GenerateObject <Ape>(new object[] { "APE", "Bert", CageType.Glass }); apeCage.AddAnimal(ape); Tiger tiger = GenericObject.GenerateObject <Tiger>(new object[] { "TIGER", "Luzifer", CageType.Glass }); tigerCage.AddAnimal(tiger); apeCage.RemoveAnimal(ape); }
static void Process(int choose) { zoo = new Zoo(); switch (choose) { case 1: { Console.WriteLine("Add a new cage: "); Console.Write("--- Enter the cage's number: "); string str = Console.ReadLine(); while (!int.TryParse(str, out cageNumber)) { Console.Write("Enter again! "); str = Console.ReadLine(); } MenuAnimal(); cage = new Cage(cageNumber); zoo.AddAnimal(cage); } break; case 2: { Console.WriteLine("Enter the cage's number you want to remove: "); string str = Console.ReadLine(); while (!int.TryParse(str, out cageNumber)) { Console.Write("Enter again! "); str = Console.ReadLine(); } zoo.RemoveCage(cageNumber); } break; case 3: { Console.Write("Choose 'dog'(press 1), 'cat' (press 2) or 'tiger' (press 3) to add: "); str = Console.ReadLine(); int child; while (!int.TryParse(str, out child)) { Console.Write("Enter again! "); str = Console.ReadLine(); } switch (child) { case 1: Console.Write("Enter the name of dog: "); string name = Console.ReadLine(); dog = new Dog(name); cage.AddAnimal(dog); break; case 2: Console.Write("Enter the name of cat: "); name = Console.ReadLine(); cat = new Cat(name); cage.AddAnimal(cat); break; case 3: Console.Write("Enter the name of tiger: "); name = Console.ReadLine(); tiger = new Tiger(name); cage.AddAnimal(tiger); break; default: Console.Write("Enter again! "); str = Console.ReadLine(); break; } } break; case 4: { Console.Write("Enter the name of animal you want to remove: "); string name = Console.ReadLine(); cage.RemoveAnimal(name); } break; case 5: { Console.WriteLine("\nIterate animal in the cage:"); Console.Write("Animal"); cage.IterateAnimals(); } break; case 6: Console.WriteLine("Exit."); Environment.Exit(Environment.ExitCode); break; default: Console.WriteLine("Enter 1, 2, 3, 4 or 5: "); Menu(); break; } Menu(); }