예제 #1
0
        public static Mammal CreateMammal(MammalSpecies Species)
        {
            Mammal animalObj = null;//Animaltype unknown at this time.

            //Lets determine users choice of animal.
            switch (Species)
            {
                case MammalSpecies.Cat:
                    animalObj = new Cat();
                    break;
                case MammalSpecies.Dog:
                    animalObj = new Dog();
                    break;
                case MammalSpecies.Gorilla:
                    animalObj = new Gorilla();
                    break;

                default:
                    Debug.Assert(false, "Not implemented");
                    break;
            }

            //Set animal category
            animalObj.Category = CategoryType.Mammal;

            return animalObj;//Return created instance of object.
        }
예제 #2
0
        public static Mammals CreateMammal(MammalSpecies Species)
        {
            Mammals animalObj = null; //type not known at this time

            //type determined by late binding
            switch (Species)
            {
                case MammalSpecies.Cow:
                    animalObj = new Cow();           //Late binding
                    break;
                //Continue with the rest
                case MammalSpecies.Dog:
                    animalObj = new Dog();    //Late binding
                    break;

                default:
                    Debug.Assert(false, "To be completed!");
                    break;
            }

            //set the category
            animalObj.Category = CategoryType.Mammal;

            return animalObj; //return the crated animal Object
        }
예제 #3
0
        public static Mammal CreateMammal(MammalSpecies Species)
        {
            Mammal animalObj = null;//Animaltype unknown at this time.

            //Lets determine users choice of animal.
            switch (Species)
            {
            case MammalSpecies.Cat:
                animalObj = new Cat();
                break;

            case MammalSpecies.Dog:
                animalObj = new Dog();
                break;

            case MammalSpecies.Gorilla:
                animalObj = new Gorilla();
                break;

            default:
                Debug.Assert(false, "Not implemented");
                break;
            }

            //Set animal category
            animalObj.Category = CategoryType.Mammal;

            return(animalObj);//Return created instance of object.
        }
예제 #4
0
        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);
        }
예제 #5
0
        public static Mammal CreateMammal(MammalSpecies species)
        {
            Mammal animalObject = null;

            try
            {
                switch (species)
                {
                case MammalSpecies.Cat:
                    animalObject = new Cat();
                    break;

                case MammalSpecies.Dog:
                    animalObject = new Dog();
                    break;

                default:
                    Debug.Assert(false, "Not implemented yet");
                    break;
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            finally
            {
                animalObject.Category = Category.Mammal;
            }
            return(animalObject);
        }
예제 #6
0
        // Adds an animal to the list in AnimalManager(via ListManager).
        private void addAnimal(object sender, EventArgs e)
        {
            Animal animalObject;

            if (listBoxCategories.SelectedItem != null)
            {
                if (listBoxAnimalObjects.SelectedItem != null)
                {
                    CategoryType selectedCategory = getSelectedCategory();

                    /* Depending on the category selected, an animal object
                     * will be created of type Mammal or Bird, by calling either
                     * the MammalFactory or the BirdFactory. */
                    switch (selectedCategory)
                    {
                    case CategoryType.Mammal:
                        MammalSpecies mammalSpecie = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listBoxAnimalObjects.SelectedItem.ToString());
                        animalObject = MammalFactory.CreateMammal(mammalSpecie);
                        break;

                    case CategoryType.Bird:
                        BirdSpecies birdSpecie = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), listBoxAnimalObjects.SelectedItem.ToString());
                        animalObject = BirdFactory.CreateBird(birdSpecie);
                        break;

                    default:
                        animalObject = null;
                        break;
                    }

                    // If validation of entered data is successful. (validateInput returns true)
                    if (validateInput(animalObject))
                    {
                        // Generates a unique id for the animal
                        animalManager.generateUniqueId(animalObject);
                        // Adds the validated animal object to the list in ListManager.
                        animalManager.Add(animalObject);
                        listViewAnimals.Items.Add(createListViewItem(animalObject));
                        // Informs the user that everything succeeded.
                        MessageBox.Show(animalObject.Name + " has been added to the list!", "Animal has been added successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        // Resets graphical elements to their initial state.
                        initInterface();
                        unsavedChanges = true;
                    }
                }
                // If trying to add an animal with no specific animal selected.
                else
                {
                    validationNotSuccessful("Please select an animal to add");
                }
            }
            // If trying to add an animal with no category selected.
            else
            {
                validationNotSuccessful("Please select a category");
            }
        }
예제 #7
0
        public Animal CreateMammal(MammalSpecies mammalSpecies, int daysOfQuarantine, bool underQuarantine, int numberOfteeth)
        {
            Mammal animalObj = null;

            switch (mammalSpecies)
            {
            case MammalSpecies.Bear:
                animalObj = new Bear();
                break;

            case MammalSpecies.Cat:
                animalObj = new Cat();
                break;

            case MammalSpecies.Deer:
                animalObj = new Deer();
                break;

            case MammalSpecies.Lion:
                animalObj = new Lion();
                break;

            case MammalSpecies.Dog:
                animalObj = new Dog();
                break;

            case MammalSpecies.Horse:
                animalObj = new Horse();
                break;

            case MammalSpecies.Panda:
                animalObj = new Panda();
                break;

            case MammalSpecies.Wolf:
                animalObj = new Wolf();
                break;

            default:
                Debug.Assert(false, "To be completed!");
                break;
            }


            animalObj.CategoryType = CategoryType.Mammal;
            animalObj = AddNewSpecifications(animalObj, daysOfQuarantine, underQuarantine, numberOfteeth);

            return(animalObj);     //return the created animal object.
        }
        static public Mammal CreateMammal(MammalSpecies species, GenderType gender, string name, int age, int teethAmount)
        {
            switch (species)
            {
            case (MammalSpecies.Dog):
                Dog doggy = new Dog(gender, name, age, teethAmount);
                return(doggy);

            case (MammalSpecies.Cat):
                Cat catty = new Cat(gender, name, age, teethAmount);
                return(catty);

            default: return(null);
            }
        }
예제 #9
0
        /* Shows attribute(s) for the specific animal selected.
         * This function gets called when the value of the selected animal in
         * the listbox changes. */
        private void showSpecificAnimalAttributes(object sender, EventArgs e)
        {
            if (listBoxAnimalObjects.SelectedItem != null)
            {
                labelAnimalAttr.Visible   = true;
                textBoxAnimalAttr.Visible = true;
                CategoryType category = getSelectedCategory();

                switch (category)
                {
                case CategoryType.Bird:
                    BirdSpecies bird = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), listBoxAnimalObjects.SelectedItem.ToString());
                    switch (bird)
                    {
                    case BirdSpecies.Crow:
                        labelAnimalAttr.Text = "Weight(kg): ";
                        break;

                    case BirdSpecies.Eagle:
                        labelAnimalAttr.Text = "Wing spread(cm): ";
                        break;

                    case BirdSpecies.Vulture:
                        labelAnimalAttr.Text = "Neck color: ";
                        break;
                    }
                    break;

                case CategoryType.Mammal:
                    MammalSpecies mammal = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listBoxAnimalObjects.SelectedItem.ToString());
                    switch (mammal)
                    {
                    case MammalSpecies.Cat:
                        labelAnimalAttr.Text = "Whisker length(cm): ";
                        break;

                    case MammalSpecies.Dog:
                        labelAnimalAttr.Text = "Breed: ";
                        break;

                    case MammalSpecies.Lion:
                        labelAnimalAttr.Text = "Tail length(cm): ";
                        break;
                    }
                    break;
                }
            }
        }
예제 #10
0
        public static Mammal CreateMammal(MammalSpecies species, int noOfTeeth, double tailLength)
        {
            Mammal mammal = null;

            switch (species)
            {
            case MammalSpecies.Dog:
                mammal = new Dog(noOfTeeth, tailLength);
                break;

            case MammalSpecies.Elephant:
                mammal = new Elephant(noOfTeeth, tailLength);
                break;
            }
            return(mammal);
        }
예제 #11
0
        private Animal CreateMammal()
        {
            // method to read Mammal and animal type specific inputs

            Animal animal = null;

            int numOfTeeth = 0;

            if (!int.TryParse(textBoxTeeth.Text, out numOfTeeth))
            {
                MessageBox.Show("Please give a valid value for number of teeth!");
            }
            double tailLength = 0;

            if (!double.TryParse(textBoxTail.Text, out tailLength))
            {
                MessageBox.Show("Please give a valid value for tail length!");
            }

            MammalSpecies species = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listBoxAnimal.Text);

            animal = MammalFactory.CreateMammal(species, numOfTeeth, tailLength);

            if (species == MammalSpecies.Dog)
            {
                ((Dog)animal).Breed = textBoxAnimalSpec.Text;
            }

            else if (species == MammalSpecies.Cat)
            {
                ((Cat)animal).Breed = textBoxAnimalSpec.Text;
            }

            else if (species == MammalSpecies.Horse)
            {
                ((Horse)animal).Breed = textBoxAnimalSpec.Text;
            }

            return(animal);
        }
예제 #12
0
        public static Mammal CreateMammal(MammalSpecies species)
        {
            Mammal animalObj = null;//Object type not known at this time
            try
            {
                //Object type determined by late binding
                switch (species)
                {

                    case MammalSpecies.Cat:

                        animalObj = new Cat();//late binding

                        break;

                    case MammalSpecies.Dog:

                        animalObj = new Dog();//late binding

                        break;

                    default:
                        Debug.Assert(false, "To be completed!");
                        break;
                }

            }
            //custom exception
            catch (Exception e)
            {
                e.Message.ToString();
            }
            finally
            {
                //set category
                animalObj.Category = CategoryType.Mammal;
            }
            return animalObj;
        }
예제 #13
0
        public static Mammal CreateMammal(MammalSpecies species)
        {
            Mammal animalObj = null;//Object type not known at this time

            try
            {
                //Object type determined by late binding
                switch (species)
                {
                case MammalSpecies.Cat:

                    animalObj = new Cat();    //late binding

                    break;

                case MammalSpecies.Dog:

                    animalObj = new Dog();    //late binding

                    break;

                default:
                    Debug.Assert(false, "To be completed!");
                    break;
                }
            }
            //custom exception
            catch (Exception e)
            {
                e.Message.ToString();
            }
            finally
            {
                //set category
                animalObj.Category = CategoryType.Mammal;
            }
            return(animalObj);
        }
예제 #14
0
        private Animal CreateMammal()
        {
            Animal animal = null;

            int noOfTeeth = 0;

            if (!int.TryParse(txt1Species.Text, out noOfTeeth))
            {
                MessageBox.Show("Please enter a valid value as number of teeth");
            }
            double tailLength = 0;

            if (!double.TryParse(txt2Species.Text, out tailLength))
            {
                MessageBox.Show("Please enter a valid value as tail length");
            }

            MammalSpecies species = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), lstSpecies.Text);

            animal = MammalFactory.CreateMammal(species, noOfTeeth, tailLength);

            if (species == MammalSpecies.Dog)
            {
                ((Dog)animal).Breed = txtBreed.Text;
            }

            else if (species == MammalSpecies.Elephant)
            {
                int trunkLength = 0;

                if (!int.TryParse(txtBreed.Text, out trunkLength))
                {
                    MessageBox.Show("Please enter a valid trunk length");
                }
                ((Elephant)animal).TrunkLength = trunkLength;
            }
            return(animal);
        }
예제 #15
0
        // Creates and returns a mammal object of the selected animal specie
        public static Mammal CreateMammal(MammalSpecies mammalSpecie)
        {
            Animal mammalObject;

            switch (mammalSpecie)
            {
            case MammalSpecies.Cat:
                mammalObject = new Cat();
                break;

            case MammalSpecies.Dog:
                mammalObject = new Dog();
                break;

            case MammalSpecies.Lion:
                mammalObject = new Lion();
                break;

            default:
                mammalObject = null;
                break;
            }
            return((Mammal)mammalObject);
        }
예제 #16
0
        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);
        }
예제 #17
0
        private void button1_Click(object sender, EventArgs e)
        {
            //	int.TryParse(AgeTbx.Text, out int age);         //	convert Agebox Context to int, and name it age.


            if (string.IsNullOrEmpty(NameTbx.Text))
            {
                MessageBox.Show("Name should not be empty!, Please write the name of your animal",
                                "Wrong input!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error // for Warning
                                                     //MessageBoxIcon.Error // for Error
                                                     //MessageBoxIcon.Information  // for Information
                                                     //MessageBoxIcon.Question // for Question
                                );
            }

            else if (string.IsNullOrEmpty(AgeTbx.Text))
            {
                MessageBox.Show("Age should not be empty!, Please write the Age of your animal",
                                "Wrong input!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error // for Warning
                                                     //MessageBoxIcon.Error // for Error
                                                     //MessageBoxIcon.Information  // for Information
                                                     //MessageBoxIcon.Question // for Question
                                );
            }

            else if (GenderLbx.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a gender for your animal",
                                "Wrong input!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error // for Warning
                                                     //MessageBoxIcon.Error // for Error
                                                     //MessageBoxIcon.Information  // for Information
                                                     //MessageBoxIcon.Question // for Question
                                );
            }

            else if (CategoryLbx.SelectedIndex < 0)
            {
                MessageBox.Show("Please select an animal category for your animal",
                                "Wrong input!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error // for Warning
                                                     //MessageBoxIcon.Error // for Error
                                                     //MessageBoxIcon.Information  // for Information
                                                     //MessageBoxIcon.Question // for Question
                                );
            }

            else if (AnimalLbx.SelectedIndex < 0)
            {
                MessageBox.Show("Please select an Animal",
                                "Wrong input!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error // for Warning
                                                     //MessageBoxIcon.Error // for Error
                                                     //MessageBoxIcon.Information  // for Information
                                                     //MessageBoxIcon.Question // for Question
                                );
            }
            // (string.IsNullOrEmpty(AgeTbx.Text))
            //if (title == "User greeting" || title == "User name") { do stuff};

            else if (string.IsNullOrEmpty(SpcTbx.Text))
            {
                MessageBox.Show("Please select an Animal Specification",
                                "Wrong input!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error // for Warning
                                                     //MessageBoxIcon.Error // for Error
                                                     //MessageBoxIcon.Information  // for Information
                                                     //MessageBoxIcon.Question // for Question
                                );
            }
            else if (!int.TryParse(AgeTbx.Text, out int age))                   //
            {
                MessageBox.Show("Age should contain only numbers",
                                "Wrong input!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning // for Warning
                                                       //MessageBoxIcon.Error // for Error
                                                       //MessageBoxIcon.Information  // for Information
                                                       //MessageBoxIcon.Question // for Question
                                );
            }
            else if (!int.TryParse(SpcTbx.Text, out int isNumber2))
            {
                MessageBox.Show("Animal Specification should contain only numbers",
                                "Wrong input!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning // for Warning
                                                       //MessageBoxIcon.Error // for Error
                                                       //MessageBoxIcon.Information  // for Information
                                                       //MessageBoxIcon.Question // for Question
                                );
            }

            else
            {
                //int.TryParse(AgeTbx.Text, out int age);         //	convert Agebox Context to int, and name it age.
                string nameOfAnimal = this.NameTbx.Text;                        //	convert Namebox context to string and name it nameOfAnimal;

                GenderType gender = (GenderType)this.GenderLbx.SelectedIndex;


                int id = this.CategoryLbx.SelectedIndex;                        //	choose the classes under the selected index in category list box.
                switch (id)
                {
                case (int)AnimalCategory.Mammal:                                                           //	when mammal

                    int.TryParse(SpcTbx.Text, out int teeth);                                              // convert T1 Context to int, and name it teeth.
                    MammalSpecies species = (MammalSpecies)AnimalLbx.SelectedIndex;                        //we cast the index of animal list box to mammel species.

                    Mammal mammal = MammalFactory.CreateMammal(species, gender, nameOfAnimal, age, teeth); //Create obj Mammal

                    am.AddAnimal(mammal);                                                                  //Add Animal mammal to our list(Animal Manager).


                    break;


                case (int)AnimalCategory.Bird:                                                     //when bird
                    int.TryParse(SpcTbx.Text, out int wing);                                       //	convert T2 Context to int, and name it wing.

                    BirdSpecies species2 = (BirdSpecies)this.AnimalLbx.SelectedIndex;              //we cast the index of animal list box to bird species.

                    Bird bird = BirdFactory.CreateBird(species2, gender, nameOfAnimal, age, wing); //Create obj Bird
                    am.AddAnimal(bird);


                    break;
                }

                UpdateListbox();
            }
        }