Move some code to make it work.

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

MickeysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gautham JanardhanCommented:
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
Gautham JanardhanCommented:
>>> 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
MickeysAuthor Commented:
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
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Gautham JanardhanCommented:

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
MickeysAuthor Commented:
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
Gautham JanardhanCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.