// precondition: all textboxes must have correct data type entered
        private void button1_Click(object sender, EventArgs e)
        {
            LibraryBook myBook = new LibraryBook();
            {
                GetBookInfo(myBook);
                bookList.Add(myBook);
                bookListBox.Items.Add(myBook.Title);

                titleTextBox.Clear();
                authorTextBox.Clear();
                publisherTextBox.Clear();
                copyrightTextBox.Clear();
                callNumberTextBox.Clear();

                titleTextBox.Focus();          // postcondition: new item in listbox and all textboxes are empty
            }
        }
Beispiel #2
0
        List <LibraryBook> books    = new List <LibraryBook>();              //list to keep track of books

        private void addBookBtn_Click(object sender, EventArgs e)            //click button
        {                                                                    //Precondition: all text boxes must be filled
            //postcondition: adds item to list box
            int currentListboxIndex = titlesListBox.SelectedIndex;

            string t  = titleTxt.Text;
            string a  = authorTxt.Text;
            string p  = publishTxt.Text;
            string cN = callNumTxt.Text;
            int    cRy;//variables to hold values from text boxes

            if (int.TryParse(cpYTxt.Text, out cRy))
            {
                ;                                    //parse
            }
            else
            {
                MessageBox.Show("Enter a year above 0!"); //error msg
            }
            newBook._title         = t;                   //changing variables from other class to match text boxes
            newBook._author        = a;
            newBook._publisher     = p;
            newBook._callNumber    = cN;
            newBook._copyRightYear = cRy;
            int bookcount = books.Count();


            if (bookcount >= 0)


            {
                LibraryBook newBook = new LibraryBook(t, a, p, cN, cRy);
                books.Add(newBook);
                titlesListBox.Items.Add("Title: " + newBook._title);
            }

            else
            {
                MessageBox.Show("0 books!");
            }
        }
Beispiel #3
0
        //Precondition: title!="",author!="",publisher!="",copyright>0,callnumber!=""
        //Postcondition: if the above conditions are meet, a new library book object is created.
        //then it is added to the list box with the title added to display the title in the list.
        //if the criteria was not meet, an error message displayed. The textboxes were then cleared.
        private void addBttn_Click(object sender, EventArgs e)
        {
            int copyright;

            if (titleTxt.Text != "" && authorTxt.Text != "" && publisherTxt.Text != "" && int.TryParse(copyrightTxt.Text, out copyright) &&
                callnumTxt.Text != "")
            {
                LibraryBook book = new LibraryBook(titleTxt.Text, authorTxt.Text, publisherTxt.Text, copyright, callnumTxt.Text);
                Books.Add(book);
                BookList.Items.Add(titleTxt.Text);
            }
            else
            {
                MessageBox.Show("Invalid input");
            }

            titleTxt.Clear();
            authorTxt.Clear();
            publisherTxt.Clear();
            copyrightTxt.Clear();
            callnumTxt.Clear();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            // Creates 5 new objects of librarybook class

            LibraryBook book_1 = new LibraryBook("Dune", "Frank Herbert", "Penguin Books", 1965, "00000");
            LibraryBook book_2 = new LibraryBook("Dune Messiah", "Frank Herbert", "Penguin Books", 1969, "11111");
            LibraryBook book_3 = new LibraryBook("Childern of Dune", "Frank Herbert", "Penguin Books", 1976, "22222");
            LibraryBook book_4 = new LibraryBook("God Emperor of Dune", "Frank Herbert", "Penguin Books", 1981, "33333");
            LibraryBook book_5 = new LibraryBook("Heretics of Dune", "Frank Herbert", "Penguin Books", 1984, "44444");

            // Array that stores the objects
            LibraryBook[] bookInventory = { book_1, book_2, book_3, book_4, book_5 };

            //Printout of the inventory
            WriteLine("Current Book Inventory and Status" + Environment.NewLine); // displays a message
            PrintOut(bookInventory);                                              // calls Printout method display current inventory and relevant information


            //changing either the book's publisher or call number or check out the book
            book_1.CheckOut();
            book_2.CheckOut();
            book_3.Publisher  = "Hasan's Books";
            book_4.CallNumber = "1234";
            book_5.Publisher  = "Mohammad's Books";

            // Printout of the inventory
            WriteLine("Updated Book Inventory and Status #1" + Environment.NewLine); // displays a message
            PrintOut(bookInventory);                                                 // calls Printout method display current inventory and relevant information


            //The books returning
            book_1.ReturnToShelf();
            book_2.ReturnToShelf();

            //Printout of the inventory
            WriteLine("Updated Book Inventory and Status #2" + Environment.NewLine); // displays a message
            PrintOut(bookInventory);                                                 // calls Printout method display current inventory and relevant information
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            // derived class objects

            LibraryBook book1 =
                new LibraryBook("To Kill a Mockingbird", "Harper Lee", "J. B. Lippincott & Co.", 1964, "BC");
            LibraryBook book2 =
                new LibraryBook("Where the Red Fern Grows", "Wilson Rawls", "Doubleday", 1961, "LC");
            LibraryBook book3 =
                new LibraryBook("The Alchemist", "Paulo Coelho", "HarperTorch", 1990, "PC");
            LibraryBook book4 =
                new LibraryBook("Candide", "Voltaire", "Cramer", 1820, "OC");
            LibraryBook book5 =
                new LibraryBook("The Stranger", "Albert Camus", "Camus", 1984, "HC");


            //create array for 5 objects
            LibraryBook[] books = new LibraryBook[5];


            //initialize array with objects
            books[0] = book1;
            books[1] = book2;
            books[2] = book3;
            books[3] = book4;
            books[4] = book5;

            // ----------------------------------------------------------------------------------
            //Dr. Wright I had trouble constructing a method for these tests.
            //Instead I tried doing it without a method, because I had an overload error.
            //My apologies for leaving the method out, I couldn't get it to run otherwise.
            // ----------------------------------------------------------------------------------

            WriteLine("Before: ");
            WriteLine();


            // for each loop to assign arrays to the ToString
            foreach (LibraryBook currentBook in books)
            {
                Console.WriteLine(currentBook); //implicitly calls ToString method
            } //end foreach

            WriteLine("After: ");
            WriteLine();

            // data manipulation for 2nd test

            book1.Publisher = "Grant";
            book1.CheckOut(); //show that book is checked out
            book2.Publisher = "John";
            book3.Publisher = "Max";
            book4.Publisher = "Bad";
            book5.Publisher = "Tim";
            book5.CheckOut(); //show that book is checked out


            // for each loop to assign arrays to the ToString
            foreach (LibraryBook currentBook in books)
            {
                Console.WriteLine(currentBook); //implicitly calls ToString method
            } //end foreach


            WriteLine("Books that are currently checked out: ");
            WriteLine();
            WriteLine();
            WriteLine();

            WriteLine(book1); //displays the books that are checked out
            WriteLine(book5); // same as above
        } //end main
 private void GetBookInfo(LibraryBook book)
 {
     book._title = titleTextBox.Text;                    // precondition: must have text
     book._author = authorTextBox.Text;                  // precondition: must have text
     book.Publisher = publisherTextBox.Text;             // precondition: must have text
     book._copyright = int.Parse(copyrightTextBox.Text); // precondition: must have integer
     book.CallNumber = callNumberTextBox.Text;           // precondition: must have text
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            //Creating objects
            LibraryBook book1 =
                new LibraryBook("How to Fish", "Fiz O Sea", "Fish Inc.", 2007, 52, true);
            LibraryBook book2 =
                new LibraryBook("Book of Names", "Doctor Lingual", "Dictionary Editors", 2012, 49, false);
            LibraryBook book3 =
                new LibraryBook("Monster Slayer", "Heroic Sam", "Monster Fighters", 2014, 61, false);
            LibraryBook book4 =
                new LibraryBook("How to Lose All Your Money", "Begger Jordan", "Soup Kitchen", 2015, 86, true);
            LibraryBook book5 =
                new LibraryBook("Survival Book", "Caveman Jim", "Brickhouse Inc.", 1993, 42, true);

            //Creating array
            LibraryBook[] books = new LibraryBook[5];

            books[0] = book1;
            books[1] = book2;
            books[2] = book3;
            books[3] = book4;
            books[4] = book5;

            //Displaying List
            void Original()
            {
                foreach (LibraryBook book in books)
                {
                    Console.WriteLine(book);
                    Console.WriteLine();
                }
            }

            //Displaying Altered List
            void Altercation1()
            {
                book1.CheckOut();
                book4.CheckOut();
                foreach (LibraryBook book in books)
                {
                    Console.WriteLine(book);
                    Console.WriteLine();
                }
            }

            //Displaying Original-altered List
            void Altercation2()
            {
                book1.ReturntoShelf();
                book1.ReturntoShelf();
                foreach (LibraryBook book in books)
                {
                    Console.WriteLine(book);
                    Console.WriteLine();
                }
            }

            Console.WriteLine("Original");
            Console.WriteLine();
            Original();
            Console.WriteLine();

            Console.WriteLine("First Altercation");
            Console.WriteLine();
            Altercation1();
            Console.WriteLine();

            Console.WriteLine("Second Altercation");
            Console.WriteLine();
            Altercation2();
            Console.WriteLine();
        }