Exemplo n.º 1
0
        public void Wyw9()
        {
            Book b1 = new Book("123p", "T1", "A1", 24.99);

            Book b2 = new Book("113p", "T2", "A2", 24.99);

            Book b3 = new Book("1s23p", "T3", "A3", 24.99);

            Book b4 = new Book("1243p", "T4", "A4", 24.99);

            BookLibrary Lib = new BookLibrary();

            Lib.AddBook(b1);
            Lib.AddBook(b2);
            Lib.AddBook(b3);
            Lib.AddBook(b4);

            Lib.PrintAll();

            List <Book> n1 = Lib.SearchAuthor("A2");

            foreach (Book b in n1)
            {
                Console.WriteLine("Informacje o ksiazce:");
                Console.WriteLine(b.GetISBN());
                Console.WriteLine(b.GetTitle());
                Console.WriteLine(b.GetAuthor());
                Console.WriteLine();
            }
        }
Exemplo n.º 2
0
 public static BookLibrary GetInstance()
 {
     if (_instance == null)
     {
         _instance = new BookLibrary();
     }
     return(_instance);
 }
Exemplo n.º 3
0
        static void Zad9()
        {
            Book bookInstance  = new Book("Chocolate", "Joanne Harris", 40);
            Book bookInstance1 = new Book("Kosmiczne zachwyty", "Neil DeGrasse Tyson", 30.90);
            Book bookInstance2 = new Book("Jak mniej myśleć", "Christel Petitcollin", 50.20);
            Book bookInstance3 = new Book("Planer AGH", "URSS AGH", 0);

            BookLibrary bookLibrary  = BookLibrary.GetInstance();
            BookLibrary bookLibrary2 = BookLibrary.GetInstance(); //Jest to to samo co bookLibrary, referencja do tego samego obiektu, ponieważ BookLibrary to Singleton, a więc może istniec tylko jedna istancja tej klasy

            bookLibrary.Add(bookInstance);
            bookLibrary.Add(bookInstance1);
            bookLibrary.Add(bookInstance2);
            bookLibrary.Add(bookInstance2); //Próba dodania 2 raz tego samego, operacja nie powoduje faktycznego dodania drugi raz tego samego obiektu
            bookLibrary.Add(bookInstance3);
            bookLibrary2.Remove(bookInstance);
            bookLibrary.Print();

            Console.WriteLine("\nPodaj autora by sprawdzić czy istnieje taka książka");
            string authorToFind = Console.ReadLine();
            Book   bookFound    = bookLibrary.FindByAuthor(authorToFind);

            if (bookFound != null)
            {
                Console.WriteLine(bookFound.ToString());
            }

            Console.WriteLine("\nPodaj tytuł by sprawdzić czy istnieje taka książka");
            string titleToFind = Console.ReadLine();

            bookFound = bookLibrary.FindByTitle(titleToFind);
            if (bookFound != null)
            {
                Console.WriteLine(bookFound.ToString());
            }
        }