From 6252f4c884e870a0976e0e7bbb3551f743ed4136 Mon Sep 17 00:00:00 2001 From: NarenRed Date: Tue, 20 Jun 2023 16:14:46 -0500 Subject: [PATCH] added Hire method and inclued a postion for the employee --- .vs/Naren_Coding_Evaluation/v17/.wsuo | Bin 0 -> 11264 bytes dotnet/MyOrganization/MyOrganization.cs | 4 ++ dotnet/MyOrganization/Organization.cs | 56 ++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 .vs/Naren_Coding_Evaluation/v17/.wsuo diff --git a/.vs/Naren_Coding_Evaluation/v17/.wsuo b/.vs/Naren_Coding_Evaluation/v17/.wsuo new file mode 100644 index 0000000000000000000000000000000000000000..73f5e50e1f00c61180f85727bbf9bb256857e9df GIT binary patch literal 11264 zcmeHN&2Jk;6n{=Bw0!kDK&eE8B9ucNIZoQ9MO39}3P_lwbv{6fgk0N6+{7QUofdA~ z_$Lq&;sQs+KfsL(QhVhF5`O^)ZZ!OUvpe3|_3nDT+q4PYXRUW;c6NUA-n=*S-m@P* zIPu4KKb`$kJaknK$)nw)^1RWWG0JjWMJFAdz= z@+FrtGL6dN-kKjC@YeBve*5}|?|;v{gnqx+inR#Drrec}fWD5>ynHcW6!+s%8R_9u z?Cz)jwXMGFBx5djP(QQ%7%E$K!-DJpWm{_C zpVx+gd;=|Q^F^OB@t;Hc2(GC7kD{-(>sL|!*JJ=?%0@SFu1D*kK4__szoU7xWGPtH(QK5Y*3Xr>*Gv4Pf4Zq&M)P z-?^$JUY1SNI=WNHeJln(eLnhXr0ZDkCcM!)aND>?^?R+iMb1I~jQg|?sN2KtXYg>s z?y#h!za<|-`W>u#5uDQp?@C!|4Uc>Y9{KY8cgMxx(OjcY^aO3;Oyn8&t~ zy^aj3m`OKKE3U+lzkB_giqkqUsr9SCZ%73)xG#(N?x5bqMced~MGpM)TqaLZ`KJ$m z0T;=uf8?L|MZ|%1XeM`uFnT93|8D&+Kn``FG7dFm;m14Yh5ct}`=hQb*-Ux)zYgRo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Organization.cs +++ b/dotnet/MyOrganization/MyOrganization.cs @@ -33,6 +33,8 @@ override protected Position CreateOrganization() vpt.AddDirectReport(dct); Position s = new Position("Salesperson"); vps.AddDirectReport(s); + Position pm = new Position("Product Manager"); + vps.AddDirectReport(pm); return ceo; } @@ -46,6 +48,8 @@ static void Main() org.Hire(new Name("Bill", "Lumbergh"), "Director Customer Technology"); org.Hire(new Name("Ford", "Prefect"), "VP Marketing"); org.Hire(new Name("Jane", "Seller"), "VP Sales"); + org.Hire(new Name("Naren", "Reddy"), "Product Manager"); + org.Hire(new Name("Vijay", "Virup"), "President"); org.Hire(new Name("Bean", "Counter"), "VP Finance"); org.Hire(new Name("Victoria", "Sinclair"), "CIO"); org.Hire(new Name("Head", "Geek"), "VP Technology"); diff --git a/dotnet/MyOrganization/Organization.cs b/dotnet/MyOrganization/Organization.cs index 7480481..c3111b2 100644 --- a/dotnet/MyOrganization/Organization.cs +++ b/dotnet/MyOrganization/Organization.cs @@ -24,12 +24,60 @@ public Organization() * @param title * @return the newly filled position or empty if no position has that title */ - public Position? Hire(Name person, string title) - { - //your code here - return null; + public Position? Hire(Name person, string title) + { + Position? targetPosition = FindPositionByTitle(root, title); + + if (targetPosition != null) + { + if (targetPosition.IsFilled()) + { + Employee? previousEmployee = targetPosition.GetEmployee(); + Console.WriteLine($"Position '{title}' is already filled by {previousEmployee}. Cannot hire {person}."); + return null; + } + + Employee newEmployee = new Employee(GetNextEmployeeIdentifier(), person); + targetPosition.SetEmployee(newEmployee); + + Console.WriteLine($"Hired {person} as '{title}'."); + return targetPosition; + } + + Console.WriteLine($"No position found with the title '{title}'. Cannot hire {person}."); + return null; + } + + private Position? FindPositionByTitle(Position currentPosition, string title) + { + if (currentPosition.GetTitle() == title) + { + return currentPosition; + } + + foreach (Position directReport in currentPosition.GetDirectReports()) + { + Position? targetPosition = FindPositionByTitle(directReport, title); + if (targetPosition != null) + { + return targetPosition; + } + } + + return null; } + + + + private int nextEmployeeId = 1000; // Starting employee ID + + private int GetNextEmployeeIdentifier() + { + int employeeId = nextEmployeeId; + nextEmployeeId++; // Increment the employee ID for the next employee + return employeeId; + } override public string ToString() { return PrintOrganization(root, "");