/// <summary> /// Method invites client to enter the desired criterion. /// Then he writes down selected criterion in field SelectionCriterion /// of parameter staffSelector. /// </summary> /// <param name="staffSelector"></param> public void SelectCriterion(StaffSelector staffSelector) { StringBuilder criterionsChoiceBuilder = new StringBuilder(CriterionChoice); criterionsChoiceBuilder.AppendLine(Criterion1).AppendLine(Criterion2).AppendLine(Criterion3); bool isCriterionNotSelected = true; do { Console.WriteLine(criterionsChoiceBuilder); int choice; Console.Write(Answer); if (int.TryParse(Console.ReadLine(), out choice)) { switch (choice) { // Criteria 1/ Maximum productivity within the amount. case 1: { staffSelector.SelectionCriterion = new MaxProductivityCriterion(); isCriterionNotSelected = false; break; } // Criteria 2/ Minimum cost for a fixed productivity. case 2: { staffSelector.SelectionCriterion = new MinAmountCriterion(); isCriterionNotSelected = false; break; } // Criteria 3/ Minimum number of employees is higher than Junior for fixed productivity. case 3: { staffSelector.SelectionCriterion = new MinCountOfElderWorkersCriterion(); isCriterionNotSelected = false; break; } default: { Console.WriteLine(ClInputError); continue; } } } else { Console.WriteLine(ClInputError); } } while (isCriterionNotSelected); }
/// <summary> /// The method creates an instance of the client's handler class /// and initializes the employee structure. /// After then it calls handler class methods of commands /// entered by client. /// After each iteration of the loop do-while, /// user is asked to press a key Escape /// or continue working with application /// by pressing any other key. /// </summary> /// <param name="args"></param> static void Main(string[] args) { try { Console.WriteLine(Welcome); StaffSelectionConsoleHandler consoleHandler = new StaffSelectionConsoleHandler(); Staffs staffs = new Staffs( new Junior(JuniorSalary, JuniorProductivity), new Middle(MiddleSalary, MiddleProductivity), new Senior(SeniorSalary, SeniorProductivity), new Lead(LeadSalary, LeadProductivity)); do { // called method for input // current amount and required productivity of the client StaffSelector currentSelector = consoleHandler.PackingClientPersonalData(); currentSelector.Staffs = staffs; // called method for choice desired criteria consoleHandler.SelectCriterion(currentSelector); // choice of employees according to the entered parameters List <Dictionary <FellowWorker, int> > result = currentSelector.SelectTeams(); // print results consoleHandler.PrintTeams(result); Console.WriteLine(Choice); } while (Console.ReadKey(true).Key != ConsoleKey.Escape); } catch (Exception exc) { Console.WriteLine(exc.Message); } }
/// <summary> /// Each select method requires an override /// according to its criterion /// </summary> /// <param name="selector">Contains cash amount and productivity</param> /// <returns>Possible solutions for the composition of the team of employees</returns> public abstract List <Dictionary <FellowWorker, int> > Select(StaffSelector selector);