Solved

Move some code to make it work.

Posted on 2009-07-10
6
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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