Exemplo n.º 1
0
        static void UserInterface()
        {
            while (true)
            {
                Console.WriteLine("Please select one:");
                Console.WriteLine("view all books");
                Console.WriteLine("add a book");
                Console.WriteLine("borrow a book");
                Console.WriteLine("return a book");
                Console.WriteLine("view book bag");
                Console.WriteLine("exit");

                string userChoice = Console.ReadLine().ToLower();

                if (userChoice == "view all books")
                {
                    Console.WriteLine($"{Library}");
                }
                else if (userChoice == "add a book")
                {
                    Console.WriteLine("Please enter the title");
                    string title = Console.ReadLine();

                    Console.WriteLine("Please enter the author's first name");
                    string firstName = Console.ReadLine();

                    Console.WriteLine("Please enter the author's last name");
                    string lastName = Console.ReadLine();

                    Console.WriteLine("Please enter the number of pages");
                    int numberOfPages = int.Parse(Console.ReadLine());

                    Console.WriteLine("Please enter the genre");
                    Genre genre = (Genre)Enum.Parse(typeof(Genre), Console.ReadLine());

                    Author author = new Author(firstName, lastName);

                    Book book = new Book()
                    {
                        Title         = title,
                        Author        = author,
                        NumberOfPages = numberOfPages,
                        Genre         = genre
                    };

                    Library.AddBook(book);
                }

                if (userChoice == "exit")
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// below is code that creates a book based off of user input for title, author, and genre
        /// </summary>
        /// <param name="title">the title of the book</param>
        /// <param name="firstName">the author's first name</param>
        /// <param name="lastName">the author's last name</param>
        public static void AddABook(string title, string firstName, string lastName)
        {
            Book book = new Book()
            {
                Title  = title,
                Author = new Author()
                {
                    FirstName = firstName, LastName = lastName
                },
                Genre = Genre.SciFi
            };

            Library.AddBook(book);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Is creating a new instance of a book which takes in the users inputs and creates a new instance of an author which takes in the users input
        /// the book then takes in the users input for number of pages, genre and then adding the book to the library
        /// </summary>
        /// <param name="title">Title of the book to be added</param>
        /// <param name="firstName">Author's First Name to be added</param>
        /// <param name="lastName">Author's Last Name to be added</param>
        /// <param name="numberOfPages">Amount of pages in the book</param>
        /// <param name="genre">The category to be placed</param>
        static void AddABook(string title, string firstName, string lastName, int numberOfPages)
        {
            Book book = new Book()
            {
                Title  = title,
                Author = new Author()
                {
                    FirstName = firstName,
                    LastName  = lastName
                },
                NumberOfPages = numberOfPages,
                Genre         = Genre.Scifi
            };

            Library.AddBook(book);
        }
Exemplo n.º 4
0
        static void LoadBooks()
        {
            Library.AddBook(new Book()
            {
                Title = "Harry Potter"
            }
                            );

            Library.AddBook(new Book()
            {
                Title = "Lord of the Flies"
            }
                            );

            Console.WriteLine($"{Library}");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates 5 initial books and puts them in the Library
        /// </summary>
        static void LoadBooks()
        {
            Book hatchet = new Book()
            {
                Title = "Hatchet", Author = new Author()
                {
                    FirstName = "John", LastName = "Lewis"
                }, Genre = Genre.History
            };
            Book got = new Book()
            {
                Title = "Song of Ice and Fire", Author = new Author()
                {
                    FirstName = "George", LastName = "Martin"
                }, Genre = Genre.History
            };
            Book scar = new Book()
            {
                Title = "Scarlett Letter", Author = new Author()
                {
                    FirstName = "Nathaniel", LastName = "Hawthorne"
                }, Genre = Genre.History
            };
            Book prairie = new Book()
            {
                Title = "Little House on the Prairie", Author = new Author()
                {
                    FirstName = "Laura", LastName = "Wilder"
                }, Genre = Genre.History
            };
            Book war = new Book()
            {
                Title = "The Art of War", Author = new Author()
                {
                    FirstName = "Sun", LastName = "Tzu"
                }, Genre = Genre.History
            };

            Library.AddBook(hatchet);
            Library.AddBook(got);
            Library.AddBook(scar);
            Library.AddBook(prairie);
            Library.AddBook(war);
        }
Exemplo n.º 6
0
        /// <summary>
        /// when completed, the method below will load books into the bookshelf
        /// </summary>
        public static void LoadBooks()
        {
            Book first = new Book {
                Title = "Alice in Wonderland", Author = new Author()
                {
                    FirstName = "Lewis", LastName = "Carol"
                }
            };
            Book second = new Book {
                Title = "Green Eggs and Ham", Author = new Author()
                {
                    FirstName = "Dr.", LastName = "Suess"
                }, Genre = Genre.Mystery
            };


            Library.AddBook(first);
            Library.AddBook(second);
        }
Exemplo n.º 7
0
        /// <summary>
        /// The ForEach is iterating over all items in the BookBag and displaying them to the user.
        /// response is the users input
        /// converting the users response to an int
        /// TryGetValue is verifying that books contains the book requesting to be removed
        /// remove is removing the book from their checked out books and then adding it back to the available list of books
        /// </summary>
        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.AddBook(returnedBook);
        }