Add the code to allow foxes to have a gender

From TRCCompSci - AQA Computer Science
Revision as of 13:05, 14 February 2017 by Westy-Chan (talk | contribs) (Explanation)
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:

 1     enum Genders
 2       {
 3           Male,
 4           Female
 5           Agender
 6           Androgyne
 7           Androgynous
 8           Bigender
 9           Cis
10           Cisgender
11           Cis Female
12           Cis Male
13           Cis Man
14           Cis Woman
15           Cisgender Female
16           Cisgender Male
17           Cisgender Man
18           Cisgender Woman
19           Female to Male
20           FTM
21           Gender Fluid
22           Gender Nonconforming
23           Gender Questioning
24           Gender Variant
25           Genderqueer
26           Intersex
27           Male to Female
28           MTF
29           Neither
30           Neutrois
31           Non-binary
32           Other
33           Pangender
34           Trans
35           Trans*
36           Trans Female
37           Trans* Female
38           Trans Male
39           Trans* Male
40           Trans Man
41           Trans* Man
42           Trans Person
43           Trans* Person
44           Trans Woman
45           Trans* Woman
46           Transfeminine
47           Transgender
48           Transgender Female
49           Transgender Male
50           Transgender Man
51           Transgender Person
52           Transgender Woman
53           Transmasculine
54           Transsexual
55           Transsexual Female
56           Transsexual Male
57           Transsexual Man
58           Transsexual Person
59           Transsexual Woman
60           Two-Spirit
61 
62       }
63 
64     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.