private void CountSumWeight() { foreach (object animal in SupportingMethods.zoo) { if (animal is KingdomAnimal) { if (animal is ClassBirds) { if (selectedItem == 2) { ClassBirds bird = animal as ClassBirds; numberOfObjectsWithThisType++; sumWeight += bird.Weight; } continue; } if (animal is ClassMammals) { if (animal is OrderArtiodactyl) { if (selectedItem == 3) { OrderArtiodactyl artiodactyl = animal as OrderArtiodactyl; numberOfObjectsWithThisType++; sumWeight += artiodactyl.Weight; } continue; } if (selectedItem == 1) { ClassMammals mammal = animal as ClassMammals; numberOfObjectsWithThisType++; sumWeight += mammal.Weight; } continue; } if (selectedItem == 0) { KingdomAnimal being = animal as KingdomAnimal; numberOfObjectsWithThisType++; sumWeight += being.Weight; } } } }
private void CountSumMaxAge() { foreach (object animal in SupportingMethods.zoo) { if (animal is ClassMammals) { if (animal is OrderArtiodactyl) { continue; } else { ClassMammals mammal = animal as ClassMammals; numberOfObjectsWithThisType++; sumMaxAge += mammal.LifeExpectancy; } } } }
private void BTAnimalCreate_Click(object sender, EventArgs e) { string name = Inputs.InputName(TBMammalName.Text); if (name != null) { int weight = Inputs.InputWeight(TBMammalWeight.Text); if (weight > 0) { int incubationPeriod = Inputs.InputIncubationPeriod(TBIncubationPeriod.Text); if (incubationPeriod > 0) { int lifeExtrancy = Inputs.InputLifeExpectancy(TBMaxAge.Text); if (lifeExtrancy > 0) { ClassMammals mammal = new ClassMammals(incubationPeriod, lifeExtrancy, weight, name); SupportingMethods.zoo.Add(mammal); mammals.Add(mammal); } else { SupportingMethods.ShowMistake("Продолжительность жизни введена неверно"); } } else { SupportingMethods.ShowMistake("Период вынашивания введен неверно"); } } else { SupportingMethods.ShowMistake(content: "Вес введен неверно"); } } TBIncubationPeriod.Clear(); TBMammalName.Clear(); TBMammalWeight.Clear(); TBMaxAge.Clear(); }