public static Decision GetCtbIncomeDecision(Dictionary <int, IDecision> branches = null) { // default param branches = branches ?? new Dictionary <int, IDecision> { }; // Code // question and decision Action <IDecision, IDecision> question = (d, answer) => { var decision = d as CtbIncomeDecision; if (decision != null) { // ask question Console.WriteLine("{0}", decision.Question); var ans = Console.ReadLine() ?? string.Empty; // assign/calculate properties of the decision decision.Amount = (float)Convert.ToInt32(ans); // var branchChoice = Convert.ToInt32(ans); //var branchChoice = (int)1; if (decision.Amount < 10) { decision.CtbIncomeEnum = CtbIncomeEnum.Below; branchChoice = 1; } else { decision.CtbIncomeEnum = CtbIncomeEnum.Above; branchChoice = 2; } // assign branch choice given users answers decision.Result = branchChoice; } }; var retd = new CtbIncomeDecision { Question = string.Format("[/1] {0} ?", Enum <CtbIncomeEnum> .EnumsStringSummary()), Mutator = question, Branches = branches }; // Return return(retd); }
public static Decision GetCtbIncomeDecision(Dictionary<int, IDecision> branches = null) { // default param branches = branches ?? new Dictionary<int, IDecision> { }; // Code // question and decision Action<IDecision, IDecision> question = (d, answer) => { var decision = d as CtbIncomeDecision; if (decision != null) { // ask question Console.WriteLine("{0}", decision.Question); var ans = Console.ReadLine() ?? string.Empty; // assign/calculate properties of the decision decision.Amount = (float)Convert.ToInt32(ans); // var branchChoice = Convert.ToInt32(ans); //var branchChoice = (int)1; if (decision.Amount < 10) { decision.CtbIncomeEnum = CtbIncomeEnum.Below; branchChoice = 1; } else { decision.CtbIncomeEnum = CtbIncomeEnum.Above; branchChoice = 2; } // assign branch choice given users answers decision.Result = branchChoice; } }; var retd = new CtbIncomeDecision { Question = string.Format("[/1] {0} ?", Enum<CtbIncomeEnum>.EnumsStringSummary()), Mutator = question, Branches = branches }; // Return return retd; }