private static void AddNewCurrency(string text, Dictionary <string, CurrencyItem> map) { Console.WriteLine("Please Enter name for currency, three capital english letters:"); string NewCurrencyName = Console.ReadLine(); Console.WriteLine($"Enter course of {NewCurrencyName} (How much GEL is 1 {NewCurrencyName}): "); double k = Convert.ToDouble(Console.ReadLine()); Console.WriteLine($"Enter course of {NewCurrencyName} to Buy: "); double BuyK = Convert.ToDouble(Console.ReadLine()); Console.WriteLine($"Enter course of {NewCurrencyName} to Sell: "); double SellK = Convert.ToDouble(Console.ReadLine()); CurrencyItem Item = new CurrencyItem(NewCurrencyName, k, BuyK, SellK); text += $"\n{Item.ToString()}"; System.IO.File.WriteAllText(DATA_FILE_PATH, text); map.Add(NewCurrencyName, Item); }
public static void Main(string[] args) { Console.WriteLine("This is Currency Converter."); string text = System.IO.File.ReadAllText(DATA_FILE_PATH); // Display the file contents to the console. Variable text is a string. //System.Console.WriteLine("Contents of WriteText.txt = {0}", text); string ConvertedText = Regex.Replace(text, @"\t|\n|\r", ""); string[] words = ConvertedText.Split(' '); var map = new Dictionary <string, CurrencyItem>(); for (int i = 0; i < words.Length; i += 4) { if (i > words.Length - 4) { continue; } string name = words[i]; double Currency = Double.Parse(words[i + 1]); double BuyCurrency = Double.Parse(words[i + 2]); double SellCurrency = Double.Parse(words[i + 3]); CurrencyItem item = new CurrencyItem(name, Currency, BuyCurrency, SellCurrency); map.Add(words[i], item); } while (true) { Console.WriteLine("Functions of Converter, type ... for ...:\n"); Console.WriteLine("ADD -> to add new currency into DataBase"); Console.WriteLine("CONVERT -> to convert one currency into another"); Console.WriteLine("SHOW -> to show all currencies in relation of GEL, boughs, sells"); Console.WriteLine("BUY -> to buy currency"); Console.WriteLine("SELL -> to sell currency"); string command = Console.ReadLine(); if (command == "ADD") { MainClass.AddNewCurrency(text, map); } else if (command == "CONVERT" || command.Length == 0) { MainClass.ConvertCurrency(map); } else if (command == "SHOW") { MainClass.ShowInfo(); } else if (command == "BUY") { MainClass.BuyCurrency(map); } else if (command == "SELL") { MainClass.SellCurrency(map); } Console.WriteLine("__________________________________________________________\n"); } }