Add the code to allow foxes to have a gender

From TRCCompSci - AQA Computer Science
Revision as of 15:35, 13 February 2017 by Admin (talk | contribs) (Created page with "==Explanation== I have looked at the code for a rabbit and copied the code relating to gender over into the fox class. Firstly you need to add the is to the start of the clas...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Explanation

I have looked at the code for a rabbit and copied the code relating to gender over into the fox class.

Firstly you need to add the is to the start of the class:

    enum Genders
      {
          Male,
          Female
      }
    private Genders Gender;


    public bool IsFemale()
    {
        if (Gender == Genders.Female)
        {
            return true;
        }
        else
        {
            return false;
        }
    }


      if (Rnd.Next(0, 100) < 50)
      {
          Gender = Genders.Male;
      }
      else
      {
          Gender = Genders.Female;
      }


Console.Write("Gender " + Gender + " ");