Difference between revisions of "Add the code to allow foxes to have a gender"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Explanation)
m (Reverted edits by Westy (talk) to last revision by Admin)
Line 9: Line 9:
 
           Male,
 
           Male,
 
           Female
 
           Female
          Agender
 
          Androgyne
 
          Androgynous
 
          Bigender
 
          Cis
 
          Cisgender
 
          Cis Female
 
          Cis Male
 
          Cis Man
 
          Cis Woman
 
          Cisgender Female
 
          Cisgender Male
 
          Cisgender Man
 
          Cisgender Woman
 
          Female to Male
 
          FTM
 
          Gender Fluid
 
          Gender Nonconforming
 
          Gender Questioning
 
          Gender Variant
 
          Genderqueer
 
          Intersex
 
          Male to Female
 
          MTF
 
          Neither
 
          Neutrois
 
          Non-binary
 
          Other
 
          Pangender
 
          Trans
 
          Trans*
 
          Trans Female
 
          Trans* Female
 
          Trans Male
 
          Trans* Male
 
          Trans Man
 
          Trans* Man
 
          Trans Person
 
          Trans* Person
 
          Trans Woman
 
          Trans* Woman
 
          Transfeminine
 
          Transgender
 
          Transgender Female
 
          Transgender Male
 
          Transgender Man
 
          Transgender Person
 
          Transgender Woman
 
          Transmasculine
 
          Transsexual
 
          Transsexual Female
 
          Transsexual Male
 
          Transsexual Man
 
          Transsexual Person
 
          Transsexual Woman
 
          Two-Spirit
 
 
 
       }
 
       }
  

Revision as of 13:13, 14 February 2017

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:

1     enum Genders
2       {
3           Male,
4           Female
5       }
6 
7     private Genders Gender;

This creates the different enum options, Genders can either be Male or Female. The Gender of the object is created using private.

This is the method from the rabbit class to check if an object is female. Copy the entire method into the fox class:

 1     public bool IsFemale()
 2     {
 3         if (Gender == Genders.Female)
 4         {
 5             return true;
 6         }
 7         else
 8         {
 9             return false;
10         }
11     }

In order to assign a Gender to a fox the code below needs to be added to the fox constructor:


1       if (Rnd.Next(0, 100) < 50)
2       {
3           Gender = Genders.Male;
4       }
5       else
6       {
7           Gender = Genders.Female;
8       }

In the inspect method add this line to display the Gender of the fox:

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

What Now??

To use the new Gender you can change how the fox is reproduced:

 1 public bool ReproduceThisPeriod()
 2     {
 3       const double ReproductionProbability = 0.60;
 4       if (Rnd.Next(0, 100) < ReproductionProbability * 100 && IsFemale())
 5       {
 6         return true;
 7       }
 8       else
 9       {
10         return false;
11       }
12     }

This has made it so only a female fox can reproduce. But I have increased the probability.