@@ -28,79 +28,136 @@ public class Person : IPerson
2828 readonly string _id = Guid . NewGuid ( ) . ToString ( ) ;
2929 public string Id => _id ;
3030
31+ private string _name ;
32+ private Gender _gender ;
33+ private IPerson ? _father ;
34+ private IPerson ? _mother ;
35+
36+ private HashSet < IPerson > _children = new HashSet < IPerson > ( ) ;
37+ private HashSet < IPerson > _brothers = new HashSet < IPerson > ( ) ;
38+ private HashSet < IPerson > _sisters = new HashSet < IPerson > ( ) ;
39+ private HashSet < IPerson > _daughters = new HashSet < IPerson > ( ) ;
40+ private HashSet < IPerson > _sons = new HashSet < IPerson > ( ) ;
41+
42+
43+
3144 public Person ( string name , Gender gender )
3245 {
33-
46+ this . _name = name ;
47+ this . _gender = gender ;
3448 }
3549
36- public string Name {
37- get => throw new NotImplementedException ( ) ;
38- set => throw new NotImplementedException ( ) ;
50+ public string Name
51+ {
52+ get => _name ;
53+ set => _name = value ;
3954 }
4055
4156 public void addBrother ( IPerson brother )
4257 {
43- throw new NotImplementedException ( ) ;
58+ if ( ! this . getBrothers ( ) . Contains ( brother ) )
59+ this . _brothers . Add ( brother ) ;
60+
61+ if ( ! brother . getSisters ( ) . Contains ( this ) )
62+ brother . addSister ( this ) ;
4463 }
4564
4665 public void addDaughter ( IPerson daughter )
4766 {
48- throw new NotImplementedException ( ) ;
67+ if ( ! this . _daughters . Contains ( daughter ) )
68+ {
69+ this . _daughters . Add ( daughter ) ;
70+ }
71+
72+ if ( ! this . _children . Contains ( daughter ) )
73+ {
74+ this . _children . Add ( daughter ) ;
75+
76+
77+ }
4978 }
5079
5180 public void addSister ( IPerson sister )
5281 {
53- throw new NotImplementedException ( ) ;
82+ if ( ! this . getSisters ( ) . Contains ( sister ) )
83+ this . _sisters . Add ( sister ) ;
84+
85+ if ( ! sister . getBrothers ( ) . Contains ( this ) )
86+ sister . addBrother ( this ) ;
5487 }
5588
5689 public void addSon ( IPerson son )
5790 {
58- throw new NotImplementedException ( ) ;
91+ if ( ! this . _sons . Contains ( son ) )
92+ {
93+ this . _sons . Add ( son ) ;
94+ }
95+
96+ if ( ! this . _children . Contains ( son ) )
97+ {
98+ this . _children . Add ( son ) ;
99+ }
59100 }
60101
61102 public IEnumerable < IPerson > getBrothers ( )
62103 {
63- throw new NotImplementedException ( ) ;
104+ return _brothers ;
64105 }
65106
66107 public IEnumerable < IPerson > getChildren ( )
67108 {
68- throw new NotImplementedException ( ) ;
109+ return _children ;
69110 }
70111
71112 public IEnumerable < IPerson > getDaughters ( )
72113 {
73- throw new NotImplementedException ( ) ;
114+ return _daughters ;
74115 }
75116
76117 public IPerson ? getFather ( )
77118 {
78- throw new NotImplementedException ( ) ;
119+ return this . _father ;
79120 }
80121
81122 public IPerson ? getMother ( )
82123 {
83- throw new NotImplementedException ( ) ;
124+ return this . _mother ;
84125 }
85126
86127 public IEnumerable < IPerson > getSisters ( )
87128 {
88- throw new NotImplementedException ( ) ;
129+ return _sisters ;
89130 }
90131
91132 public IEnumerable < IPerson > getSons ( )
92133 {
93- throw new NotImplementedException ( ) ;
134+ return _sons ;
94135 }
95136
96137 public void setFather ( IPerson father )
97138 {
98- throw new NotImplementedException ( ) ;
139+ this . _father = father ;
140+ if ( this . _gender == Gender . Male )
141+ {
142+ father . addSon ( this ) ;
143+ }
144+ else
145+ {
146+ father . addDaughter ( this ) ;
147+ }
99148 }
100149
101150 public void setMother ( IPerson mother )
102151 {
103- throw new NotImplementedException ( ) ;
152+ this . _mother = mother ;
153+ if ( this . _gender == Gender . Male )
154+ {
155+ mother . addSon ( this ) ;
156+ }
157+ else
158+ {
159+ mother . addDaughter ( this ) ;
160+ }
104161 }
105162 }
106163}
0 commit comments