Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Book[] library      = new Book[50];
            int    libraryCount = 0;
            int    libraryIdx   = 0;

            string   cmd  = "";
            string   lCmd = "";
            Example1 eg   = new Example1();

            while (cmd.ToLower() != "exit")
            {
                cmd  = eg.Ask("Awaiting input?");
                lCmd = cmd.ToLower();
                if (lCmd == "add")
                {
                    Book tmp = new Book();
                    tmp.author     = eg.Ask("Please enter Author >");
                    tmp.title      = eg.Ask("Please enter Title >");
                    tmp.checkedout = false;
                    int.TryParse(eg.Ask("Please enter Current Shelf >"), out tmp.shelf);
                    library[libraryCount] = tmp;
                    libraryCount++;
                }
                if (lCmd == "list")
                {
                    for (int idx = 0; idx < libraryCount; idx++)
                    {
                        Book book = library[idx];
                        if (book.isDeleted == true)
                        {
                            library[idx] = library[idx - 1];
                            libraryCount--;
                        }
                        eg.MyPrinter($"Book Index = {idx} : {book.author},{book.title},{book.shelf},{book.checkedout}");
                    }
                }
                if (lCmd == "delete")
                {
                    int chosenBook = 0;
                    int.TryParse(eg.Ask("What number book in the list would you like to delete?"), out chosenBook);
                    for (int reset = 1; reset < libraryCount; reset++)
                    {
                        library[chosenBook] = library[chosenBook + 1];
                        chosenBook++;
                    }

                    libraryCount--;
                }
                if (lCmd == "checkout")
                {
                    int check = 0;
                    int.TryParse(eg.Ask("Which book would you like to check out?"), out check);
                    library[check].checkedout = true;
                }
                if (lCmd == "return")
                {
                    int check = 0;
                    int.TryParse(eg.Ask("Which book would you like to check out?"), out check);
                    library[check].checkedout = false;
                }
                //implement delete book from library
                //implement checkout book from library (set the checked out bool to true
                //implement return book
            }
            eg.MyPrinter("End of execution");

            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Book[] library      = new Book[50];
            int    libraryCount = 0;
            int    libraryIdx   = 0;

            string   cmd  = "";
            string   lCmd = "";
            Example1 eg   = new Example1();

            while (cmd.ToLower() != "exit")
            {
                cmd  = eg.Ask("Awaiting input?");
                lCmd = cmd.ToLower();
                if (lCmd == "add")
                {
                    Book tmp;
                    tmp.author     = eg.Ask("Please enter Author >");
                    tmp.title      = eg.Ask("Please enter Title >");
                    tmp.checkedout = false;
                    int.TryParse(eg.Ask("Please enter Current Shelf >"), out tmp.shelf);
                    library[libraryCount] = tmp;
                    libraryCount++;
                }
                if (lCmd == "list")
                {
                    foreach (Book book in library)
                    {
                        if (book.author != null | book.title != null)
                        {
                            eg.MyPrinter($"Author: {book.author},Title: {book.title},Shelf: {book.shelf},Checkout: {book.checkedout}");
                        }
                    }
                }
                if (lCmd == "delete")
                {
                    Book tmp = new Book();
                    int  temp;
                    tmp.checkedout = false;
                    int.TryParse(eg.Ask("Please enter list >"), out temp);
                    library[temp] = tmp;
                }
                if (lCmd == "checkout")
                {
                    Book tmp;
                    int  temp;
                    tmp.checkedout = true;
                    int.TryParse(eg.Ask("Please enter list >"), out temp);
                    library[temp].checkedout = tmp.checkedout;
                }
                if (lCmd == "return")
                {
                    Book tmp;
                    int  temp;
                    tmp.checkedout = false;
                    int.TryParse(eg.Ask("Please enter list >"), out temp);
                    library[temp].checkedout = tmp.checkedout;
                }
                if (lCmd == "search")
                {
                    int    count = 0;
                    string tmp   = eg.Ask("Please enter what you want to search by title or author >");
                    if (tmp == "author")
                    {
                        tmp = eg.Ask("Please enter the author are you looking for >");
                        foreach (Book book in library)
                        {
                            if (book.author == tmp)
                            {
                                if (!book.checkedout)
                                {
                                    Console.WriteLine($"List: {count}, Author: {book.author}, Title: {book.title}");
                                }
                            }
                            count++;
                        }
                    }
                    if (tmp == "title")
                    {
                        tmp = eg.Ask("Please enter the title are you looking for >");
                        foreach (Book book in library)
                        {
                            if (book.title == tmp)
                            {
                                if (!book.checkedout)
                                {
                                    Console.WriteLine($"List: {count}, Title: {book.title}, Author: {book.author}");
                                }
                            }
                            Console.WriteLine($"List: {count}, Title: {book.title}, Author: {book.author}");
                            count++;
                        }
                    }
                }
                if (lCmd == "modify")
                {
                    Book tmp  = new Book();
                    int  temp = 0;
                    int.TryParse(eg.Ask("Please enter the list >"), out temp);
                    tmp.checkedout = library[temp].checkedout;
                    tmp.author     = eg.Ask("Please enter Author >");
                    tmp.title      = eg.Ask("Please enter Title >");
                    int.TryParse(eg.Ask("Please enter Current Shelf >"), out tmp.shelf);
                    library[temp] = tmp;
                }
                if (lCmd == "resize")
                {
                    int tempList = 0;
                    int.TryParse(eg.Ask("Please enter the list resize >"), out tempList);
                    Book[] temp = new Book[tempList];
                    for (int i = 0; i < tempList; i++)
                    {
                        temp[i] = library[i];
                    }
                    library = new Book[tempList];
                    library = temp;
                }
                //implement delete book from library
                //implement checkout book from library (set the checked out bool to true
                //implement return book
            }
            eg.MyPrinter("End of execution");

            Console.ReadKey();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Book[] library      = new Book[50];
            int    libraryCount = 0;
            int    libraryidx   = 0;


            string   cmd  = "";
            string   lCmd = "";
            Example1 eg   = new Example1();

            while (cmd.ToLower() != "exit")
            {
                cmd  = eg.Ask("Awaiting input?");
                lCmd = cmd.ToLower();
                if (lCmd == "add")
                {
                    Book tmp = new Book();
                    tmp.author     = eg.Ask("Please enter Author >");
                    tmp.title      = eg.Ask("Please enter Title >");
                    tmp.checkedout = false;
                    int.TryParse(eg.Ask("Please enter Current Shelf >"), out tmp.shelf);

                    library[libraryCount] = tmp;
                    libraryCount++;
                }
                if (lCmd == "list")
                {
                    for (int idx = 0; idx < libraryCount; idx++)
                    {
                        Book book = library[idx];
                        eg.MyPrinter($"Book Index={idx} : {book.author}, {book.title}, {book.shelf}, {book.checkedout}");
                    }
                }
                if (lCmd == "delete")
                {
                    int deleteBook = 0;
                    int.TryParse(eg.Ask("What number book in the list would you like to delete?"), out deleteBook); // Take users requested deletion line
                    for (int fix = 1; fix < libraryCount; fix++)                                                    // moves the entire list up on in the array ex. 1->2 2->3 3->4
                    {
                        library[deleteBook] = library[deleteBook + 1];                                              // set value of requested line equal to the line above ex. requestedDelete = book above in array
                        deleteBook++;                                                                               // Change users requested line to be the line above ex. book above in array = requestedDelete
                    }
                    libraryCount--;                                                                                 // deletes last line
                }
                if (lCmd == "checkout")
                {
                    int    bookFind = 0;
                    string checkedOutx;
                    int.TryParse(eg.Ask("What number book in the list are you looking for?"), out bookFind);
                    Book book = library[bookFind];
                    checkedOutx = eg.Ask($"Is {book.title} The book you would like to check out? (Y/N)");

                    if (checkedOutx == "Y")
                    {
                        library[bookFind].checkedout = true;
                    }
                    else if (checkedOutx == "N")
                    {
                        Console.WriteLine("Ok, what would you like to do next?");
                    }
                    else
                    {
                        Console.WriteLine("You big dumb, thats not a Y or N");
                    }
                }
                if (lCmd == "return")
                {
                    int returnBook = 0;
                    int.TryParse(eg.Ask(" What number book in the list would you like to return?"), out returnBook);
                    library[returnBook].checkedout = false;
                }

                //implement delete book from library
                //implement checkout book from library (set the checked out bool to true
                //implement return book
            }
            eg.MyPrinter("End of execution");

            Console.ReadKey();
        }