Ejemplo n.º 1
0
        private static void Main()
        {
            var train = new Train[8];

            CreateArrayOfTrains(train);
            var body = new[]
            {
                "Menu:", "Search train by number", "Show all trains"
            };

            do
            {
                var menuSelect = Menu.CreateMenuInt(body);
                switch (menuSelect)
                {
                case 1:
                    Console.Clear();
                    Console.Write("Enter number of your train - ");
                    var trainNumberForSearch = ConsoleExtension.CheckInt() - 1;
                    if (trainNumberForSearch > 8)
                    {
                        Console.WriteLine("Error!");
                        ConsoleExtension.WaitingAction();
                        break;
                    }
                    ShowTrainByNumber(train[trainNumberForSearch]);
                    break;

                case 2:
                    Console.Clear();
                    ShowAllTrains(train);
                    break;
                }
            } while (true);
        }
Ejemplo n.º 2
0
        private static List <string> CreateNewBook()
        {
            var subSelect = Menu.CreateMenuInt(new[]
                                               { "Do you want to enter new book or enter the default book?", "New", "Default" }
                                               );

            var pageText = new List <string>();

            Console.Clear();
            if (subSelect == 1)
            {
                Console.Write("How many pages u want to see? - ");
                var pages = ConsoleExtension.CheckInt();
                for (var i = 0; i < pages; i++)
                {
                    Console.Write($"Enter text of page №{i + 1}: ");
                    pageText.Add(Console.ReadLine());
                }
            }
            else
            {
                pageText = new List <string>()
                {
                    "1 page book", "2 page book", "3 page book"
                };
            }
            Console.Write("Done! Press any key for continue");
            Console.ReadKey();
            return(pageText);
        }
Ejemplo n.º 3
0
        private static void Main()
        {
            var body = new[]
            {
                "Select your position : ", "Worker", "Accountant", "Manager"
            };
            var workerId = Menu.CreateMenuIntWithoutEsc(body);

            Console.Write("\nHow many hours did you work in the last month? - ");
            var hours = ConsoleExtension.CheckInt();

            switch (workerId)
            {
            case 0:
                ShowBonus(Accountant.Post.Worker, hours);
                break;

            case 1:
                ShowBonus(Accountant.Post.Accountant, hours);
                break;

            case 2:
                ShowBonus(Accountant.Post.Manager, hours);
                break;
            }
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        private static void CreateArrayOfTrains(IList <Train> train)
        {
            Console.Write("How many trains u want to add manual? (max value = 8 trains) - ");
            var numberOfTrains = CheckNumberOfTrain();

            if (numberOfTrains != train.Count)
            {
                Console.WriteLine($"\n{train.Count - numberOfTrains} trains will have default values!\n");
                ConsoleExtension.WaitingAction();
            }
            for (var i = 0; i < train.Count; i++)
            {
                if (i >= numberOfTrains)
                {
                    var j = i + 1;
                    train[i] = new Train($"Destination {j}", j, $"0{j}:00");
                    continue;
                }
                Console.Clear();
                Console.WriteLine($"Enter train №{i+1}");
                Console.Write("\nEnter destination - ");
                var destination = Console.ReadLine();
                Console.Write("Enter train number - ");
                var trainNumber = ConsoleExtension.CheckInt();
                Console.Write("Enter departure time - ");
                var departureTime = Console.ReadLine();
                train[i] = new Train(destination, trainNumber, departureTime);
            }
        }
Ejemplo n.º 5
0
        private static void Main()
        {
            Console.WriteLine("Enter a, b:");
            var a    = ConsoleExtension.CheckInt();
            var b    = ConsoleExtension.CheckInt();
            var body = new[]
            {
                "Select an action on the numbers:", "Sum", "Sub", "Mul", "Div"
            };

            switch (Menu.CreateMenuIntWithoutEsc(body))
            {
            case 0:
                Console.WriteLine($"\nSum {a} + {b} = {Calculator.Sum(a, b)}");
                break;

            case 1:
                Console.WriteLine($"\nSub {a} + {b} = {Calculator.Sub(a, b)}");
                break;

            case 2:
                Console.WriteLine($"\nMul {a} + {b} = {Calculator.Mul(a, b)}");
                break;

            case 3:
                DivByZeroException(a, b);
                break;
            }

            Console.ReadKey();
        }
Ejemplo n.º 6
0
        private static void Main()
        {
            Console.Write("Enter count of number - ");
            var count = ConsoleExtension.CheckInt();

            Console.WriteLine($"Average of {count} random numbers = {DelegateAverage.GetAverage(count)}");
            Console.ReadKey();
        }
Ejemplo n.º 7
0
        private static void Main()
        {
            Console.WriteLine("Enter 3 numbers:");
            var             num1            = ConsoleExtension.CheckInt();
            var             num2            = ConsoleExtension.CheckInt();
            var             num3            = ConsoleExtension.CheckInt();
            AverageDelegate averageDelegate = (a, b, c) => (a + b + c) / 3;
            var             average         = averageDelegate(num1, num2, num3);

            Console.WriteLine($"\nAverage of {num1}, {num2}, {num3} = {0:00.00}", average);
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        private static int CheckNumberOfTrain()
        {
            var numberOfTrains = ConsoleExtension.CheckInt();

            if (numberOfTrains <= 8)
            {
                return(numberOfTrains);
            }
            Console.WriteLine("Exceeded maximum number of trains!");
            numberOfTrains = 8;
            ConsoleExtension.WaitingAction();

            return(numberOfTrains);
        }
Ejemplo n.º 9
0
        private static void Main()
        {
            Console.Write("Enter model of notebook - ");
            var model = Console.ReadLine();

            Console.Write("Enter manufacturer of notebook - ");
            var manufacturer = Console.ReadLine();

            Console.Write("Enter price of notebook - ");
            var price    = ConsoleExtension.CheckInt();
            var notebook = new Notebook(model, manufacturer, price);

            Console.WriteLine("Notebook:");
            Console.WriteLine($"Model: {notebook.Model}");
            Console.WriteLine($"Manufacturer: {notebook.Manufacturer}");
            Console.WriteLine($"Price: {notebook.Price} UAH");
            Console.ReadKey();
        }
Ejemplo n.º 10
0
        static void Main()
        {
            var list = new List <int>();

            Console.Write("How many numbers u want to add? - ");
            var numbers = ConsoleExtension.CheckInt();

            for (var i = 0; i < numbers; i++)
            {
                Console.Write($"\nEnter number №{i+1} - ");
                list.Add(ConsoleExtension.CheckInt());
            }
            Console.WriteLine("List before sort:");
            list.ShowList();
            list.SortUpList();
            Console.WriteLine("\nList after sort:");
            list.ShowList();
            Console.ReadKey();
        }
Ejemplo n.º 11
0
        private static void Main()
        {
            Console.Write("Enter the month of your birth - ");
            var birthMonth = ConsoleExtension.CheckInt();

            Console.Write("Enter the day of your birth - ");
            var birthDay = ConsoleExtension.CheckInt();
            var today    = DateTime.Now;
            int leftYear;

            if (today.Month < birthMonth)
            {
                leftYear = today.Year;
            }
            else
            {
                leftYear = today.Year + 1;
            }
            var birthday = new DateTime(leftYear, birthMonth, birthDay);
            var left     = birthday - today;

            Console.WriteLine($"Before your birthday is left: {left.Days} days");
            Console.ReadKey();
        }
Ejemplo n.º 12
0
 private static int PageReturn(string act)
 {
     Console.Clear();
     Console.Write($"Which page do you want to {act} a comment? - ");
     return(ConsoleExtension.CheckInt());
 }