public List <Ape> CalculateSameLevelRelationship(RelationshipType relationshipType, ApeFamilyAssociationService familyAssociationService, ApeFamilyService familyService) { List <Ape> result = new List <Ape>(); switch (relationshipType) { case RelationshipType.Brother: result = GetSiblings(GenderType.Male, familyAssociationService); break; case RelationshipType.Sister: result = GetSiblings(GenderType.Female, familyAssociationService); break; case RelationshipType.SisterInLaw: result = GetSisterInLawOrBrotherInLaw(GenderType.Female, familyAssociationService); break; case RelationshipType.BrotherInLaw: result = GetSisterInLawOrBrotherInLaw(GenderType.Male, familyAssociationService); break; case RelationshipType.Cousins: result = GetCousins(familyAssociationService, familyService); break; default: break; } return(result); }
public List <Ape> GetUncleOrAuntOnMaternalOrPaternalSide(GenderType gender, ApeFamilyAssociationService service, Ape ape) { List <Ape> result = new List <Ape>(); result.AddRange(ape.GetSiblings(gender, service)); result.AddRange(ape.GetSisterInLawOrBrotherInLaw(gender, service)); return(result); }
public List <Ape> GetParent(GenderType gender, ApeFamilyAssociationService service) { ApeFamily family = service.GetElement(_name); List <Ape> result = new List <Ape>(); if (family != null) { result.Add(family.Partners.SingleOrDefault(e => e != this && e.GetGender() == gender)); } return(result); }
public List <Ape> GetSiblings(ApeFamilyAssociationService service) { ApeFamily family = service.GetElement(_name); List <Ape> siblings = new List <Ape>(); if (family != null) { siblings = family.Children.Where(elem => elem != this).ToList(); } return(siblings); }
public List <Ape> GetSisterInLawOrBrotherInLaw(GenderType gender, ApeFamilyAssociationService service) { List <Ape> result = new List <Ape>(); result.AddRange(GetSpouse().GetSiblings(gender, service)); GenderType genderToBeFound = gender == GenderType.Female ? GenderType.Male : GenderType.Female; List <Ape> siblings = this.GetSiblings(genderToBeFound, service); foreach (var sibling in siblings) { result.Add(sibling.GetSpouse()); } return(result); }
public List <Ape> CalculateRelationship(RelationshipType relationshipType, ApeFamilyAssociationService familyAssociationService, ApeFamilyService apeFamilyService) { List <Ape> result = new List <Ape>(); switch (relationshipType) { case RelationshipType.Brother: case RelationshipType.Sister: case RelationshipType.SisterInLaw: case RelationshipType.BrotherInLaw: case RelationshipType.Cousins: result = CalculateSameLevelRelationship(relationshipType, familyAssociationService, apeFamilyService); break; case RelationshipType.Mother: case RelationshipType.Father: case RelationshipType.PaternalUncle: case RelationshipType.MaternalAunt: case RelationshipType.PaternalAunt: case RelationshipType.MaternalUncle: result = CalculateUpBy1LevelRelationship(relationshipType, familyAssociationService); break; case RelationshipType.Children: case RelationshipType.Son: case RelationshipType.Daughter: result = CalculateDownBy1LevelRelationship(relationshipType, apeFamilyService); break; case RelationshipType.GrandChildren: case RelationshipType.GrandSon: case RelationshipType.GrandDaughter: result = CalculateDownBy2LevelRelationship(relationshipType, apeFamilyService); break; } return(result); }
public List <Ape> CalculateUpBy1LevelRelationship(RelationshipType relationshipType, ApeFamilyAssociationService familyService) { List <Ape> result = new List <Ape>(); switch (relationshipType) { case RelationshipType.Mother: result = GetParent(GenderType.Female, familyService); break; case RelationshipType.Father: result = GetParent(GenderType.Male, familyService); break; case RelationshipType.MaternalUncle: result = GetUncleOrAuntOnMaternalOrPaternalSide(GenderType.Male, familyService, GetParent(GenderType.Female, familyService).FirstOrDefault()); break; case RelationshipType.MaternalAunt: result = GetUncleOrAuntOnMaternalOrPaternalSide(GenderType.Female, familyService, GetParent(GenderType.Female, familyService).FirstOrDefault()); break; case RelationshipType.PaternalAunt: result = GetUncleOrAuntOnMaternalOrPaternalSide(GenderType.Female, familyService, GetParent(GenderType.Male, familyService).FirstOrDefault()); break; case RelationshipType.PaternalUncle: result = GetUncleOrAuntOnMaternalOrPaternalSide(GenderType.Male, familyService, GetParent(GenderType.Male, familyService).FirstOrDefault()); break; } return(result); }
public List <Ape> GetCousins(ApeFamilyAssociationService service, ApeFamilyService familyService) { List <Ape> result = new List <Ape>(); List <Ape> fatherSideCousins = new List <Ape>(); List <Ape> motherSideCousins = new List <Ape>(); List <Ape> father = GetParent(GenderType.Male, service); List <Ape> mother = GetParent(GenderType.Female, service); foreach (var fatherSideSibling in father.ElementAt(0).GetSiblings(service)) { fatherSideCousins.AddRange(fatherSideSibling.GetChildren(familyService)); } foreach (var motherSideSibling in mother.ElementAt(0).GetSiblings(service)) { motherSideCousins.AddRange(motherSideSibling.GetChildren(familyService)); } result.AddRange(fatherSideCousins); result.AddRange(motherSideCousins); return(result); }
static void Main(string[] args) { ApeService apeService = new ApeService(); ApeFamilyService apeFamilyService = new ApeFamilyService(apeService); ApeFamilyAssociationService apeFamilyAssociationService = new ApeFamilyAssociationService(apeFamilyService); int userInput = 0; do { userInput = DisplayMenu(apeService); switch (userInput) { case 1: try { Console.WriteLine("Please enter the name of the Ape you want to find relationship for:"); string apeName = Console.ReadLine(); Console.WriteLine("Enter RelationShip Type"); string relationShipType = Console.ReadLine(); Ape ape = apeService.GetElement(apeName); Models.RelationshipType relationship; if (!Enum.TryParse(relationShipType, true, out relationship)) { throw new Exception("Invalid Relationship"); } List <Ape> apes = ape.CalculateRelationship(relationship, apeFamilyAssociationService, apeFamilyService); Utility.PrintName(apes); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("We should start from all over"); } break; case 2: try { Console.WriteLine("Please enter the name of the parent you want add the family under"); string parent = Console.ReadLine(); Console.WriteLine("Enter child name:"); string child = Console.ReadLine(); Console.WriteLine("Enter child gender:"); string genderType = Console.ReadLine(); Ape parentApe = apeService.GetElement(parent); Models.GenderType gender; if (!Enum.TryParse(genderType, true, out gender)) { throw new Exception("We are not aware of such a gender!!"); } ApeFamily apeFamily = apeFamilyService.GetAll().SingleOrDefault(p => p.Partners.Contains(parentApe)); if (apeFamily == null) { throw new Exception("That would be incorrect. Apes are not Godzillas."); } Ape newBorn = apeFamily.AddNewBorn(child, parentApe.GetDepthLevel() + 1, gender); apeFamilyAssociationService.AddElement(child, apeFamily); apeService.AddElement(newBorn.GetName(), newBorn); Console.WriteLine($"New born {newBorn.GetName()} successfully added to family"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("We should start from all over"); } break; case 3: Utility.PrintName(apeFamilyService.GetMothersWithMaximumGirlApes()); break; case 4: try { Console.WriteLine("Please enter the name of the ape1"); string ape1Name = Console.ReadLine(); Console.WriteLine("Please enter the name of the ape1"); string ape2Name = Console.ReadLine(); Ape ape1 = apeService.GetElement(ape1Name); Ape ape2 = apeService.GetElement(ape2Name); Utility.PrintName(apeFamilyAssociationService.GetRelationshipBetweenApes(ape1, ape2)); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("We should start from all over"); } break; } } while (userInput != 5); Console.WriteLine(); }
public void Arrange() { _apeService = new ApeService(); _apeFamilyService = new ApeFamilyService(_apeService); _apeFamilyAssociationService = new ApeFamilyAssociationService(_apeFamilyService); }