Esempio n. 1
0
        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;
                }
            }
        }
Esempio n. 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();
        }
Esempio n. 3
0
        private const int SleepInterval = 150; //Интервал обновления

        private static void Main(string[] args)
        {
            CH.SetConsoleOutputEncoding();
            CH.SetConsoleColor();

            Console.CursorVisible = false;

            //Varian_1_Old();
            Variant_2_New();
        }
Esempio n. 4
0
        private static void Main(string[] args)
        {
            CH.SetConsoleOutputEncoding();
            CH.SetConsoleColor();

            var students = new List <Student>
            {
                new Student("Abdul", "Student 1", "Departament 1", 1, "G1"),
                new Student("Vdul", "Student 2", "Departament -2", 1, "G2"),
                new Student("Opozdal", "Student 3", "Departament 3", 1, "G3"),
                new Student("Umni", "Student 4", "Departament 666", 1, "G666"),
                new Student("Knyzz", "From last table", "Departament 666", 1, "G666") //4
            };

            var lecturers = new List <Lecturer>
            {
                new Lecturer("Uchit", " Chemuto", "Gdeto", "O chomto"),
                new Lecturer("NE Uchit", " Chemuto", "TamTO", "Ni o chom")
            };

            var heads = new List <HeadLecturrer>
            {
                new HeadLecturrer("Zloy", "Dulahan", "Hell", 666)
            };

            var univarcity = new University();

            foreach (var student in students)
            {
                univarcity.UnivrsityHumans.Add(student);
            }

            foreach (var lecturer in lecturers)
            {
                univarcity.UnivrsityHumans.Add(lecturer);
            }

            foreach (var head in heads)
            {
                univarcity.UnivrsityHumans.Add(head);
            }

            CH.WriteSeparator();

            univarcity.UnivrsityHumans.Add(students[4]); //there must be error in log

            CH.WriteSeparator();
            CH.WriteSeparator();

            univarcity.UniversityWork();

            Console.ReadKey();
        }
Esempio n. 5
0
        private static void Main(string[] args)
        {
            CH.SetConsoleColor();
            CH.SetConsoleOutputEncoding();

            var newStudents = new List <Student> // TODO надо закоментить ненужные
            {
                new Student(),
                new Student {
                    LastName = null
                },
                new Student {
                    FirstName = null
                },
                null
            };

            var group    = new StudentGroup(new List <Student>(), new ConsoleLogger());
            var newGroup = new StudentGroup(new List <Student>(newStudents), new ConsoleLogger());


            try
            {
                foreach (var student in newStudents)
                {
                    group.AddStudent(student);
                }
            }
            catch (InvalidStudentInput e)
            {
                Console.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.Message);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }


            try
            {
                group.AddStudentsFromGroup(newGroup);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.ReadKey();
        }
Esempio n. 6
0
        private static void Main(string[] args)
        {
            CH.SetConsoleOutputEncoding();
            CH.SetConsoleColor();

            var songs = new List <Song>
            {
                new Song("Super Band", "Super Song"),
                new Song(title: "Super Song"),
                new Song("Super Band"),
                new Song("Giper Band", "Awful Song"),
                new Song("Super Band", "Super Song"),
                new Song("Just Band", "Isn't Song"),
                new Song("Band of justice", "Super Song"),
                new Song(),
                new Song("My", "First SOng", 500, 300),
                new Song("My", "Second song", 1500, 700)
            };

            var myFirstAlbum = new Album("My First Album"); // or new Album();

            foreach (var song in songs)
            {
                myFirstAlbum.AddSong(song);
            }

            var player = new Player();

            var rand = new Random(DateTime.Now.Second);

            Console.Write($"We are ready to play All album ({myFirstAlbum.Songs.Count})");
            Console.ReadKey();
            player.PlayAlbum(myFirstAlbum);

            var from = rand.Next(0, myFirstAlbum.Songs.Count);

            Console.WriteLine(Environment.NewLine);
            Console.Write($"We are ready to play from song #{from + 1} to end of album");
            Console.ReadKey();
            player.PlayAlbum(myFirstAlbum, from);

            from = rand.Next(0, myFirstAlbum.Songs.Count);
            var to = rand.Next(from, myFirstAlbum.Songs.Count);

            Console.WriteLine(Environment.NewLine);
            Console.Write($"We are ready to play album from song #{from + 1} to #{to + 1} song");
            Console.ReadKey();
            player.PlayAlbum(myFirstAlbum, from, to);

            Console.WriteLine("That is all. Goodbye");
            Console.ReadKey();
        }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            CH.SetConsoleColor();
            CH.SetConsoleOutputEncoding();

            TaskOne();
            CH.WriteSeparator();
            CH.WriteSeparator();
            TaskTwo();
            CH.WriteSeparator();
            CH.WriteSeparator();
            TaskThree();

            Console.ReadKey();
        }
Esempio n. 8
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();
        }
Esempio n. 9
0
        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();
        }
Esempio n. 10
0
        private static void Main(string[] args)
        {
            CH.SetConsoleColor();
            CH.SetConsoleOutputEncoding();

            var tracks = new List <Track>
            {
                new Track("SomeFilePath0", "Track #0", "Some Band", new TimeSpan(1, 0, 0, 0)),
                new Track("SomeFilePath0", "Track #1", "Some Band", new TimeSpan(0, 1, 0, 0)),
                new Track("SomeFilePath0", "Track #2", "Some Band", new TimeSpan(0, 0, 1, 0)),
                new Track("SomeFilePath0", "Track #3", "Some Band", new TimeSpan(0, 0, 0, 1))
            };
            var labum = new Album("Album which will be serialized", new LinkedList <Track>(tracks));

            IAlbumSerializer serializer = new BinaryAlbumSerializer(MusicLibraryDir);

            Console.WriteLine("Saving into file:");

            var filePath = serializer.SaveToFile(labum);

            Console.WriteLine($"Labum was successfully saved. FilePath: {filePath}");
            CH.WriteSeparator();
            Console.ReadKey();

            Console.WriteLine("Loading from file:");

            var labumFromFile = serializer.LoadFromFile(filePath);

            CheckAlbum(labumFromFile);
            CH.WriteSeparator();
            Console.ReadKey();

            Console.WriteLine("Loading from BinaryArray:");

            var buffer = File.ReadAllBytes(filePath);
            var labumFromBinaryArray = serializer.LoadFromBinaryArray(buffer);

            CheckAlbum(labumFromBinaryArray);
            CH.WriteSeparator();
            Console.ReadKey();
        }
Esempio n. 11
0
        private static void Main(string[] args)
        {
            CH.SetConsoleColor();
            CH.SetConsoleOutputEncoding();

            var op         = new NewsOperator();
            var subscriber = new NewsSubscriber(NewsCategory.Sport);

            var newNews = new News
            {
                Category         = NewsCategory.Sport | NewsCategory.Events,
                Title            = SomeNewsTitleString,
                ShortDescription = SomeNewsDescriptionString,
                Content          = SomeNewsContentString
            };

            op.Subscribe(subscriber);

            op.AddNews(newNews);

            Console.ReadKey();
        }
Esempio n. 12
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();
        }
Esempio n. 13
0
        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;
                }
            }
        }