Esempio n. 1
0
        /// <summary>
        /// Adds six books for interaction
        /// </summary>
        public static void LoadBooks()
        {
            // Create Books

            // Book 1
            Book   EndersGame = new Book();
            Author author1    = new Author("Orson", "Scott Card");

            EndersGame.Title      = "Ender\'s Game";
            EndersGame.BookAuthor = author1;
            EndersGame.BookGenre  = (Book.Genre) 1;

            // Book 2
            Book   LotR    = new Book();
            Author author2 = new Author("J.R.R.", "Tolkien");

            LotR.Title      = "The Lord of the Rings: The Fellowship of the Ring";
            LotR.BookAuthor = author2;
            LotR.BookGenre  = (Book.Genre) 2;

            // Book 3
            Book   TheShining = new Book();
            Author author3    = new Author("Stephen", "King");

            TheShining.Title      = "The Shining";
            TheShining.BookAuthor = author3;
            TheShining.BookGenre  = (Book.Genre) 3;

            // Book 4
            Book   Hamlet  = new Book();
            Author author4 = new Author("William", "Shakespeare");

            Hamlet.Title      = "Hamlet";
            Hamlet.BookAuthor = author4;
            Hamlet.BookGenre  = (Book.Genre) 4;

            // Book 5
            Book   TheMazeRunner = new Book();
            Author author5       = new Author("James", "Dashner");

            TheMazeRunner.Title      = "The Maze Runner";
            TheMazeRunner.BookAuthor = author5;
            TheMazeRunner.BookGenre  = (Book.Genre) 5;

            // Book 6
            Book   RedOctober = new Book();
            Author author6    = new Author("Tom", "Clancy");

            RedOctober.Title      = "The Hunt for Red October";
            RedOctober.BookAuthor = author6;
            RedOctober.BookGenre  = (Book.Genre) 6;

            // Adding Books to the Library
            Library.Add(EndersGame);
            Library.Add(LotR);
            Library.Add(TheShining);
            Library.Add(Hamlet);
            Library.Add(TheMazeRunner);
            Library.Add(RedOctober);
        }
Esempio n. 2
0
        /// <summary>
        /// This method handles the book loading process
        /// that is used to display all of the Library books to the user.
        /// </summary>
        static void LoadBooks()
        {
            Book a = new Book
            {
                Title  = "Pride and Prejudice",
                Author = new Author()
                {
                    FirstName = "Jane", LastName = "Austen"
                },
                Genre = Genre.Romance
            };

            Book b = new Book
            {
                Title  = "1984",
                Author = new Author()
                {
                    FirstName = "George", LastName = "Orwell"
                },
                Genre = Genre.Drama
            };

            Book c = new Book
            {
                Title  = "The Hobbit",
                Author = new Author()
                {
                    FirstName = "J.R.R.", LastName = "Tolkien"
                },
                Genre = Genre.Fantasy
            };

            Book d = new Book
            {
                Title  = "The Lion, the Witch and the Wardrobe",
                Author = new Author()
                {
                    FirstName = "C.S.", LastName = "Lewis"
                },
                Genre = Genre.Fantasy
            };

            Book e = new Book
            {
                Title  = "Jane Eyre",
                Author = new Author()
                {
                    FirstName = "Charlotte", LastName = "Bronte"
                },
                Genre = Genre.Drama
            };

            Library.Add(a);
            Library.Add(b);
            Library.Add(c);
            Library.Add(d);
            Library.Add(e);
        }
Esempio n. 3
0
        /// <summary>
        /// This method takes in the book data as three string parameters,
        /// instantiates a new Book object and adds it to the Library object.
        /// </summary>
        /// <param name="title">The title of the book</param>
        /// <param name="firstName">The first name of the author of the book</param>
        /// <param name="lastName">The last name of the author of the book</param>
        static void AddABook(string title, string firstName, string lastName)
        {
            Book book = new Book()
            {
                Title  = title,
                Author = new Author()
                {
                    FirstName = firstName, LastName = lastName
                },
                Genre = Genre.Romance
            };

            Library.Add(book);
        }
Esempio n. 4
0
        static void AddABook(string title, string firstName, string lastName, int numberOfPages, Genre genre)
        {
            Book book = new Book()
            {
                Title  = title,
                Author = new Author()
                {
                    FirstName = firstName,
                    LastName  = lastName
                },
                NumberOfPages = numberOfPages,
                Genre         = genre
            };

            Library.Add(book);
        }
Esempio n. 5
0
        static void ReturnBook()
        {
            Dictionary <int, Book> books = new Dictionary <int, Book>();

            Console.WriteLine("Which book would you like to return");
            int counter = 1;

            foreach (var item in BookBag)
            {
                books.Add(counter, item);
                Console.WriteLine($"{counter++}. {item.Title} - {item.Author.FirstName} {item.Author.LastName}");
            }

            string response = Console.ReadLine();

            int.TryParse(response, out int selection);
            books.TryGetValue(selection, out Book returnedBook);
            BookBag.Remove(returnedBook);
            Library.Add(returnedBook);
        }
Esempio n. 6
0
        /// <summary>
        /// Chooses a book to return back to the library from your book bag
        /// </summary>
        /// <param name="title">Title of the targeted return book</param>
        public static void ReturnBook(string title)
        {
            Dictionary <int, Book> books = new Dictionary <int, Book>();
            int counter = 0;

            foreach (Book item in BookBag)
            {
                books.Add(counter++, item);
            }
            counter = 0;
            int key = 0;

            foreach (Book item in BookBag)
            {
                if (item.Title == title)
                {
                    key = counter;
                }
                counter++;
            }

            Library.Add(books[key]);
            BookBag.Remove(books[key]);
        }
Esempio n. 7
0
        /// <summary>
        /// Controls the user experience for the app
        /// </summary>
        public static void UserInterface()
        {
            Console.WriteLine("Welcome to Phil\'s Lending Library! Please choose an option below to get started:");
            bool quit = false;

            while (!quit)
            {
                Console.WriteLine();
                Console.WriteLine("1. View All Books");
                Console.WriteLine("2. Add a Book");
                Console.WriteLine("3. Borrow a Book");
                Console.WriteLine("4. Return a Book");
                Console.WriteLine("5. View Book Bag");
                Console.WriteLine("6. Exit");
                Console.WriteLine();

                string choice = Console.ReadLine();
                Console.WriteLine();

                switch (choice)
                {
                case "1":
                    foreach (Book novel in Library)
                    {
                        Console.WriteLine($"- {novel.Title} By: {novel.BookAuthor.FirstName} {novel.BookAuthor.LastName} -- {novel.BookGenre} genre");
                    }
                    break;

                case "2":
                    Console.WriteLine("Please enter the title of the book:");
                    string title = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Please enter the author\'s first name:");
                    string first = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Please enter the author\'s last name:");
                    string last = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Please select the genre of this book");
                    int genre = 0;
                    while (genre < 1 || genre > 6)
                    {
                        foreach (int i in Enum.GetValues(typeof(Book.Genre)))
                        {
                            Console.WriteLine($"{i}. {(Book.Genre)i}");
                        }
                        string genreAnswer = Console.ReadLine();
                        genre = Int32.TryParse(genreAnswer, out int result) ? result : 0;
                    }
                    Book book = new Book();
                    book.Title      = title;
                    book.BookAuthor = new Author(first, last);
                    book.BookGenre  = (Book.Genre)genre;
                    Library.Add(book);
                    break;

                case "3":
                    Console.WriteLine("Choose the book that you would like to borrow:");
                    int count  = 0;
                    int borrow = -1;
                    while (borrow < 0 || borrow > Library.Count())
                    {
                        count = 0;
                        foreach (Book b in Library)
                        {
                            Console.WriteLine($"{count + 1}. {b.Title} By: {b.BookAuthor.FirstName} {b.BookAuthor.LastName} -- {b.BookGenre} genre");
                            count++;
                        }
                        Console.WriteLine();
                        string answer = Console.ReadLine();
                        borrow = Int32.TryParse(answer, out int result) ? result : -1;
                    }
                    count = 0;
                    foreach (Book b in Library)
                    {
                        if (borrow == count + 1)
                        {
                            BorrowBook(b.Title);
                        }
                        count++;
                    }
                    break;

                case "4":
                    Console.WriteLine("Choose the book that you would like to return:");
                    int count2  = 0;
                    int borrow2 = -1;
                    while (borrow2 < 0 || borrow2 > BookBag.Count)
                    {
                        count2 = 0;
                        foreach (Book b in BookBag)
                        {
                            Console.WriteLine($"{count2 + 1}. {b.Title} By: {b.BookAuthor.FirstName} {b.BookAuthor.LastName} -- {b.BookGenre} genre");
                            count2++;
                        }
                        Console.WriteLine();
                        string answer = Console.ReadLine();
                        borrow2 = Int32.TryParse(answer, out int result) ? result : -1;
                    }
                    count2 = 0;
                    Book returnBook = new Book();
                    foreach (Book b in BookBag)
                    {
                        if (borrow2 == count2 + 1)
                        {
                            returnBook = b;
                        }
                        count2++;
                    }
                    ReturnBook(returnBook.Title);
                    break;

                case "5":
                    foreach (Book i in BookBag)
                    {
                        Console.WriteLine($"- {i.Title} By: {i.BookAuthor.FirstName} {i.BookAuthor.LastName} -- {i.BookGenre} genre");
                    }
                    break;

                case "6":
                    quit = true;
                    break;

                default:
                    Console.WriteLine("Invalid Selection Please Try Again");
                    break;
                }
            }
        }