示例#1
0
    // Precondition:  None
    // Postcondition: The LibraryBook class has been tested
    public static void Main(string[] args)
    {
        decimal displayLateFee;


        LibraryBook     book1     = new LibraryBook("The Wright Guide to C#", "Andrew Wright", "UofL Press", 2010, 2, "ZZ25 3G");                                                                    // 1st test book
        LibraryBook     book2     = new LibraryBook("Harriet Pooter", "IP Thief", "Stealer Books", 2000, 3, "AG773 ZF");                                                                             // 2nd test book
        LibraryMovie    movie1    = new LibraryMovie("The Hills have Eyes", "Emily Robertson", 2010, 10, "AA232", 2.0, "Molly Simmins", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.G); //1st test movie
        LibraryMovie    movie2    = new LibraryMovie("The Child", "Tom Boyd", 2019, 10, "A0U32", 1.0, "Sean Smith", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.R);                     //2nd test movie
        LibraryJournal  journal1  = new LibraryJournal("The Wall Street Journal", "The NY Press", 2016, 10, "WW234", 3, 5, "Business", "John Smith");                                                //1st test journal
        LibraryJournal  journal2  = new LibraryJournal("The New Yorker", "The NY Press", 2018, 10, "W9234", 7, 12, "Business", "Yolanda Rogers");                                                    //2nd test journal
        LibraryMusic    music1    = new LibraryMusic("Theory of a Deadman", "The Press", 2018, 10, "QW234", 34.67, "Theory of a Deadman", LibraryMediaItem.MediaType.CD, 5);                         // 1st test music
        LibraryMusic    music2    = new LibraryMusic("Kids Bop 45", "The Kidz", 2019, 10, "XC234", 56.67, "KIDS Inc.", LibraryMediaItem.MediaType.CD, 8);                                            // 2nd test music
        LibraryMagazine magazine1 = new LibraryMagazine("Gossip Central", "Teen Vogue", 2015, 10, "TT189", 7, 6);                                                                                    //1st test magazine
        LibraryMagazine magazine2 = new LibraryMagazine("People", "The Press", 2019, 10, "KJ189", 9, 2);                                                                                             //2nd test magazine

        LibraryPatron patron1 = new LibraryPatron("Ima Reader", "123456");                                                                                                                           // 1st test patron
        LibraryPatron patron2 = new LibraryPatron("Jane Doe", "112233");                                                                                                                             // 2nd test patron
        LibraryPatron patron3 = new LibraryPatron("   John Smith   ", "   654321   ");                                                                                                               // 3rd test patron - Trims?
        LibraryPatron patron4 = new LibraryPatron("Jessie Hehn", "234567");                                                                                                                          // 4th test patron
        LibraryPatron patron5 = new LibraryPatron("AJ Ross", "654321");                                                                                                                              // 5th test patron


        List <LibraryItem> theLibraryItems = new List <LibraryItem> {
            book1, book2, movie1, movie2, journal1, journal2, music1, music2, magazine1, magazine2
        };                                                                                                                                                    // Test list of books, movies, journals,music,and magazines

        WriteLine("Original list of books");
        WriteLine("----------------------");
        PrintItems(theLibraryItems);
        Pause();
    }
示例#2
0
    // Precondition:  None
    // Postcondition: The LibraryBook class has been tested
    public static void Main(string[] args)
    {
        LibraryMovie    movie1   = new LibraryMovie("the movie", "B", 1999, "a1234", 10, 120, "MR.T", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.PG13);
        LibraryMovie    movie2   = new LibraryMovie("the film", "H", 2007, "ghghg1", 14, 100, "MR.A", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.R);
        LibraryJournal  journal1 = new LibraryJournal("Scifi", "SCE", 2019, "f12367", 15, 201, 3, "chemistry", "uofl");
        LibraryMusic    music1   = new LibraryMusic("the music", "musicpub", 1976, "z120", 12, 120, LibraryMediaItem.MediaType.CD, "the who", 12);
        LibraryMagazine mag1     = new LibraryMagazine("The Mag", "MagPub", 1989, "12ACD", 30, 2, 15);

        LibraryBook book1 = new LibraryBook("The Wright Guide to C#", "Andrew Wright", "UofL Press",
                                            2010, "ZZ25 3G", 10);                      // 1st test book
        LibraryBook book2 = new LibraryBook("Harriet Pooter", "IP Thief", "Stealer Books",
                                            2000, "AG773 ZF", 10);                     // 2nd test book
        LibraryBook book3 = new LibraryBook("The Color Mauve", "Mary Smith", "Beautiful Books Ltd.",
                                            1985, "JJ438 4T", 10);                     // 3rd test book
        LibraryBook book4 = new LibraryBook("The Guan Guide to SQL", "Jeff Guan", "UofL Press",
                                            2016, "ZZ24 4F", 10);                      // 4th test book
        LibraryBook book5 = new LibraryBook("    The Big Book of Doughnuts   ", "   Homer Simpson   ", "   Doh Books   ",
                                            2001, "   AE842 7A   ", 10);               // 5th test book - Trims?

        LibraryPatron patron1 = new LibraryPatron("Ima Reader", "123456");             // 1st test patron
        LibraryPatron patron2 = new LibraryPatron("Jane Doe", "112233");               // 2nd test patron
        LibraryPatron patron3 = new LibraryPatron("   John Smith   ", "   654321   "); // 3rd test patron - Trims?

        List <LibraryBook> theBooks = new List <LibraryBook> {
            book1, book2, book3, book4, book5
        };                                                                                        // Test list of books

        //Library Movie test
        WriteLine("Testing the LibraryMovie class");
        WriteLine("--------------------------------");
        WriteLine(movie1);
        WriteLine($"Late Fee: {movie1.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {movie1.CalcLateFee(45):C}\n");
        WriteLine("_____________________________________");
        WriteLine(movie2);
        WriteLine($"Late Fee: {movie2.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {movie2.CalcLateFee(45):C}");
        Pause();

        //Library Journal test
        WriteLine("Testing the LibraryJournal class");
        WriteLine("--------------------------------");
        WriteLine(journal1);
        WriteLine($"Late Fee: {journal1.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {journal1.CalcLateFee(45):C}");
        Pause();

        //Library Music test
        WriteLine("Testing the LibraryMusic class");
        WriteLine("--------------------------------");
        WriteLine(music1);
        WriteLine($"Late Fee: {music1.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {music1.CalcLateFee(45):C}");
        Pause();

        //Library Magazine test
        WriteLine("Testing the LibraryMagazine class");
        WriteLine("--------------------------------");
        WriteLine(mag1);
        WriteLine($"Late Fee: {mag1.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {mag1.CalcLateFee(45):C}");
        Pause();


        WriteLine("Original list of books");
        WriteLine("----------------------");
        PrintBooks(theBooks);
        Pause();

        // Make changes
        book1.CheckOut(patron1);
        book2.Publisher = "Borrowed Books";
        try
        {
            book2.CheckOut(null); // Attempt invalid patron
        }
        catch (ArgumentNullException ex)
        {
            WriteLine("Caught invalid patron sent to CheckOut");
            WriteLine(ex.Message);
        }
        book3.CheckOut(patron2);
        book4.CallNumber = "    AB123 4A    ";
        book5.CheckOut(patron3);
        try
        {
            book5.CopyrightYear = -1234; // Attempt invalid year
        }
        catch (ArgumentOutOfRangeException ex)
        {
            WriteLine("Caught invalid CopyrightYear set:");
            WriteLine(ex.Message);
            WriteLine("Resetting to default year");
            book5.CopyrightYear = book5.DEFAULT_YEAR;
        }

        WriteLine("After changes");
        WriteLine("-------------");
        PrintBooks(theBooks);
        Pause();

        // Return the books
        book1.ReturnToShelf();
        book3.ReturnToShelf();
        book5.ReturnToShelf();

        WriteLine("After returning the books");
        WriteLine("-------------------------");
        PrintBooks(theBooks);
    }
        static void Main(string[] args)
        {
            LibraryItem book1 = new LibraryBook("The Wright Guide to C#", "Andrew Wright", "UofL Press",
                                                2010, 0, "ZZ25 3G");                                                                                                                               // 1st test book
            LibraryItem movie1 = new LibraryMovie("Harriet Pooter", "Stealer Books",
                                                  2000, 0, "AG773 ZF", 189.00, "Michael Bay", LibraryMovie.MediaType.BLURAY, LibraryMovie.MPAARatings.R);                                          // 1st movie test
            LibraryItem cd1 = new LibraryMusic("The Color Mauve", "Beautiful Books Ltd.",
                                               1985, 0, "JJ438 4T", 79, "Adele", LibraryMediaItem.MediaType.CD, 17);                                                                               // CD test
            LibraryItem magazine1 = new LibraryMagazine("The Guan Guide to SQL", "UofL Press",
                                                        2016, 0, "ZZ24 4F", 1, 4);                                                                                                                 // Magazine test
            LibraryItem book5 = new LibraryBook("    The Big Book of Doughnuts   ", "   Homer Simpson   ", "   Doh Books   ",
                                                2001, 0, "   AE842 7A   ");                                                                                                                        // 5th test book - Trims?
            LibraryItem     cSharpQterly = new LibraryJournal("C# Quarterly", "C Sharp Press", 2014, 0, "QRT2014", 4, 20, "Computer Science", "Dr. Wright");                                       //Journal Test
            LibraryItem     book2        = new LibraryBook("Extreme Ownership", "Jocko Willink and LiefBabin", "St. Matrin's Press", 2015, 0, "978-1-250");                                        //Test Book 2
            LibraryItem     movie2       = new LibraryMovie("The Usual Suspects", "Mirmax", 1995, 0, "555897989", 106.00, "Bryan Singer", LibraryMovie.MediaType.VHS, LibraryMovie.MPAARatings.R); //Test Movie #2
            LibraryItem     cd2          = new LibraryMusic("2001", "Interscope", 2001, 0, "8988787984", 86, "Dr. Dre", LibraryMusic.MediaType.CD, 15);                                            //Test CD 2
            LibraryItem     magazine2    = new LibraryMagazine("Time", "Andy Rooney", 1978, 0, "254547", 42, 23);                                                                                  //test magazine 2
            LibraryItem     jounral2     = new LibraryJournal("Planet Earth", "The Discrovery Channel", 2009, 0, "5654123557", 8, 24, "Nature", "Second");                                         //Test Journal #2
            LibraryMagazine magazine3    = new LibraryMagazine("Time", "Andy Rooney", 1978, 0, "7897845", 2, 32);                                                                                  //Same magazine different edition and volume

            LibraryPatron patron1 = new LibraryPatron("Ima Reader", "123456");                                                                                                                     // 1st test patron
            LibraryPatron patron2 = new LibraryPatron("Jane Doe", "112233");                                                                                                                       // 2nd test patron
            LibraryPatron patron3 = new LibraryPatron("   John Smith   ", "   654321   ");                                                                                                         // 3rd test patron - Trims?
            LibraryPatron patron4 = new LibraryPatron("Tiger Woods", "6922251");                                                                                                                   //4th test patron
            LibraryPatron patron5 = new LibraryPatron("John Daly", "251448");                                                                                                                      //5th test patron

            List <LibraryItem> theItems = new List <LibraryItem> {
                book1, movie1, cd1, magazine1, book5, cSharpQterly, book2, movie2, cd2, magazine2, jounral2, magazine3
            };                                                                                                                                                             // Test list of items

            WriteLine("Original list of books");
            WriteLine("----------------------");
            PrintBooks(theItems);
            Pause();

            // Check out books
            book1.CheckOut(patron1);
            cSharpQterly.CheckOut(patron3);
            book2.CheckOut(patron4);
            cd2.CheckOut(patron4);
            cd1.CheckOut(patron5);
            book5.CheckOut(patron2);
            movie1.CheckOut(patron5);

            var checkedOut =
                from i in theItems
                where i.Patron != null
                select i;

            foreach (var i in checkedOut)
            {
                WriteLine($"Currenlty Checked out books: \n");
                WriteLine($"{i} \n");
                WriteLine($"Total Checked out: {checkedOut.Count()}");
            }

            var media =
                from thing in checkedOut
                where thing.Medium
                select thing;

            foreach (var thing in media)
            {
                WriteLine($"")
            }

            var oneAndOnly =
                from one in theItems
                where one

                // try
                //{
                //     movie1.CheckOut(null); // Attempt invalid patron
                // }
                //catch (ArgumentNullException ex)
                //{
                //  WriteLine("Caught invalid patron sent to CheckOut");
                //WriteLine(ex.Message);
                //}

                //WriteLine("Recent Check outs: ");
                //WriteLine("-------------");
                //PrintBooks(theBooks);
                //Pause();

                // Return the books
                //book1.ReturnToShelf();
                //cd1.ReturnToShelf();
                //book5.ReturnToShelf();
                //cSharpQterly.ReturnToShelf();

                // WriteLine("After returning the books");
                // WriteLine("-------------------------");
                // PrintBooks(theBooks);
        }
示例#4
0
    // Precondition:  None
    // Postcondition: The LibraryItem hierarchy is sorted using the IComparable and IComparer classes
    public static void Main(string[] args)
    {
        List <LibraryItem> libraryItemList = new List <LibraryItem>(); //List of Library Items

        //Two test objects for each of the 5 concrete classes
        LibraryBook book1 = new LibraryBook("    Celia, A Slave    ", "Avon", 1999, 7, "11111111",
                                            "Melton A. McLaurin");//Title is surrounded by white space to test trim
        LibraryBook book2 = new LibraryBook("Visual C#: How to Program 6th Edition", "Pearson", 2017, 10, "99999999",
                                            "Deitel");
        LibraryJournal journal1 = new LibraryJournal("Fake Science Monthly", "Nick", 2002, 5, "22222222", 89, 3,
                                                     "Sea Bears and Fairy Tales", "Patrick Star");
        LibraryJournal journal2 = new LibraryJournal("Real Science Monthly", "NASA", 2016, 14, "88888888", 25, 4,
                                                     "Climatology", "Bill Nye");
        LibraryMagazine magazine1 = new LibraryMagazine("Sports Illustrated", "Time", 2016, 7, "33333333", 49, 10);
        LibraryMagazine magazine2 = new LibraryMagazine("Sports Illustrated", "Time", 2017, 10, "77777777", 50, 11);
        LibraryMovie    movie1    = new LibraryMovie("Friday", "NLC", 1995, 7, "44444444", 91.0, "F. Gary Gray",
                                                     LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.R);
        LibraryMovie movie2 = new LibraryMovie("Captain America: Civil War", "Marvel", 2016, 14, "66666666", 147.0,
                                               "Anthony Russo", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.PG13);
        LibraryMusic music1 = new LibraryMusic("Album", "Studio", 2015, 2, "55555555", 27.0, "Singer",
                                               LibraryMediaItem.MediaType.SACD, 7);
        LibraryMusic music2 = new LibraryMusic("Record", "Older Studio", 1987, 5, "00000000", 18.0, "Older Singer",
                                               LibraryMediaItem.MediaType.VINYL, 4);

        //Adds each of the objects above to the List
        libraryItemList.Add(book1);
        libraryItemList.Add(book2);
        libraryItemList.Add(journal1);
        libraryItemList.Add(journal2);
        libraryItemList.Add(magazine1);
        libraryItemList.Add(magazine2);
        libraryItemList.Add(movie1);
        libraryItemList.Add(movie2);
        libraryItemList.Add(music1);
        libraryItemList.Add(music2);

        Console.Out.WriteLine("Original List of Library Items:");
        Console.WriteLine();
        foreach (LibraryItem item in libraryItemList) //Writes all items to the console
        {
            Console.WriteLine(item);
            Console.WriteLine();
        }
        Pause();

        libraryItemList.Sort(); //Sorts the list in ascending natural order
        Console.WriteLine("Sorted List in ascending natural order): ");
        Console.WriteLine();
        foreach (LibraryItem item in libraryItemList) //Writes all items to the console
        {
            Console.WriteLine(item);
            Console.WriteLine();
        }
        Pause();

        libraryItemList.Sort(new DescendingItemOrder()); //Sorts using IComparer class DescendingItemOrder
        Console.WriteLine("Sorted List in descending natural order using IComparer: ");
        Console.WriteLine();
        foreach (LibraryItem item in libraryItemList) //Writes all the items to the console
        {
            Console.WriteLine(item);
            Console.WriteLine();
        }
        Pause();
    }