Beispiel #1
0
 public static void Input_Info(Printed_Edition p)
 {
     Console.WriteLine("Input name: ");
     p.Name = Console.ReadLine();
     try
     {
         Console.WriteLine("Input number of pages: ");
         p.Pages = int.Parse(Console.ReadLine());
         Console.WriteLine("Input number of chapters: ");
         p.Chapters = int.Parse(Console.ReadLine());
         Console.WriteLine("Input price in USD: ");
         p.Price = double.Parse(Console.ReadLine());
         Console.WriteLine("Input number of goods: ");
         p.Quantity = int.Parse(Console.ReadLine());
     }
     catch (System.FormatException)
     {
         Console.WriteLine("Invalid input!");
     }
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            Printed_Edition[] arr      = new Printed_Edition[2];
            Magazine          magazine = new Magazine();
            Book book = new Book();

            Input_Info(book);
            Input_Info(magazine);
            arr[0] = book;
            arr[1] = magazine;
            for (; ;)
            {
                string[] action;
                int      i;
                Console.WriteLine("Input 1 to choose book or 2 to choose magazine");
                int.TryParse(Console.ReadLine(), out i);
                i--;
                Console.WriteLine("Actions: ");
                Console.WriteLine("sn 'name' to set name\t\t\tgn to get name");
                Console.WriteLine("sp 'pages' to set pages\t\t\tgp to get pages");
                Console.WriteLine("sc 'chapters' to set chapters\t\t\tgc to get chapters;");
                Console.WriteLine("sr 'price' to set price\t\t\tgp to get price ");
                Console.WriteLine("sq 'quantity' to set quantity\t\t\tgq to get quantity");
                Console.WriteLine("pa to print all info\t\t\tex to exit");
                Console.WriteLine("Input: ");
                action = Console.ReadLine().Split(" ");
                if (action[0] == "sn")
                {
                    arr[0].Name = action[1];
                }
                try
                {
                    if (action[0] == "sp")
                    {
                        arr[0].Pages = int.Parse(action[1]);
                    }
                    if (action[0] == "sc")
                    {
                        arr[0].Chapters = int.Parse(action[1]);
                    }
                    if (action[0] == "sp")
                    {
                        arr[0].Price = double.Parse(action[1]);
                    }
                    if (action[0] == "sq")
                    {
                        arr[0].Quantity = int.Parse(action[1]);
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Invalid input!");
                }
                if (action[0] == "gn")
                {
                    Console.WriteLine($"Name: {arr[i].Name}");
                }
                if (action[0] == "gp")
                {
                    Console.WriteLine($"Pages: {arr[i].Pages}");
                }
                if (action[0] == "gc")
                {
                    Console.WriteLine($"Chapters: {arr[i].Chapters}");
                }
                if (action[0] == "gp")
                {
                    Console.WriteLine($"Price: {arr[i].Price}");
                }
                if (action[0] == "gq")
                {
                    Console.WriteLine($"Quantity: {arr[i].Quantity}");
                }
                if (action[0] == "pa")
                {
                    Console.WriteLine(arr[i].GetInfo());
                }
                if (action[0] == "ex")
                {
                    break;
                }
            }
        }