Exemple #1
0
        private static Tuple <string, decimal> GetNewPurchaseInfo()
        {
            bool isInputValid;

            string  purchaseName;
            decimal purchasePrice;

            do
            {
                CH.WriteSeparator();

                purchaseName = CH.GetStringFromConsole("Please input the purchase name [Butter/Wine/Caviar/ e.t.c.]");
                var purchasePriseStr =
                    CH.GetStringFromConsole($"Please input the purchase price [{0.5m:C}/{9.99m:C}/ e.t.c.]");

                var isValidPurchaseName  = !string.IsNullOrWhiteSpace(purchaseName);
                var isValidPurchasePrice = decimal.TryParse(purchasePriseStr, out purchasePrice);

                isInputValid = isValidPurchaseName && isValidPurchasePrice;


                if (!isInputValid)
                {
                    Console.WriteLine("Incorrect input. Try again.");
                }
            } while (!isInputValid);

            return(new Tuple <string, decimal>(purchaseName, purchasePrice));
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            CH.SetConsoleOutputEncoding();
            CH.SetConsoleColor();

            const string inputMsg        = "Введитк натуральное число (n>0) : ";
            const string noPrimeMsg      = "Нет простых чисел в выбранном диапазоне";
            const string invalidInputMsg = "Введены неверные значения...";
            const string outMsg          = "{0,10}";

            var inputString = CH.GetStringFromConsole(inputMsg);

            if (!uint.TryParse(inputString, out var n))
            {
                Console.WriteLine(invalidInputMsg);
                Console.ReadKey();
                return;
            }

            CH.WriteSeparator();

            if (n == 1)
            {
                Console.WriteLine(noPrimeMsg);
            }
            else if (n >= 2)
            {
                Console.Write(outMsg, 2);


                for (uint number = 2; number <= n; number++)
                {
                    var isPrime = false;

                    for (uint oldNumber = 2; oldNumber <= Math.Ceiling(Math.Sqrt(number)); ++oldNumber)
                    {
                        if (number % oldNumber != 0)
                        {
                            isPrime = true;
                            break;
                        }
                    }

                    if (isPrime)
                    {
                        Console.Write(outMsg, number);
                    }
                }
            }

            Console.WriteLine();
            CH.WriteSeparator();

            //exit
            Console.ReadKey();
        }
Exemple #3
0
        private static void Main(string[] args)
        {
            CH.SetConsoleOutputEncoding();
            CH.SetConsoleColor();

            //output caption
            CH.WriteSeparator();
            Console.WriteLine("\t\t\t\t\t\t- Sphere Calculator -");
            CH.WriteSeparator();
            Console.WriteLine("\t\t\t\t\t\t-= Basic Formulas =-");
            Console.WriteLine("\t\t\t\t\tVolume=(4/3)\u03C0R\u00B3 m\u00B3 & Area = 4\u03C0R\u00B2 m\u00B2");

            //input radius of sphere
            CH.WriteSeparator();
            var separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            double sphereRadius;
            string sphereRadiusString;

            do
            {
                sphereRadiusString = CH.GetStringFromConsole(
                    $"Please enter the radius (R) of your sphere in meters (m) [you must separate of number parts with \"{separator}\" char]");
            } while (!double.TryParse(sphereRadiusString, out sphereRadius));


            //convertation & calculations

            var sphereV = 4.0 / 3.0 * Math.PI * Math.Pow(sphereRadius, 3.0);
            var sphereA = 4.0 * Math.PI * Math.Pow(sphereRadius, 2.0);

            //output results
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            CH.WriteSeparator();

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(
                "\tVolume=(4/3)\u03C0R\u00B3={0:0.###} m\u00B3{1}\tArea=(4/3)\u03C0R\u00B3={2:0.###} m\u00B2", sphereV,
                Environment.NewLine, sphereA);

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            CH.WriteSeparator();
            Console.WriteLine(
                $"\tThank you for using our program, we hope it helped you :D {Environment.NewLine}\tGoodbye!");

            //exit
            Console.ReadKey();
        }
Exemple #4
0
        private static decimal GetPriceFilterValue()
        {
            bool    isInputValid;
            decimal priceFilterValue;

            do
            {
                CH.WriteSeparator();

                var priceFilterValueStr = CH.GetStringFromConsole($"filter value [{0.5m:C}/{9.99m:C}]");

                isInputValid = decimal.TryParse(priceFilterValueStr, out priceFilterValue);
            } while (!isInputValid);

            return(priceFilterValue);
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            CH.SetConsoleOutputEncoding();
            CH.SetConsoleColor();

            const int numberOfPeriods = 12;

            const string inputMsg1       = "Введите cумму кредитования, \u00A4";
            const string inputMsg2       = "Введите ставку кредитования, % [1 - 100% как 15,5% ]";
            const string paymentTypeMsg  = "Выберите вид платежа:";
            const string paymentTypeMsg1 =
                "1 - аннуитетный платеж - это равный по сумме ежемесячный платеж по кредиту;";
            const string paymentTypeMsg2 =
                "2 - дифференцированный платеж -  это ежемесячный платеж, уменьшающийся к концу срока кредитования.";
            const string invalidInputMsg = "Введены неверные значения...";
            const string tableLineMsg    =
                " | {0,6} | {1,13:0.##}\u00A4 | {2,13:0.##}\u00A4 | {3,13:0.##}\u00A4 | {4,13:0.##}\u00A4 |";
            const string tableFooterLineMsg = " | Итого: | {0,30:0.##}\u00A4 | {1,13:0.##}\u00A4 | {2,13:0.##}\u00A4 |";

            CH.WriteSeparator();

            //input
            var creditAmountString = CH.GetStringFromConsole(inputMsg1);
            var creditRateString   = CH.GetStringFromConsole(inputMsg2);

            CH.WriteSeparator();

            var amountIsInvalid = !decimal.TryParse(creditAmountString, out var originalCreditAmount);
            var rateIsInvalid   = !double.TryParse(creditRateString, out var creditInterestRate);


            if (amountIsInvalid || rateIsInvalid || originalCreditAmount <= 1 || creditInterestRate < 1 ||
                creditInterestRate > 100)
            {
                Console.WriteLine(invalidInputMsg);
                Console.ReadKey();
                return;
            }


            Console.WriteLine(paymentTypeMsg);
            var choosedStringIndex = CH.GetChoiceFromUser(new[] { paymentTypeMsg1, paymentTypeMsg2 }, true).ChoisedIndex;

            CH.WriteSeparator();


            var sumOfInterestCharges = 0m;
            var sumOfPayments        = 0m;
            var debt = originalCreditAmount;

            creditInterestRate *= 0.01;

            //Table
            Console.WriteLine(tableLineMsg, "Период", "Задолженность", "Начисленные %",
                              "Основной долг", "Сумма платежа");

            if (choosedStringIndex == 0) //аннуитетный платеж
            {
                var monthlyCreditInterestRate = creditInterestRate / 12;
                var amountOfPayment           = originalCreditAmount *
                                                (decimal)(monthlyCreditInterestRate +
                                                          monthlyCreditInterestRate /
                                                          (Math.Pow(1 + monthlyCreditInterestRate, 12d) - 1d));

                for (var period = 1; period <= 12; period++)
                {
                    var interestCharges   = debt * (decimal)monthlyCreditInterestRate;
                    var repaymentOfCredit = amountOfPayment - interestCharges;

                    Console.WriteLine(tableLineMsg, period, debt, interestCharges,
                                      repaymentOfCredit, amountOfPayment);

                    debt -= repaymentOfCredit;

                    sumOfInterestCharges += interestCharges;
                    sumOfPayments        += amountOfPayment;
                }
            }
            else //дифференцированный платеж
            {
                var repaymentOfCredit = originalCreditAmount / numberOfPeriods;
                var currentYear       = DateTime.Today.Year;

                for (var period = 1; period <= 12; period++)
                {
                    var interestCharges =
                        debt * (decimal)(creditInterestRate * DateTime.DaysInMonth(currentYear, period) / 365d);
                    var amountOfPayment = repaymentOfCredit + interestCharges;

                    Console.WriteLine(tableLineMsg, period, debt, interestCharges,
                                      repaymentOfCredit, amountOfPayment);

                    debt -= repaymentOfCredit;

                    sumOfInterestCharges += interestCharges;
                    sumOfPayments        += amountOfPayment;
                }
            }


            CH.WriteSeparator();
            Console.WriteLine(tableFooterLineMsg, sumOfInterestCharges, originalCreditAmount, sumOfPayments);
            CH.WriteSeparator();

            //Exit
            Console.ReadKey();
        }