Ejemplo n.º 1
0
        private static void Exchange()
        {
            Console.WriteLine("Select the wallet whose currency you want to change");
            var sellCurrencyWallet = ChooseWallet();

            Console.WriteLine("Select the wallet for which you want to change the currency");
            var buyCurrencyWallet = ChooseWallet();

            Console.WriteLine($"You have {sellCurrencyWallet.AmountOfMoney} {sellCurrencyWallet.Currency}");
            Console.WriteLine($"{sellCurrencyWallet.Currency} to {buyCurrencyWallet.Currency} rate " +
                              $"is {Exchanger.GetRate(sellCurrencyWallet.Currency, buyCurrencyWallet.Currency)}");
            Console.WriteLine("Enter amount of money:");
            while (true)
            {
                if (double.TryParse(Console.ReadLine(), out var money))
                {
                    if (money <= sellCurrencyWallet.AmountOfMoney)
                    {
                        Exchanger.Exchange(sellCurrencyWallet, buyCurrencyWallet, money);
                        break;
                    }
                    Console.WriteLine("Not enough money. Try again");
                }
                else
                {
                    Console.WriteLine("Incorrect amount. Try again");
                }
            }
        }
Ejemplo n.º 2
0
        public static void ShowMenu()
        {
            string firstCode;
            string secondCode;
            double money;

            Console.WriteLine("Money Exchanger. Available currency:");
            Console.WriteLine("USD\nEUR\nUAH\nPLN\nCHF\nGBP\n");
            Console.WriteLine("Please, enter currency you want to sell");

            while (true)
            {
                firstCode = Console.ReadLine();
                if (CodeChecker(firstCode))
                {
                    break;
                }
                Console.WriteLine("Need to enter one of available currency. Try again:");
            }

            Console.WriteLine($"Please, enter amount of {firstCode.ToUpper()}");

            while (true)
            {
                var moneyString = Console.ReadLine();
                if (double.TryParse(moneyString, out money))
                {
                    break;
                }
                Console.WriteLine($"Need to enter amount of {firstCode.ToUpper()} you want to sell. Try again:");
            }

            Console.WriteLine("Please, enter currency you want to buy");

            while (true)
            {
                secondCode = Console.ReadLine();
                if (CodeChecker(secondCode))
                {
                    break;
                }
                Console.WriteLine("Need to enter one of available currency. Try again:");
            }
            Exchanger.Exchange(firstCode, secondCode, money);
        }