示例#1
0
        public void AddBook()
        {
            Console.WriteLine("ADD A BOOK!");

            Console.WriteLine("Author name?");
            string author = Console.ReadLine();

            Console.WriteLine("Title?");
            string title = Console.ReadLine();

            double price = -1;

            while (price < 0)
            {
                Console.WriteLine("Price?");
                if (!Double.TryParse(Console.ReadLine(), out price))
                {
                    Console.WriteLine("I'm sorry, but that's not a number!");
                    price = -1;
                }
                else if (price < 0)
                {
                    Console.WriteLine("I'm sorry, but the number must be zero, or greater!!");
                }
            }

            ErrorCode ec = theList.Add(author, title, price);

            errors(ec);
            // STUDENTS: YOUR ERROR-CHECKING CODE SHOULD GO HERE!
        }
示例#2
0
        public void AddBook()
        {
            Console.WriteLine("ADD A BOOK!");

            Console.WriteLine("Author name?");
            string author = Console.ReadLine();

            Console.WriteLine("Title?");
            string title = Console.ReadLine();

            double price = -1;

            while (price < 0)
            {
                Console.WriteLine("Price?");
                if (!Double.TryParse(Console.ReadLine(), out price))
                {
                    Console.WriteLine("I'm sorry, but that's not a number!");
                    price = -1;
                }
                else if (price < 0)
                {
                    Console.WriteLine("I'm sorry, but the number must be zero, or greater!!");
                }
            }

            //if ec is Duplicate Book, print the message to the user
            //if ec is OK, print the message to the user

            ErrorCode ec = theList.Add(author, title, price);

            if (ec == ErrorCode.DuplicateBook)
            {
                Console.WriteLine("Book is a duplicate!");
            }
            else if (ec == ErrorCode.OK)
            {
                Console.WriteLine("Book was added!");
            }
        }
示例#3
0
        public void AddBook()
        {
            Console.WriteLine(); //Spacing/aesthetics

            Console.WriteLine("ADD A BOOK!");

            Console.WriteLine("Author name?");
            string author = Console.ReadLine();

            Console.WriteLine("Title?");
            string title = Console.ReadLine();

            double price = -1;

            while (price < 0)
            {
                Console.WriteLine("Price?");
                if (!Double.TryParse(Console.ReadLine(), out price))
                {
                    Console.WriteLine("Sorry, your entry is not a valid price!");
                    price = -1;
                }
                else if (price < 0)
                {
                    Console.WriteLine("Sorry, you must enter a number greater than or equal to zero!");
                }
            }

            ErrorCode ec = theList.Add(author, title, price);

            if (ec == ErrorCode.DuplicateBook)
            {
                Console.WriteLine("This book is already in the library!");
            }
            else
            {
                Console.WriteLine("This book was successfully added to the library.");
            }
        }
示例#4
0
        public void AddBook()
        {
            Console.WriteLine("ADD A BOOK!");

            Console.WriteLine("Author name?");
            string author = Console.ReadLine();

            Console.WriteLine("Title?");
            string title = Console.ReadLine();

            double price = -1;

            while (price < 0)
            {
                Console.WriteLine("Price?");
                if (!Double.TryParse(Console.ReadLine(), out price))
                {
                    Console.WriteLine("I'm sorry, but that's not a number!");
                    price = -1;
                }
                else if (price < 0)
                {
                    Console.WriteLine("I'm sorry, but the number must be zero, or greater!!");
                }
            }

            ErrorCode ec = theList.Add(author, title, price);

            if (ec == ErrorCode.DuplicateBook)
            {
                Console.WriteLine("Duplicate book found. Entry failed!");
            }
            if (ec == ErrorCode.OK)
            {
                Console.WriteLine("Book was successfully entered.");
            }
        }
示例#5
0
        public void AddBook()
        {
            Console.WriteLine("ADD A BOOK!");

            Console.WriteLine("Author name?");
            string author = Console.ReadLine();

            Console.WriteLine("Title?");
            string title = Console.ReadLine();

            double price = -1;

            while (price < 0)
            {
                Console.WriteLine("Price?");
                if (!Double.TryParse(Console.ReadLine(), out price))
                {
                    Console.WriteLine("I'm sorry, but that's not a number!");
                    price = -1;
                }
                else if (price < 0)
                {
                    Console.WriteLine("I'm sorry, but the number must be zero, or greater!!");
                }
            }

            ErrorCode ec = theList.Add(author, title, price);

            if (ec == ErrorCode.OK)
            {
                Console.WriteLine("successfully added a book");
            }
            else
            {
                Console.WriteLine("failed to add a book");//make thses more fancy
            }
        }