private static void Main(string[] args) { CH.SetConsoleOutputEncoding(); CH.SetConsoleColor(); var rand = new Random((int)DateTime.Now.Ticks); ; var field = new Field(rand.Next(10, 20), rand.Next(10, 20)); while (true) { switch (CH.GetChoiceFromUser(new[] { "Generate new animals", "To next step" }, true, true).ChoisedIndex) { case 0: field.GenerateNewAnimals(rand.Next(5, 20), rand.Next(2, 5)); break; case 1: field.NextStep(); break; case -1: return; } } }
public void Predict() { CH.WriteSeparator(); Console.WriteLine("Please choice prediction interval: "); var choiceResult = CH.GetChoiceFromUser <Period>(true); CH.ClearLine(2); Console.WriteLine(Predict(choiceResult)); }
private static void Main(string[] args) { CH.SetConsoleOutputEncoding(); CH.SetConsoleColor(); switch (CH.GetChoiceFromUser(new[] { "Attachment", "Presentation" }, true, true).ChoisedIndex) { case 0: new Predictor().Predict(); break; case 1: Console.WriteLine("Ha-ha there is nothing. See source files in folder \"Presentation\""); break; } Console.ReadKey(); }
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(); }
private static void Main(string[] args) { CH.SetConsoleOutputEncoding(); CH.SetConsoleColor(); //TODO 1.Создать консольное приложения для работы со списком покупок. // 2.Добавить возможность добавления покупки «называние» «цена» // 3.Добавить возможность «узнать цену товара» // 4.Добавить возможность «вывести товары дороже чем» var purchasesList = new Dictionary <string, decimal>(); var filterValue = 0m; var filterDirection = 0; var isPriceVisible = false; var selectedMenuIndex = -1; string[] menuOptions = { "Add purchase", //0 "Set price filter", //1 "Show/Hide prices", //2 "Exit" //3 }; InitializePurchasesListByDefault(purchasesList); while (true) { Console.Clear(); WritePurchasesListToConsole(purchasesList, isPriceVisible, filterDirection, filterValue); if (selectedMenuIndex == -1) // Show main menu { Console.WriteLine("Options:"); selectedMenuIndex = CH.GetChoiceFromUser(menuOptions).ChoisedIndex; } else { switch (selectedMenuIndex) { case 0: var newPurchase = GetNewPurchaseInfo(); if (purchasesList.ContainsKey(newPurchase.Item1)) { Console.WriteLine("Purchase already exist in list or invalid"); } else { purchasesList.Add(newPurchase.Item1, newPurchase.Item2); Console.WriteLine("Purchase was added to list"); } break; case 1: string[] options = { "No", //0 "Yes i do, i want to see purchases with price LOWER than...", //1 "Yes i do, i want to see purchases with price HIGHER than..." //2 }; Console.WriteLine("Do you want to filter list?"); filterDirection = CH.GetChoiceFromUser(options).ChoisedIndex; if (filterDirection != 0) { filterValue = GetPriceFilterValue(); } break; case 2: Console.WriteLine("Do you want to see prices in the purchases list?"); isPriceVisible = CH.GetChoiceFromUser(new[] { "No", "Yes" }).ChoisedIndex != 0; break; case 3: return; } selectedMenuIndex = -1; } } }