static void Main(string[] args) { TxtPrinter.PrintInformation("WELCOME TO THE BRIDGE PROGRAM -- WHICH IS A BORING PROGRAM THAT SORT OF DOES CONVERSIONS"); var keepLooping = true; while (keepLooping) { var(converters, converterNames) = TypParser.GetTypeDictionaryAndNameList <AbstractConverter>(); Console.WriteLine("Enter the number of the measurement from which you want to convert."); TxtParser.PrintStringList(converterNames); var strConverterChoice = TxtParser.GetTextFromConsole(); if (!TypParser.TryGetType(strConverterChoice, converters, out var converter)) { Console.WriteLine(INVALID_CHOICE_MESSAGE); continue; } var(formatters, formatterNames) = TypParser.GetInstantiatedTypeDictionaryAndNameList <IFormatter>(); Console.WriteLine("Enter the number of the way you want the output formatted."); TxtParser.PrintStringList(formatterNames); var strFormatterChoice = TxtParser.GetTextFromConsole(); if (!TypParser.TryGetType(strFormatterChoice, formatters, out var formatter)) { Console.WriteLine(INVALID_CHOICE_MESSAGE); continue; } var instantiatedConverter = Activator.CreateInstance(converter, formatter) as AbstractConverter; Console.WriteLine("Enter the value that you want converted"); var strValue = TxtParser.GetTextFromConsole(); if (!decimal.TryParse(strValue, out var value)) { Console.WriteLine("That's not a value that can be converted. Let's try this again I guess."); continue; } instantiatedConverter.Convert(value); keepLooping = ContinuationDeterminer.GoAgain(); } }
static void Main(string[] args) { TxtPrinter.PrintInformation("WELCOME TO THE STRATEGY PROGRAM -- WHICH SORT OF MIGHT MAKE YOU THINK"); var countryTaxSystemMap = new Dictionary <string, List <string> >(); try { using (var reader = new StreamReader(MapPath)) { var json = reader.ReadToEnd(); var jObject = JObject.Parse(json); foreach (var system in jObject) { if (countryTaxSystemMap.ContainsKey(system.Key)) { Console.WriteLine($"There is a duplicate tax system entry in {MapPath}. Only the first entry will be used."); continue; } countryTaxSystemMap.Add(system.Key, system.Value.ToObject <List <string> >()); } } } catch (Exception ex) { Console.WriteLine($"Unable to parse the county-tax system map from {MapPath}. Exception: {ex.Message}"); Console.ReadKey(); Environment.Exit(1); } var taxCalculators = new List <ITaxCalculator>(); try { var(calulatorDictionary, calculatorNames) = TypParser.GetTypeDictionaryAndNameList <ITaxCalculator>(); var key = 1; foreach (var calculatorName in calculatorNames) { if (!countryTaxSystemMap.TryGetValue(calculatorName.ToLower(), out var countries)) { Console.WriteLine($"There is no entry for the {calculatorName} tax calculator in the map; therefore, " + $"this tax calculator will be ignored."); continue; } var calculator = Activator.CreateInstance(calulatorDictionary[key++], countries) as ITaxCalculator; taxCalculators.Add(calculator); } } catch (Exception ex) { Console.WriteLine($"There was an error trying to create the tax calculators. Exception: {ex.Message}"); Console.ReadKey(); Environment.Exit(1); } var allCountries = taxCalculators .SelectMany(c => c.TaxableCountries) .Distinct() .OrderBy(c => c) .ToList(); var calculatorContext = new CalculatorContext(); while (true) { var currentCountry = allCountries[Asker.GetChoiceFromList("What country do you live in?", allCountries)]; var taxCalculator = taxCalculators.FirstOrDefault(c => c.TaxableCountries.Contains(currentCountry)); calculatorContext.SetCalculator(taxCalculator); var tax = calculatorContext.CalculateTax(currentCountry); Console.Write("\nYour tax is: "); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{tax.ToString("0.00")}\n"); Console.ResetColor(); if (!ContinuationDeterminer.GoAgain()) { Environment.Exit(0); } } }