示例#1
0
 public void ListOut()
 {
     foreach (GeneralInfo x in Info)
     {
         if (x as Book != null)
         {
             Book book = x as Book;
             Console.WriteLine(book.ToString());
         }
         else if (x as SchoolBook != null)
         {
             SchoolBook school = x as SchoolBook;
             Console.WriteLine(school.ToString());
         }
         else if (x as Magazin != null)
         {
             Magazin magazin = x as Magazin;
             Console.WriteLine(magazin.ToString());
         }
     }
 }
示例#2
0
        static void Main(string[] args)
        {
            PrintEdition printEdition1 = new PrintEdition("Book");
            Book         book1         = new Book("Harry Potter and the Prisoner of Azkaban", "United Kingdom", 1999, 464, "hard", 30);
            Author       author1       = new Author("Joanne", "Rowling");
            Publishing   publishing1   = new Publishing("Bloomsbury");

            PrintEdition printEdition2 = new PrintEdition("Magazin");
            Magazin      magazin2      = new Magazin("Vogue", "USA", 1998, 73, "soft", 10.5);
            //Magazin magazin2 = new Magazin("Vogue", "USA", 1998, 73, "soft", -20.5);
            Author     author2     = new Author("Alena", "Doletskaya");
            Publishing publishing2 = new Publishing("Condé Nast");

            PrintEdition printEdition3 = new PrintEdition("School Book");
            SchoolBook   schoolBook3   = new SchoolBook("Upstream. Elementary A2 Student's Book", "United Kingdom", 2005, 128, "soft", 12.5);
            Author       author3       = new Author("Virginia", "Evans");
            Publishing   publishing3   = new Publishing("Express Publishing");

            Printer Printer = new Printer();

            Object[] arr = new Object[] { printEdition1, book1, author1, publishing1, printEdition2, magazin2, author2, publishing2, printEdition3, schoolBook3, author3, publishing3 };

            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(Printer.IAmPrinting(arr[i]));
            }
            author1.Comment();
            publishing3.Comment();

            Console.WriteLine();
            Console.Write(author1.Name + " " + author1.Surname);
            if (author1 is ICommentable)
            {
                Console.WriteLine(" is a very famous author");
            }
            else
            {
                Console.WriteLine("is a beginner");
            }

            Console.WriteLine();
            printEdition1.Equals(magazin2);


            Console.WriteLine("\n\n\n\n\n~~~~~LAB_6~~~~~\n");

            Library lib1 = new Library();

            lib1.Add(book1);
            lib1.Add(magazin2);
            lib1.Add(schoolBook3);
            lib1.ListOut();

            Console.WriteLine("\n\nControl: ");
            Control control = new Control();

            control.CountSchool();
            control.FullPrice();


            Console.WriteLine("\n\n\n\n\n~~~~~LAB_7~~~~~\n");

            try
            {
                lib1.Delete(schoolBook3);
            }
            catch (DeleteElementException ex)
            {
                Console.WriteLine(ex.Message + "\nMethod with exception: " + ex.TargetSite + "\n" + ex.StackTrace + "\n\n");
            }

            try
            {
                Book book12 = new Book("", "United Kingdom", 1999, 464, "hard", 30);
            }
            catch (EmptyTitle ex)
            {
                Console.WriteLine(ex.Message + "\nMethod with exception: " + ex.TargetSite + "\n" + ex.StackTrace + "\n\n");
            }

            try
            {
                Magazin magazin22 = new Magazin("Vogue", "USA", 2021, 73, "soft", 10.5);
            }
            catch (ImpossibleYear ex)
            {
                Console.WriteLine(ex.Message + "\nMethod with exception: " + ex.TargetSite + "\n" + ex.StackTrace + "\n\n");
            }

            try
            {
                SchoolBook schoolBook32 = new SchoolBook("Upstream. Elementary A2 Student's Book", "United Kingdom", 2005, 128, "soft", 12.5);//год подходит
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nMethod with exception: " + ex.TargetSite + "\n" + ex.StackTrace + "\n\n");
            }

            try
            {
                int a = 4;
                int b = 0;
                a = a / b;
            }
            catch (DivideByZeroException ex)
            {
                Console.WriteLine(ex.Message + "\nMethod with exception: " + ex.TargetSite + "\n" + ex.StackTrace + "\n\n");
            }

            finally
            {
                Console.WriteLine("The work is done!!!\nI hope so...\n\n");
            }
        }