Solved

Move some code to make it work.

Posted on 2009-07-10
6
151 Views
Last Modified: 2012-05-07
I have a problem with my project. I dont know how to move some stuff to make it ok

I want my Animal properites to be in the IAnimal interface

I also would like that the propertie speed  not to be in the Animal class but only to be in the Horse class.

How do I do this?


Here is the project (need to wait 80 sec)
http://uploading.com/files/MNUA20T3/Modul2.zip.html

IANIMAL.CS

----------------------------------

using System;

using System.Collections.Generic;

using System.Text;
 

namespace Animals

{   

    /// <summary>

    /// IAnimal Interface

    /// </summary>

    public interface IAnimal

    { 
 

        /// <summary>

        /// Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        String eat(String food);
 

        /// <summary>

        /// set the ID number

        /// </summary>

        /// <param name="id"></param>

        void setIDNumber(String id);
 
 

        /// <summary>

        /// set the Name

        /// </summary>

        /// <param name="name"></param>

        void setName(String name);
 
 

        /// <summary>

        /// set the NumberofLegs

        /// </summary>

        /// <param name="numOfLegs"></param>

        void setNumberOfLegs(int numOfLegs);
 

    } //end interface

} //end namespace
 
 
 

----------------------------

ANIMAL.CS

----------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;
 

namespace Animals

{
 

    /// <summary>

    /// Class Animal

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Animal))]

    [XmlInclude(typeof(MeatEater))]

    [XmlInclude(typeof(PlantEater))]

    [XmlInclude(typeof(Dog))]

    [XmlInclude(typeof(Giraffe))]

    [XmlInclude(typeof(Horse))]

    [XmlInclude(typeof(Wolf))]

    [XmlInclude(typeof(Duck))]

    [XmlInclude(typeof(Tiger))]

    [XmlInclude(typeof(Lion))]

    [XmlInclude(typeof(Rabbit))]

    [XmlInclude(typeof(Donkey))]

    [XmlInclude(typeof(Cow))]

    public abstract class Animal: IAnimal

    {
 

        #region Deklaration
 

        [XmlAttribute]

        private String name;

        private String IDNumber;

        private int numberOfLegs;

        private HousingType livesIn;

        private String category;

        private String type;

        private String speed;

        private bool isAggressive;
 

        #endregion
 
 
 

        #region Konstruktor
 

        /// <summary>

        /// Animal Konstruktor

        /// </summary>

        public Animal()

        {

            this.name = String.Empty;

            this.IDNumber = String.Empty;

            this.numberOfLegs = 0;

            HousingType house = new HousingType();

            this.livesIn = house;

            this.category = String.Empty;

            this.type = String.Empty;

            this.speed = String.Empty;

            this.isAggressive = false;

        } //end Animal
 
 
 

        /// <summary>

        /// Konstruktor till Animal

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="numberOfLegs"></param>

        /// <param name="livesIn"></param>

        /// <param name="category"></param>

        /// <param name="type"></param>

        public Animal(String name, String ID, int numberOfLegs, HousingType livesIn, String category, String type, String speed, bool isAggressive)

        {

            this.name = name;

            this.IDNumber =ID;

            this.numberOfLegs = numberOfLegs;

            this.livesIn = livesIn;

            this.category = category;

            this.type = type;

            this.speed = speed;

            this.isAggressive = isAggressive;

        } //end Animal
 

        #endregion
 
 

        #region Egenskaper
 
 

        /// <summary>

        /// Gets and Sets Name

        /// </summary>

        public String Name

        {

            set { name = value; }

            get { return name; }

        } //end Name
 

        

        /// <summary>

        /// Gets and Sets Speed

        /// </summary>

        public String Speed

        {

            set { speed = value; }

            get { return speed; }

        } //end speed
 
 

        /// <summary>

        /// Gets ID

        /// </summary>

        public String ID

        {

            get { return IDNumber; }

        } //end getID
 
 
 

        /// <summary>

        /// Gets NumberOfLegs

        /// </summary>

        public int NumberOfLegs

        {

            get { return numberOfLegs; }

        } //end getNumberOfLegs
 
 
 

        /// <summary>

        /// Gets Housing

        /// </summary>

        public HousingType Housing

        {

            get { return livesIn; }

        } //end getHousing
 
 

        /// <summary>

        /// Sets and gets Aggressive

        /// </summary>

        public bool Aggressive

        {

            set { isAggressive = value; }

            get { return isAggressive; }

        } //end Aggressive
 
 

        /// <summary>

        /// Sets Housing

        /// </summary>

        public HousingType setHousing

        {

            set { livesIn = value; }

        } //end setHousing
 
 
 

        /// <summary>

        /// Gets and Sets Category

        /// </summary>

        public String Category

        {

            get { return category; }

            set { category = value; }

        } //end Category
 
 
 

        /// <summary>

        /// Gets and sets Typ

        /// </summary>

        public String Typ

        {

            get { return type; }

            set { type = value; }

        } //end Typ
 

        #endregion
 
 

        #region IAnimal Members
 
 

        /// <summary>

        /// Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        public virtual string eat(string food)

        {

            return "Animal eat method";

        } //end eat
 
 
 

        /// <summary>

        /// Sets Id number

        /// </summary>

        /// <param name="id"></param>

        void IAnimal.setIDNumber(string id)

        {

            this.IDNumber = id;

        } //end setIDNumber
 
 

        /// <summary>

        /// Sets Name

        /// </summary>

        /// <param name="name"></param>

        void IAnimal.setName(string name)

        {

            this.name = name;

        } //end setName
 
 
 

        /// <summary>

        /// Sets number of legs

        /// </summary>

        /// <param name="numOfLegs"></param>

        void IAnimal.setNumberOfLegs(int numOfLegs)

        {

            this.numberOfLegs = numOfLegs;

        } //end setNumberOfLegs
 

        #endregion
 
 

        #region Metoder
 
 

        /// <summary>

        /// Print

        /// </summary>

        /// <returns></returns>

        public abstract String toString();

      
 

        #endregion
 
 

       

    } //end class

} //end namespace
 
 
 
 

--------------------------------

PLANTEATER.cs

--------------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;
 
 

namespace Animals

{

    /// <summary>

    /// PlantEater class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(PlantEater))] 

    public abstract class  PlantEater : Animal

    {
 

        #region Deklaration
 

        [XmlAttribute]

        protected List<string> likes;

        protected const String category = "PlantEater";
 

        #endregion
 

        #region Konstruktor
 

        /// <summary>

        /// PlantEater konstruktor

        /// </summary>

        public PlantEater()

        { }
 
 

        /// <summary>

        /// Konstruktor PlantEater

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="numberOfLegs"></param>

        /// <param name="housing"></param>

        /// <param name="type"></param>

        public PlantEater(String name, String ID, int numberOfLegs, HousingType housing, String type, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, category, type, speed, aggressive)

        {

            likes = new List<string>();

            likes.Add("Leaves");

        } //end PlantEater
 

        #endregion
 
 
 

        #region Methods
 

        /// <summary>

        /// Does it like it? Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        public override String eat(string food)

        {

            foreach (string eat in likes)

            {

                if (eat.ToLower() == food.ToLower())

                {

                    return "Yummy";

                } //end if

            } //end foreach
 

            return "Uuuusccccccch";

        } //end eat
 
 
 

        /// <summary>

        /// Print

        /// </summary>

        /// <returns></returns>

        public override String toString()

        {            

            return "MeatEeater klassen toString";

        } //end ToString
 

        #endregion
 
 

    } //end class

} //end namespace
 
 

--------------------------------------

Dog.cs

------------------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;
 
 

namespace Animals

{

    /// <summary>

    /// Dog Class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Dog))] 

    public class Dog : MeatEater

    {

        #region Deklaration
 

        [XmlAttribute]          

        private const int numberOfLegs = 4;

        private const String classDog = "Dog";
 

        #endregion
 

        #region Konstruktor
 

        /// <summary>

        /// Dog Konstruktor

        /// </summary>

        public Dog()

        {}
 
 
 

        /// <summary>

        /// Dog Konstruktor

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="housing"></param>

        public Dog(String name, String ID, HousingType housing, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, classDog, speed, aggressive)

        {

            likes.Add("Cats");

        } //end Dog
 

        #endregion
 

    } //end class

} //end namespace
 
 

------------------------------------

HORSE.cs

-----------------------------------
 

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;
 

namespace Animals

{
 

    /// <summary>

    /// Horse Class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Horse))] 

    public class Horse : PlantEater

    {
 

        #region Deklaration
 

        [XmlAttribute]

        private const int numberOfLegs = 4;

        private const String classHorse = "Horse";
 

        #endregion
 

        #region Konstruktor
 

        /// <summary>

        /// Horse Konstruktor

        /// </summary>

        public Horse()

        { }
 

        /// <summary>

        /// Konstruktor Horse

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="housing"></param>

        public Horse(String name, String ID, HousingType housing, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, classHorse, speed, aggressive)

        {

            likes.Add("Hö");

        } //end Horse
 

        #endregion
 
 

    } //end class

} //end namespace

Open in new window

0
Comment
Question by:Mickeys
  • 4
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24829655
i have moved the number of legs prop into the iAnimalInterface , similarly u can do for others also
IANIMAL.CS

----------------------------------

using System;

using System.Collections.Generic;

using System.Text;

 

namespace Animals

{   

    /// <summary>

    /// IAnimal Interface

    /// </summary>

    public interface IAnimal

    { 

 

        int NumberOfLegs

        {

            get ;

        } 

        /// <summary>

        /// Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        String eat(String food);

 

        /// <summary>

        /// set the ID number

        /// </summary>

        /// <param name="id"></param>

        void setIDNumber(String id);

 

 

        /// <summary>

        /// set the Name

        /// </summary>

        /// <param name="name"></param>

        void setName(String name);

 

 

        /// <summary>

        /// set the NumberofLegs

        /// </summary>

        /// <param name="numOfLegs"></param>

        void setNumberOfLegs(int numOfLegs);

 

    } //end interface

} //end namespace

 

 

 

----------------------------

ANIMAL.CS

----------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;

 

namespace Animals

{

 

    /// <summary>

    /// Class Animal

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Animal))]

    [XmlInclude(typeof(MeatEater))]

    [XmlInclude(typeof(PlantEater))]

    [XmlInclude(typeof(Dog))]

    [XmlInclude(typeof(Giraffe))]

    [XmlInclude(typeof(Horse))]

    [XmlInclude(typeof(Wolf))]

    [XmlInclude(typeof(Duck))]

    [XmlInclude(typeof(Tiger))]

    [XmlInclude(typeof(Lion))]

    [XmlInclude(typeof(Rabbit))]

    [XmlInclude(typeof(Donkey))]

    [XmlInclude(typeof(Cow))]

    public abstract class Animal: IAnimal

    {

 

        #region Deklaration

 

        [XmlAttribute]

        private String name;

        private String IDNumber;

        private int numberOfLegs;

        private HousingType livesIn;

        private String category;

        private String type;

        private String speed;

        private bool isAggressive;

 

        #endregion

 

 

 

        #region Konstruktor

 

        /// <summary>

        /// Animal Konstruktor

        /// </summary>

        public Animal()

        {

            this.name = String.Empty;

            this.IDNumber = String.Empty;

            this.numberOfLegs = 0;

            HousingType house = new HousingType();

            this.livesIn = house;

            this.category = String.Empty;

            this.type = String.Empty;

            this.speed = String.Empty;

            this.isAggressive = false;

        } //end Animal

 

 

 

        /// <summary>

        /// Konstruktor till Animal

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="numberOfLegs"></param>

        /// <param name="livesIn"></param>

        /// <param name="category"></param>

        /// <param name="type"></param>

        public Animal(String name, String ID, int numberOfLegs, HousingType livesIn, String category, String type, String speed, bool isAggressive)

        {

            this.name = name;

            this.IDNumber =ID;

            this.numberOfLegs = numberOfLegs;

            this.livesIn = livesIn;

            this.category = category;

            this.type = type;

            this.speed = speed;

            this.isAggressive = isAggressive;

        } //end Animal

 

        #endregion

 

 

        #region Egenskaper

 

 

        /// <summary>

        /// Gets and Sets Name

        /// </summary>

        public String Name

        {

            set { name = value; }

            get { return name; }

        } //end Name

 

        

        /// <summary>

        /// Gets and Sets Speed

        /// </summary>

        public String Speed

        {

            set { speed = value; }

            get { return speed; }

        } //end speed

 

 

        /// <summary>

        /// Gets ID

        /// </summary>

        public String ID

        {

            get { return IDNumber; }

        } //end getID

 

 

 

        /// <summary>

        /// Gets NumberOfLegs

        /// </summary>

        public int NumberOfLegs

        {

            get { return numberOfLegs; }

        } //end getNumberOfLegs

 

 

 

        /// <summary>

        /// Gets Housing

        /// </summary>

        public HousingType Housing

        {

            get { return livesIn; }

        } //end getHousing

 

 

        /// <summary>

        /// Sets and gets Aggressive

        /// </summary>

        public bool Aggressive

        {

            set { isAggressive = value; }

            get { return isAggressive; }

        } //end Aggressive

 

 

        /// <summary>

        /// Sets Housing

        /// </summary>

        public HousingType setHousing

        {

            set { livesIn = value; }

        } //end setHousing

 

 

 

        /// <summary>

        /// Gets and Sets Category

        /// </summary>

        public String Category

        {

            get { return category; }

            set { category = value; }

        } //end Category

 

 

 

        /// <summary>

        /// Gets and sets Typ

        /// </summary>

        public String Typ

        {

            get { return type; }

            set { type = value; }

        } //end Typ

 

        #endregion

 

 

        #region IAnimal Members

 

 

        /// <summary>

        /// Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        public virtual string eat(string food)

        {

            return "Animal eat method";

        } //end eat

 

 

 

        /// <summary>

        /// Sets Id number

        /// </summary>

        /// <param name="id"></param>

        void IAnimal.setIDNumber(string id)

        {

            this.IDNumber = id;

        } //end setIDNumber

 

 

        /// <summary>

        /// Sets Name

        /// </summary>

        /// <param name="name"></param>

        void IAnimal.setName(string name)

        {

            this.name = name;

        } //end setName

 

 

 

        /// <summary>

        /// Sets number of legs

        /// </summary>

        /// <param name="numOfLegs"></param>

        void IAnimal.setNumberOfLegs(int numOfLegs)

        {

            this.numberOfLegs = numOfLegs;

        } //end setNumberOfLegs

 

        #endregion

 

 

        #region Metoder

 

 

        /// <summary>

        /// Print

        /// </summary>

        /// <returns></returns>

        public abstract String toString();

      

 

        #endregion

 

 

       

    } //end class

} //end namespace

 

 

 

 

--------------------------------

PLANTEATER.cs

--------------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;

 

 

namespace Animals

{

    /// <summary>

    /// PlantEater class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(PlantEater))] 

    public abstract class  PlantEater : Animal

    {

 

        #region Deklaration

 

        [XmlAttribute]

        protected List<string> likes;

        protected const String category = "PlantEater";

 

        #endregion

 

        #region Konstruktor

 

        /// <summary>

        /// PlantEater konstruktor

        /// </summary>

        public PlantEater()

        { }

 

 

        /// <summary>

        /// Konstruktor PlantEater

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="numberOfLegs"></param>

        /// <param name="housing"></param>

        /// <param name="type"></param>

        public PlantEater(String name, String ID, int numberOfLegs, HousingType housing, String type, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, category, type, speed, aggressive)

        {

            likes = new List<string>();

            likes.Add("Leaves");

        } //end PlantEater

 

        #endregion

 

 

 

        #region Methods

 

        /// <summary>

        /// Does it like it? Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        public override String eat(string food)

        {

            foreach (string eat in likes)

            {

                if (eat.ToLower() == food.ToLower())

                {

                    return "Yummy";

                } //end if

            } //end foreach

 

            return "Uuuusccccccch";

        } //end eat

 

 

 

        /// <summary>

        /// Print

        /// </summary>

        /// <returns></returns>

        public override String toString()

        {            

            return "MeatEeater klassen toString";

        } //end ToString

 

        #endregion

 

 

    } //end class

} //end namespace

 

 

--------------------------------------

Dog.cs

------------------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;

 

 

namespace Animals

{

    /// <summary>

    /// Dog Class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Dog))] 

    public class Dog : MeatEater

    {

        #region Deklaration

 

        [XmlAttribute]          

        private const int numberOfLegs = 4;

        private const String classDog = "Dog";

 

        #endregion

 

        #region Konstruktor

 

        /// <summary>

        /// Dog Konstruktor

        /// </summary>

        public Dog()

        {}

 

 

 

        /// <summary>

        /// Dog Konstruktor

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="housing"></param>

        public Dog(String name, String ID, HousingType housing, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, classDog, speed, aggressive)

        {

            likes.Add("Cats");

        } //end Dog

 

        #endregion

 

    } //end class

} //end namespace

 

 

------------------------------------

HORSE.cs

-----------------------------------

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;

 

namespace Animals

{

 

    /// <summary>

    /// Horse Class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Horse))] 

    public class Horse : PlantEater

    {

 

        #region Deklaration

 

        [XmlAttribute]

        private const int numberOfLegs = 4;

        private const String classHorse = "Horse";

 

        #endregion

 

        #region Konstruktor

 

        /// <summary>

        /// Horse Konstruktor

        /// </summary>

        public Horse()

        { }

 

        /// <summary>

        /// Konstruktor Horse

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="housing"></param>

        public Horse(String name, String ID, HousingType housing, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, classHorse, speed, aggressive)

        {

            likes.Add("Hö");

        } //end Horse

 

        #endregion

 

 

    } //end class

} //end namespace

Open in new window

0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24829660
>>> I also would like that the propertie speed  not to be in the Animal class but only to be in the Horse class.
if u are inherting both animal and horse from the IAnimal Interface then the speed property will be there in both classes. what u can do is where u dont want it throw a not implemented exception..


0
 

Author Comment

by:Mickeys
ID: 24829781
Ok I managed to move the code.

But the other thing about speed I dont know how to do. Could you show me how to throw?

The instructions are like this:
Declare a private field, speed, in the Horse class. Write get- and set properties connected to
this variable. The value should be visible on the GUI as shown in the run example above.


I guess I did it in alittle diffrent way (and it worked) but they were not happy about that. :-/
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24829799

IANIMAL.CS

----------------------------------

using System;

using System.Collections.Generic;

using System.Text;

 

namespace Animals

{   

    /// <summary>

    /// IAnimal Interface

    /// </summary>

    public interface IAnimal

    { 

         public String Speed

        {

            set ;

            get ;

        } //end speed
 

        int NumberOfLegs

        {

            get ;

        } 

        /// <summary>

        /// Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        String eat(String food);

 

        /// <summary>

        /// set the ID number

        /// </summary>

        /// <param name="id"></param>

        void setIDNumber(String id);

 

 

        /// <summary>

        /// set the Name

        /// </summary>

        /// <param name="name"></param>

        void setName(String name);

 

 

        /// <summary>

        /// set the NumberofLegs

        /// </summary>

        /// <param name="numOfLegs"></param>

        void setNumberOfLegs(int numOfLegs);

 

    } //end interface

} //end namespace

 

 

 

----------------------------

ANIMAL.CS

----------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;

 

namespace Animals

{

 

    /// <summary>

    /// Class Animal

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Animal))]

    [XmlInclude(typeof(MeatEater))]

    [XmlInclude(typeof(PlantEater))]

    [XmlInclude(typeof(Dog))]

    [XmlInclude(typeof(Giraffe))]

    [XmlInclude(typeof(Horse))]

    [XmlInclude(typeof(Wolf))]

    [XmlInclude(typeof(Duck))]

    [XmlInclude(typeof(Tiger))]

    [XmlInclude(typeof(Lion))]

    [XmlInclude(typeof(Rabbit))]

    [XmlInclude(typeof(Donkey))]

    [XmlInclude(typeof(Cow))]

    public abstract class Animal: IAnimal

    {

 

        #region Deklaration

 

        [XmlAttribute]

        private String name;

        private String IDNumber;

        private int numberOfLegs;

        private HousingType livesIn;

        private String category;

        private String type;

        private bool isAggressive;

 

        #endregion

 

 

 

        #region Konstruktor

 

        /// <summary>

        /// Animal Konstruktor

        /// </summary>

        public Animal()

        {

            this.name = String.Empty;

            this.IDNumber = String.Empty;

            this.numberOfLegs = 0;

            HousingType house = new HousingType();

            this.livesIn = house;

            this.category = String.Empty;

            this.type = String.Empty;

            this.speed = String.Empty;

            this.isAggressive = false;

        } //end Animal

 

 

 

        /// <summary>

        /// Konstruktor till Animal

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="numberOfLegs"></param>

        /// <param name="livesIn"></param>

        /// <param name="category"></param>

        /// <param name="type"></param>

        public Animal(String name, String ID, int numberOfLegs, HousingType livesIn, String category, String type, String speed, bool isAggressive)

        {

            this.name = name;

            this.IDNumber =ID;

            this.numberOfLegs = numberOfLegs;

            this.livesIn = livesIn;

            this.category = category;

            this.type = type;

            this.speed = speed;

            this.isAggressive = isAggressive;

        } //end Animal

 

        #endregion

 

 

        #region Egenskaper

 

 

        /// <summary>

        /// Gets and Sets Name

        /// </summary>

        public String Name

        {

            set { name = value; }

            get { return name; }

        } //end Name

 

        

        /// <summary>

        /// Gets and Sets Speed

        /// </summary>

        public virtual String Speed

        {

            set { throw new NotImplementedException(); }

            get { throw new NotImplementedException(); }

        } //end speed

 

 

        /// <summary>

        /// Gets ID

        /// </summary>

        public String ID

        {

            get { return IDNumber; }

        } //end getID

 

 

 

        /// <summary>

        /// Gets NumberOfLegs

        /// </summary>

        public int NumberOfLegs

        {

            get { return numberOfLegs; }

        } //end getNumberOfLegs

 

 

 

        /// <summary>

        /// Gets Housing

        /// </summary>

        public HousingType Housing

        {

            get { return livesIn; }

        } //end getHousing

 

 

        /// <summary>

        /// Sets and gets Aggressive

        /// </summary>

        public bool Aggressive

        {

            set { isAggressive = value; }

            get { return isAggressive; }

        } //end Aggressive

 

 

        /// <summary>

        /// Sets Housing

        /// </summary>

        public HousingType setHousing

        {

            set { livesIn = value; }

        } //end setHousing

 

 

 

        /// <summary>

        /// Gets and Sets Category

        /// </summary>

        public String Category

        {

            get { return category; }

            set { category = value; }

        } //end Category

 

 

 

        /// <summary>

        /// Gets and sets Typ

        /// </summary>

        public String Typ

        {

            get { return type; }

            set { type = value; }

        } //end Typ

 

        #endregion

 

 

        #region IAnimal Members

 

 

        /// <summary>

        /// Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        public virtual string eat(string food)

        {

            return "Animal eat method";

        } //end eat

 

 

 

        /// <summary>

        /// Sets Id number

        /// </summary>

        /// <param name="id"></param>

        void IAnimal.setIDNumber(string id)

        {

            this.IDNumber = id;

        } //end setIDNumber

 

 

        /// <summary>

        /// Sets Name

        /// </summary>

        /// <param name="name"></param>

        void IAnimal.setName(string name)

        {

            this.name = name;

        } //end setName

 

 

 

        /// <summary>

        /// Sets number of legs

        /// </summary>

        /// <param name="numOfLegs"></param>

        void IAnimal.setNumberOfLegs(int numOfLegs)

        {

            this.numberOfLegs = numOfLegs;

        } //end setNumberOfLegs

 

        #endregion

 

 

        #region Metoder

 

 

        /// <summary>

        /// Print

        /// </summary>

        /// <returns></returns>

        public abstract String toString();

      

 

        #endregion

 

 

       

    } //end class

} //end namespace

 

 

 

 

--------------------------------

PLANTEATER.cs

--------------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;

 

 

namespace Animals

{

    /// <summary>

    /// PlantEater class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(PlantEater))] 

    public abstract class  PlantEater : Animal

    {

 

        #region Deklaration

 

        [XmlAttribute]

        protected List<string> likes;

        protected const String category = "PlantEater";

 

        #endregion

 

        #region Konstruktor

 

        /// <summary>

        /// PlantEater konstruktor

        /// </summary>

        public PlantEater()

        { }

 

 

        /// <summary>

        /// Konstruktor PlantEater

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="numberOfLegs"></param>

        /// <param name="housing"></param>

        /// <param name="type"></param>

        public PlantEater(String name, String ID, int numberOfLegs, HousingType housing, String type, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, category, type, speed, aggressive)

        {

            likes = new List<string>();

            likes.Add("Leaves");

        } //end PlantEater

 

        #endregion

 

 

 

        #region Methods

 

        /// <summary>

        /// Does it like it? Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        public override String eat(string food)

        {

            foreach (string eat in likes)

            {

                if (eat.ToLower() == food.ToLower())

                {

                    return "Yummy";

                } //end if

            } //end foreach

 

            return "Uuuusccccccch";

        } //end eat

 

 

 

        /// <summary>

        /// Print

        /// </summary>

        /// <returns></returns>

        public override String toString()

        {            

            return "MeatEeater klassen toString";

        } //end ToString

 

        #endregion

 

 

    } //end class

} //end namespace

 

 

--------------------------------------

Dog.cs

------------------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;

 

 

namespace Animals

{

    /// <summary>

    /// Dog Class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Dog))] 

    public class Dog : MeatEater

    {

        #region Deklaration

 

        [XmlAttribute]          

        private const int numberOfLegs = 4;

        private const String classDog = "Dog";

 

        #endregion

 

        #region Konstruktor

 

        /// <summary>

        /// Dog Konstruktor

        /// </summary>

        public Dog()

        {}

 

 

 

        /// <summary>

        /// Dog Konstruktor

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="housing"></param>

        public Dog(String name, String ID, HousingType housing, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, classDog, speed, aggressive)

        {

            likes.Add("Cats");

        } //end Dog

 

        #endregion

 

    } //end class

} //end namespace

 

 

------------------------------------

HORSE.cs

-----------------------------------

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;

 

namespace Animals

{

 

    /// <summary>

    /// Horse Class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Horse))] 

    public class Horse : PlantEater

    {

 

        string speed;

        #region Deklaration

 

        [XmlAttribute]

        private const int numberOfLegs = 4;

        private const String classHorse = "Horse";

 

        #endregion

 

        #region Konstruktor

 

        /// <summary>

        /// Horse Konstruktor

        /// </summary>

        public Horse()

        { }
 

        public override string Speed

        {

            set { speed = value; }

            get { return speed; }
 

        }

 

        /// <summary>

        /// Konstruktor Horse

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="housing"></param>

        public Horse(String name, String ID, HousingType housing, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, classHorse, speed, aggressive)

        {

            likes.Add("Hö");

        } //end Horse

 

        #endregion

 

 

    } //end class

} //end namespace

Open in new window

0
 

Author Comment

by:Mickeys
ID: 24829834
dont work. I get a error message when running the program saying not implemented.

I guess that is what you where after? But that wont be good. Then the hole program stops!

I want only speed to be in horse class....and when in other classes it should just ignore it.

See pic and code
IAnimal.cs

------------------------
 

using System;

using System.Collections.Generic;

using System.Text;
 

namespace Animals

{   

    /// <summary>

    /// IAnimal Interface

    /// </summary>

    public interface IAnimal

    { 
 

        /// <summary>

        /// Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        String eat(String food);
 

        /// <summary>

        /// set the ID number

        /// </summary>

        /// <param name="id"></param>

        void setIDNumber(String id);
 
 

        /// <summary>

        /// Gets ID

        /// </summary>

        String ID

        {

            get;

        } //end getID
 

        /// <summary>

        /// set the Name

        /// </summary>

        /// <param name="name"></param>

        void setName(String name);
 

        /// <summary>

        /// 

        /// </summary>

        int NumberOfLegs

        {

            get;

        } 
 
 

        /// <summary>

        /// set the NumberofLegs

        /// </summary>

        /// <param name="numOfLegs"></param>

        void setNumberOfLegs(int numOfLegs);
 
 

        

        /// <summary>

        /// Gets and Sets Name

        /// </summary>

        String Name

        {

            get;

        } //end Name
 
 

        /// <summary>

        /// Gets and Sets Speed

        /// </summary>

        String Speed

        {

            set;

            get;

        } //end speed
 
 
 
 
 
 

        /// <summary>

        /// Gets Housing

        /// </summary>

        HousingType Housing

        {

            get;

        } //end getHousing
 
 

        /// <summary>

        /// Sets and gets Aggressive

        /// </summary>

        bool Aggressive

        {

            set;

            get;

        } //end Aggressive
 
 

        /// <summary>

        /// Sets Housing

        /// </summary>

        HousingType setHousing

        {

            set;

        } //end setHousing
 
 
 

        /// <summary>

        /// Gets and Sets Category

        /// </summary>

        String Category

        {

            get;

            set;

        } //end Category
 
 
 

        /// <summary>

        /// Gets and sets Typ

        /// </summary>

        String Typ

        {

            get;

            set;

        } //end Typ

    } //end interface

} //end namespace
 
 
 

ANIMAL.cs

---------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;
 

namespace Animals

{
 

    /// <summary>

    /// Class Animal

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Animal))]

    [XmlInclude(typeof(MeatEater))]

    [XmlInclude(typeof(PlantEater))]

    [XmlInclude(typeof(Dog))]

    [XmlInclude(typeof(Giraffe))]

    [XmlInclude(typeof(Horse))]

    [XmlInclude(typeof(Wolf))]

    [XmlInclude(typeof(Duck))]

    [XmlInclude(typeof(Tiger))]

    [XmlInclude(typeof(Lion))]

    [XmlInclude(typeof(Rabbit))]

    [XmlInclude(typeof(Donkey))]

    [XmlInclude(typeof(Cow))]

    public abstract class Animal: IAnimal

    {
 

        #region Deklaration
 

        [XmlAttribute]

        private String name;

        private String IDNumber;

        private int numberOfLegs;

        private HousingType livesIn;

        private String category;

        private String type;

        private bool isAggressive;
 

        #endregion
 
 
 

        #region Konstruktor
 

        /// <summary>

        /// Animal Konstruktor

        /// </summary>

        public Animal()

        {

            this.name = String.Empty;

            this.IDNumber = String.Empty;

            this.numberOfLegs = 0;

            HousingType house = new HousingType();

            this.livesIn = house;

            this.category = String.Empty;

            this.type = String.Empty;

            this.isAggressive = false;

        } //end Animal
 
 
 

        /// <summary>

        /// Konstruktor till Animal

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="numberOfLegs"></param>

        /// <param name="livesIn"></param>

        /// <param name="category"></param>

        /// <param name="type"></param>

        public Animal(String name, String ID, int numberOfLegs, HousingType livesIn, String category, String type, String speed, bool isAggressive)

        {

            this.name = name;

            this.IDNumber =ID;

            this.numberOfLegs = numberOfLegs;

            this.livesIn = livesIn;

            this.category = category;

            this.type = type;

            this.isAggressive = isAggressive;

        } //end Animal
 

        #endregion
 
 

        #region Egenskaper
 
 

        /// <summary>

        /// Gets and Sets Name

        /// </summary>

        public String Name

        {

            set { name = value; }

            get { return name; }

        } //end Name
 

        

        /// <summary>

        /// Gets and Sets Speed

        /// </summary>

        //public String Speed

        //{

        //    set { speed = value; }

        //    get { return speed; }

        //} //end speed
 

        /// <summary>

        /// Gets and Sets Speed

        /// </summary>

        public virtual String Speed

        {

            set { throw new NotImplementedException(); }

            get { throw new NotImplementedException(); }

        } //end speed
 
 
 

        /// <summary>

        /// Gets ID

        /// </summary>

        public String ID

        {

            get { return IDNumber; }

        } //end getID
 
 
 

        /// <summary>

        /// Gets NumberOfLegs

        /// </summary>

        public int NumberOfLegs

        {

            get { return numberOfLegs; }

        } //end getNumberOfLegs
 
 
 

        /// <summary>

        /// Gets Housing

        /// </summary>

        public HousingType Housing

        {

            get { return livesIn; }

        } //end getHousing
 
 

        /// <summary>

        /// Sets and gets Aggressive

        /// </summary>

        public bool Aggressive

        {

            set { isAggressive = value; }

            get { return isAggressive; }

        } //end Aggressive
 
 

        /// <summary>

        /// Sets Housing

        /// </summary>

        public HousingType setHousing

        {

            set { livesIn = value; }

        } //end setHousing
 
 
 

        /// <summary>

        /// Gets and Sets Category

        /// </summary>

        public String Category

        {

            get { return category; }

            set { category = value; }

        } //end Category
 
 
 

        /// <summary>

        /// Gets and sets Typ

        /// </summary>

        public String Typ

        {

            get { return type; }

            set { type = value; }

        } //end Typ
 

        #endregion
 
 

        #region IAnimal Members
 
 

        /// <summary>

        /// Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        public virtual string eat(string food)

        {

            return "Animal eat method";

        } //end eat
 
 
 

        /// <summary>

        /// Sets Id number

        /// </summary>

        /// <param name="id"></param>

        void IAnimal.setIDNumber(string id)

        {

            this.IDNumber = id;

        } //end setIDNumber
 
 

        /// <summary>

        /// Sets Name

        /// </summary>

        /// <param name="name"></param>

        void IAnimal.setName(string name)

        {

            this.name = name;

        } //end setName
 
 
 

        /// <summary>

        /// Sets number of legs

        /// </summary>

        /// <param name="numOfLegs"></param>

        void IAnimal.setNumberOfLegs(int numOfLegs)

        {

            this.numberOfLegs = numOfLegs;

        } //end setNumberOfLegs
 

        #endregion
 
 

        #region Metoder
 
 

        /// <summary>

        /// Print

        /// </summary>

        /// <returns></returns>

        public abstract String toString();

      
 

        #endregion
 
 

       

    } //end class

} //end namespace
 
 
 
 

PLANTEATER.CS

-----------------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;
 
 

namespace Animals

{

    /// <summary>

    /// PlantEater class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(PlantEater))] 

    public abstract class  PlantEater : Animal

    {
 

        #region Deklaration
 

        [XmlAttribute]

        protected List<string> likes;

        protected const String category = "PlantEater";
 

        #endregion
 

        #region Konstruktor
 

        /// <summary>

        /// PlantEater konstruktor

        /// </summary>

        public PlantEater()

        { }
 
 

        /// <summary>

        /// Konstruktor PlantEater

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="numberOfLegs"></param>

        /// <param name="housing"></param>

        /// <param name="type"></param>

        public PlantEater(String name, String ID, int numberOfLegs, HousingType housing, String type, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, category, type, speed, aggressive)

        {

            likes = new List<string>();

            likes.Add("Leaves");

        } //end PlantEater
 

        #endregion
 
 
 

        #region Methods
 

        /// <summary>

        /// Does it like it? Eat method

        /// </summary>

        /// <param name="food"></param>

        /// <returns></returns>

        public override String eat(string food)

        {

            foreach (string eat in likes)

            {

                if (eat.ToLower() == food.ToLower())

                {

                    return "Yummy";

                } //end if

            } //end foreach
 

            return "Uuuusccccccch";

        } //end eat
 
 
 

        /// <summary>

        /// Print

        /// </summary>

        /// <returns></returns>

        public override String toString()

        {            

            return "MeatEeater klassen toString";

        } //end ToString
 

        #endregion
 
 

    } //end class

} //end namespace
 
 

HORSE.CS

-------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;
 

namespace Animals

{
 

    /// <summary>

    /// Horse Class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Horse))] 

    public class Horse : PlantEater

    {
 

        #region Deklaration
 

        [XmlAttribute]

        private const int numberOfLegs = 4;

        private const String classHorse = "Horse";

        string speed = "0";
 
 

        #endregion
 

        #region Konstruktor
 

        /// <summary>

        /// Horse Konstruktor

        /// </summary>

        public Horse()

        { }
 

        /// <summary>

        /// Konstruktor Horse

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="housing"></param>

        public Horse(String name, String ID, HousingType housing, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, classHorse, speed, aggressive)

        {

            likes.Add("Hö");

        } //end Horse
 

        #endregion
 

#region Egenskaper

        public override string Speed

        {

            set { speed = value; }

            get { return speed; }

 

        }
 

#endregion

    } //end class

} //end namespace
 
 
 
 
 

DOG.CS

-----------------------

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Xml.Serialization;

using System.IO;
 
 

namespace Animals

{

    /// <summary>

    /// Dog Class

    /// </summary>

    [Serializable]

    [XmlInclude(typeof(Dog))] 

    public class Dog : MeatEater

    {

        #region Deklaration
 

        [XmlAttribute]          

        private const int numberOfLegs = 4;

        private const String classDog = "Dog";
 

        #endregion
 

        #region Konstruktor
 

        /// <summary>

        /// Dog Konstruktor

        /// </summary>

        public Dog()

        {}
 
 
 

        /// <summary>

        /// Dog Konstruktor

        /// </summary>

        /// <param name="name"></param>

        /// <param name="ID"></param>

        /// <param name="housing"></param>

        public Dog(String name, String ID, HousingType housing, String speed, bool aggressive)

            : base(name, ID, numberOfLegs, housing, classDog, speed, aggressive)

        {

            likes.Add("Cats");

        } //end Dog
 

        #endregion
 

    } //end class

} //end namespace

Open in new window

Unavngivet.bmp
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 24829841
change the implementation of the speed in animal class as shown below then
public virtual String Speed

        {

            set {  }

            get { return string.Empty }

        }

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now