public static Reptile CreateReptile(ReptileSpecies Species) { Reptile animalObj = null;//Animaltype unknown at this time. //Lets determine users choice of animal. switch (Species) { case ReptileSpecies.Alligator: animalObj = new Alligator(); break; case ReptileSpecies.Cobra: animalObj = new Cobra(); break; case ReptileSpecies.Komodo: animalObj = new Komodo(); break; default: Debug.Assert(false, "Not implemented"); break; } //Set animal category animalObj.Category = CategoryType.Reptile; return(animalObj);//Return created instance of object. }
public static Reptile CreateReptile(ReptileSpecies Species) { Reptile animalObj = null;//Animaltype unknown at this time. //Lets determine users choice of animal. switch (Species) { case ReptileSpecies.Alligator: animalObj = new Alligator(); break; case ReptileSpecies.Cobra: animalObj = new Cobra(); break; case ReptileSpecies.Komodo: animalObj = new Komodo(); break; default: Debug.Assert(false, "Not implemented"); break; } //Set animal category animalObj.Category = CategoryType.Reptile; return animalObj;//Return created instance of object. }
private Animal castAnimal(int speciesIndex, CategoryType type) { //Checking which object to create: if (type == CategoryType.Bird) { BirdSpecies speciestype = (BirdSpecies)speciesIndex; animalis = BirdFactory.CreateBird(speciestype); } else if (type == CategoryType.Insect) { InsectSpecies insectSpec = (InsectSpecies)speciesIndex; animalis = InsectFactory.CreateInsect(insectSpec); } else if (type == CategoryType.Mammal) { MammalSpecies mammalSpec = (MammalSpecies)speciesIndex; animalis = MammalFactory.CreateMammal(mammalSpec); } else if (type == CategoryType.Marine) { MarineSpecies marineSpec = (MarineSpecies)speciesIndex; animalis = MarineFactory.CreateMarine(marineSpec); } else if (type == CategoryType.Reptile) { ReptileSpecies reptileSpec = (ReptileSpecies)speciesIndex; animalis = ReptileFactory.CreateReptile(reptileSpec); } return(animalis); }
public static Reptiles CreateReptile(ReptileSpecies Species) { Reptiles animalObj = null; //type not known at this time //type determined by late binding switch (Species) { case ReptileSpecies.Snake: animalObj = new Snake(); //Late binding break; //Continue with the rest case ReptileSpecies.Lizard: animalObj = new Lizard(); //Late binding break; default: Debug.Assert(false, "To be completed!"); break; } //set the category animalObj.Category = CategoryType.Reptile; return animalObj; //return the crated animal Object }
public Animal CreateReptile(ReptileSpecies reptileSpecies) { Reptile animalObj = null; switch (reptileSpecies) { case ReptileSpecies.Frog: animalObj = new Frog(); break; case ReptileSpecies.Lizard: animalObj = new Lizard(); break; case ReptileSpecies.Snake: animalObj = new Snake(); break; default: Debug.Assert(false, "To be completed!"); break; } animalObj.CategoryType = CategoryType.Reptile; return(animalObj); //return the created animal object. }
public static Reptile CreateReptile(ReptileSpecies species) { // Object type not known at this time Reptile animalObj = null; try { switch (species) { case ReptileSpecies.Boa: animalObj = new Boa();//late binding if(animalObj == null){ NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; case ReptileSpecies.Chamaleon: animalObj = new Chamaleon();//late binding if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; } } //custom exception catch (Exception e) { e.Message.ToString(); NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } finally { animalObj.Category = CategoryType.Reptile; } return animalObj; }
public static Reptile CreateReptile(ReptileSpecies species) { // Object type not known at this time Reptile animalObj = null; try { switch (species) { case ReptileSpecies.Boa: animalObj = new Boa(); //late binding if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; case ReptileSpecies.Chamaleon: animalObj = new Chamaleon(); //late binding if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; } } //custom exception catch (Exception e) { e.Message.ToString(); NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } finally { animalObj.Category = CategoryType.Reptile; } return(animalObj); }
private Animal CreateReptile() { // method to read Reptile specific inputs Animal animal = null; bool livesInWater = true; if (textBoxTeeth.Text == "YES") { livesInWater = true; } else if (textBoxTeeth.Text == "NO") { livesInWater = false; } double weight = 0.0; if (!double.TryParse(textBoxTail.Text, out weight)) { MessageBox.Show("Please give a valid value for weight!"); } ReptileSpecies species = (ReptileSpecies)Enum.Parse(typeof(ReptileSpecies), listBoxAnimal.Text); animal = Reptile.CreateReptile(species, weight, livesInWater); if (species == ReptileSpecies.Snake) { ((Snake)animal).Color = LabelSpeciesProperty.Text; } else if (species == ReptileSpecies.Lizard) { ((Lizard)animal).Color = LabelSpeciesProperty.Text; } else if (species == ReptileSpecies.Turtle) { ((Turtle)animal).Color = LabelSpeciesProperty.Text; } return(animal); }
public static Reptile CreateReptile(ReptileSpecies Species) { /// <summary /// Static method that creates choosen Animal, determed on the parameter Species. /// Reptile animalObj set to null; /// <returns>animalObj with created animal object</returns> /// </summary Reptile animalObj = null; switch (Species) { case ReptileSpecies.Anaconda: animalObj = new Anaconda(); break; case ReptileSpecies.Crocodile: animalObj = new Crocodile(); break; } animalObj.Category = CategoryType.Reptile; return animalObj; }
/// <summary> /// CreateReptile: Method that will be used to created different reptile objects /// </summary> public static Reptile CreateReptile(ReptileSpecies species, double weight, bool livesInWater) { Reptile reptile = null; switch (species) { case ReptileSpecies.Snake: reptile = new Snake(weight, livesInWater); break; case ReptileSpecies.Lizard: reptile = new Lizard(weight, livesInWater); break; case ReptileSpecies.Turtle: reptile = new Turtle(weight, livesInWater); break; } return(reptile); }
private Animal SetAnimalType() { Animal newAnimal = new Animal(); var selectedCategori = listBxCategori.SelectedIndex; if (string.IsNullOrEmpty(listbxAnimalSpecies.Text)) { showValidationMessage.ShowNewMessageBox("Du måste välja djurarten från listan!"); return(newAnimal = null); } else { switch (selectedCategori) { case 0: BirdSpecies birdSpecies = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), listbxAnimalSpecies.Text); BirdFactory birdFactory = new BirdFactory(); newAnimal = birdFactory.Createbird(birdSpecies); break; case 1: InsectSpecies insectSpecies = (InsectSpecies)Enum.Parse(typeof(InsectSpecies), listbxAnimalSpecies.Text); InsectFactory insectFactory = new InsectFactory(); newAnimal = insectFactory.CreateInsect(insectSpecies); break; case 2: MammalSpecies mammalSpecies = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listbxAnimalSpecies.Text); MammalFactory mammalFactory = new MammalFactory(); int daysOfQuarantine; int numberOfteeth; bool underQuarantine = chBoxUnderQuarantine.Checked; if (!helper.CheckInteger(texBoxDaysInQuarantine.Text, out daysOfQuarantine) && underQuarantine == true) { string messageDayOfQuarantine = "You have entered the error value in days of quarantine"; errorDayInQuarantiner.SetError(texBoxDaysInQuarantine, messageDayOfQuarantine); showValidationMessage.ShowNewMessageBox(messageDayOfQuarantine); newAnimal = null; break; } else { errorDayInQuarantiner.Clear(); } if (!int.TryParse(tboxNoOfTeeth.Text, out numberOfteeth)) { errorNoOfTeeth.SetError(tboxNoOfTeeth, "You have entered the error value"); showValidationMessage.TeethException(tboxNoOfTeeth.Text); newAnimal = null; break; } else { errorNoOfTeeth.Clear(); } newAnimal = mammalFactory.CreateMammal(mammalSpecies, daysOfQuarantine, underQuarantine, numberOfteeth); break; case 3: MarineSpecies marineSpecies = (MarineSpecies)Enum.Parse(typeof(MarineSpecies), listbxAnimalSpecies.Text); MarineFactory marineFactory = new MarineFactory(); newAnimal = marineFactory.CreateMarine(marineSpecies); break; case 4: ReptileSpecies reptileSpecies = (ReptileSpecies)Enum.Parse(typeof(ReptileSpecies), listbxAnimalSpecies.Text); ReptileFactory reptileFactory = new ReptileFactory(); newAnimal = reptileFactory.CreateReptile(reptileSpecies); break; } } return(newAnimal); }