Esempio n. 1
0
        ////////////////////////////////////
        // Extra credit methods hereafter //
        ////////////////////////////////////

        /** Construct a Book, taking data from reader.
         * Read through three lines that contain the
         * title, author, and year of publication, respectively.
         * There may be an extra blank line at the beginning.
         * If so ignore it.
         * Nothing beyond the line with the year is read. */
        public Book(StreamReader reader)
        { // code for extra credit!
            int counter = 0;

            string[,] lines = new string[1, 1000];
            string line = reader.ReadLine();

            BookList list = new BookList();

            do
            {
                lines[0, counter] = line;
                counter++;
            } while ((line = reader.ReadLine()) != null);

            reader.Close();

            for (int x = 0; x < counter; x = x + 4)
            {
                tit = lines[0, x];
                aut = lines[0, x + 1];
                yr  = Convert.ToInt32(lines[0, x + 2]);
                //Book book = new Book(tit, aut, yr);
                list.Addbook(new Book(tit, aut, yr));
            }

            Console.WriteLine("\nThe SEMI-AUTO list is:");
            list.PrintList();
        }
Esempio n. 2
0
        /// <summary> Remove book from the list.</summary>
        /// <param name="book"> The book to remove. </param>
        public void RemoveBook(Book book)
        {
            if (!IfBookExists(book))
            {
                throw new ArgumentException("The book doesn't exist!");
            }

            BookList.Remove(book);
        }
Esempio n. 3
0
        /// <summary> Add book to the list.</summary>
        /// <param name="book"> The book to add. </param>
        public void AddBook(Book book)
        {
            if (IfBookExists(book))
            {
                throw new ArgumentException("The book already exists!");
            }

            BookList.Add(book);
        }
        /// <summary> Remove book from the list.</summary>
        /// <param name="book"> The book to remove. </param>
        public void RemoveBook(Book book)
        {
            if (!IfBookExists(book))
            {
                logger.Error("The book doesn't exist!");
                throw new ArgumentException("The book doesn't exist!");
            }

            BookList.Remove(book);
            logger.Info("Book was removed successfully");
        }
        /// <summary> Add book to the list.</summary>
        /// <param name="book"> The book to add. </param>
        public void AddBook(Book book)
        {
            if (IfBookExists(book))
            {
                logger.Error("The book already exists!");
                throw new ArgumentException("The book already exists!");
            }

            BookList.Add(book);
            logger.Info("Book was added successfully");
        }
Esempio n. 6
0
        // Revised AddBook documentation for extra credit:

        /** Adds aBook to the list if aBook is
         * not already in the list.
         * Return true if aBook is added,
         * and false if it was already in the list. */
        public bool AddAllRevised(BookList books)
        { // code for extra credit
            foreach (Book book in list)
            {
                if (list.Contains(book) == false && books.Contains(book) == true)
                {
                    list.Add(book);
                }
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
        /** Test BookList. */
        public static void Main()
        {
            BookList books = new BookList();

            // ...
            books.Addbook(new Book("C# Yellow Book", "Rob Miles", 2011));
            // Add more!
            // ...
            Console.WriteLine("The full list is:");
            books.PrintList();
            // Add more tests to fully test your code.
            // Make sure the correctness of the tests can be seen without reading
            // the source code -- comment on the meanings.
            // ...
        }
Esempio n. 8
0
        /** Test BookList. */
        public static void Main()
        {
            BookList books = new BookList();

            books.Addbook(new Book("C# Yellow Book", "Rob Miles", 2011));
            books.Addbook(new Book("C# Software Solutions", "John Lewis", 2007));                                                                                                                       // MANUAL list "books" has 2 books in it for further tests below
            Console.WriteLine("The MANUAL list is:");
            books.PrintList();                                                                                                                                                                          // MANUAL list: use PrintList() function as a test
            Console.WriteLine("Manual titles by authors are:");
            books.PrintTitlesByAuthor(books.GetListAuthors());                                                                                                                                          // MANUAL list: print titles in booklist as a test
            Console.WriteLine("Manual books by year 2011 are:");
            books.PrintBooksInYears(2011, 2011);                                                                                                                                                        // MANUAL lIST: print books in year 2011 as a test

            BookList tab = new BookList();

            tab.Addbook(new Book(FileUtil.GetDataReader("books.txt")));                                                                                                                                                 // SEMI-AUTO list: added multiple books to booklist in 1 line via new Book constructor w/reader


            new BookList(FileUtil.GetDataReader("books.txt"));                                                                                                                                                                  // FULL-AUTO list: created new booklist with 1 line via mod BookList contructor w/reader


            Book book1 = new Book("C# Yellow Book", "Rob Miles", 2011);
            Book book2 = new Book("C# Yellow Book", "Rob Miles", 2011);
            bool test  = book2.Equals(book1);                                                                                                                                                                                                   // test for same book versus book: returns true since books are same

            Console.WriteLine("\nThe logical test for the same book (both Miles books) is: {0}\n{1}\n{2}\n", test, book1, book2);

            bool test2 = books.Contains(book1);                                                                                                                                                                                         // test for same book in booklist: returns true since book already in booklist books

            Console.WriteLine("\nThe logical test for the same book (Miles) in booklist (books) is: {0}\n{1}\n{2}\n", test2, book1, books);

            BookList bookie = new BookList();

            bookie.Addbook(book1);
            bool test3 = books.AddAll(bookie);                                                                                                                                                                                                  // test for same (items in) booklist versus booklist: return false for duped books

            Console.WriteLine("\nThe logical test for the same booklist is: {0}\n{1}\n{2}\n", test3, books, bookie);

            bool test4 = books.AddAllRevised(bookie);                                                                                                                                                                                   // revised test for same (items in) booklist versus booklist: add missing books & return true

            Console.WriteLine("\nThe logical test for the same booklist is: {0}\n{1}\n{2}\n", test4, books, bookie);
        }
Esempio n. 9
0
 /** Add all the Books in books to this BookList.
  * Return true if the current list was changed.
  * Return false if each Book in books is a
  * duplicate of a Book in the current list. */
 public bool AddAll(BookList books)
 {                 // code for extra credit
     return(true); // so stub compiles
 }