Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();

               parcels = new List<Parcel>();      // List of parcels
               addresses = new List<Address>();   // List of addresses

               Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
             "Louisville", "KY", 40202);                                                // Test Address 1
               Address a2 = new Address("Jane Doe", "987 Main St.", "",
               "Beverly Hills", "CA", 90210);                                           // Test Address 2
               Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
               "El Paso", "TX", 79901);                                                 // Test Address 3
               Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
               "Portland", "ME", 04101);                                                // Test Address 4

               Letter letter1 = new Letter(a1, a2, 3.95M);                                  // Letter test object
               GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);              // Ground test object
               NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,          // Next Day test object
               85, 7.50M);
               TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0,      // Two Day test object
               80.5, TwoDayAirPackage.Delivery.Saver);

               addresses.Add(a1);
               addresses.Add(a2);
               addresses.Add(a3);
               addresses.Add(a4);

               parcels.Add(letter1);
               parcels.Add(gp1);
               parcels.Add(ndap1);
               parcels.Add(tdap1);
        }
Esempio n. 2
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                "Louisville", "KY", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                "El Paso", "TX", 79901); // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                "Portland", "ME", 04101); // Test Address 4

            Letter letter1 = new Letter(a1, a2, 3.95M);                            // Letter test object
            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);        // Ground test object
            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,    // Next Day test object
                85, 7.50M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                80.5, TwoDayAirPackage.Delivery.Saver);

            List<Parcel> parcels;      // List of test parcels

            parcels = new List<Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(gp1);
            parcels.Add(ndap1);
            parcels.Add(tdap1);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 3
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);        // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);              // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);             // Test Address 4

            Letter            letter1 = new Letter(a1, a2, 3.95M);         // Letter test object
            Letter            letter2 = new Letter(a1, a2, 4.54M);
            Letter            letter3 = new Letter(a2, a4, 7.76M);
            Letter            letter4 = null;                                       //Null test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object
            GroundPackage     gp2     = new GroundPackage(a1, a2, 15, 11, 6, 13.5);
            GroundPackage     gp3     = new GroundPackage(a4, a1, 20, 14, 9, 16.7);
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,  // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a2, a4, 13, 22, 55,    // Next Day test object
                                                            55, 10.50M);

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a3, a1, 44.5, 55.5, 30.0, // Two Day test object
                                                          85.5, TwoDayAirPackage.Delivery.Early);


            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(tdap1);
            parcels.Add(ndap2);
            parcels.Add(letter2);
            parcels.Add(tdap2);
            parcels.Add(letter3);
            parcels.Add(gp3);
            parcels.Add(letter4);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine();
            Console.WriteLine("Descending Zip Order: ");
            parcels.Sort(new DescendingZipOrder()); //sort, using specified comparer class DescendingZipOrder
            foreach (Parcel p in parcels)           //print list
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine();
            Console.WriteLine("Ascending Cost Order: ");
            parcels.Sort(new AscendingCostOrder()); //sort, using specified comparer class AscendingCostOrder
            foreach (Parcel p in parcels)           //print list
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine();
            Console.WriteLine("Ascending Parcel Type/Descending Cost Order: ");
            parcels.Sort(new AscendingParcelSort()); //sort, using specified comparer class AscendingParcelSort
            foreach (Parcel p in parcels)            //print list
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
        }
Esempio n. 4
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);        // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);              // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);             // Test Address 4
            Address a5 = new Address("Lewis Clark", "613 Rainy Way",
                                     "Portland", "ME", 04101);             // Test Address 5
            Address a6 = new Address("Titus Carrol", "3612 Sierra Lane",
                                     "Louisville", "KY", 40202);           // Test Address 6

            Letter            letter1 = new Letter(a1, a2, 3.95M);         // Letter test object
            Letter            letter2 = new Letter(a1, a4, 5.65M);
            Letter            letter3 = new Letter(a4, a6, 4.12M);
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object
            GroundPackage     gp2     = new GroundPackage(a1, a6, 12, 14, 7, 16.7); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a5, a6, 13, 22, 17,     // Next Day test object
                                                            76, 8.90M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a1, a2, 17, 12, 20,     // Next Day test object
                                                            40, 7.23M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a2, a3, 34.5, 23.5, 46.0,
                                                          60.2, TwoDayAirPackage.Delivery.Early);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort();//sort in ascending order
            Console.WriteLine("Sorted List (Ascending):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine("Original List:");//display orginal list again, as per instructions
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new DescendingParcelOrder()); //sort with comparer class
            Console.WriteLine("Sorted List (Descending):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine("Original List:");//display orginal list again, as per instructions
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            //sorted by Parcel type and then cost descending
            parcels.Sort(new ParcelTypeSort()); //sort with EC comparer class
            Console.WriteLine("Sorted List (Parcel Type and Descending cost):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 5
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);    // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);      // Test Address 4

            Letter            letter1 = new Letter(a1, a2, 3.95M);  // Letter test objects (3)
            Letter            letter2 = new Letter(a4, a3, 4.00M);
            Letter            letter3 = new Letter(a2, a3, 2.00M);
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test objects (3)
            GroundPackage     gp2     = new GroundPackage(a1, a2, 20, 5, 10, 15.5);
            GroundPackage     gp3     = new GroundPackage(a2, a1, 2, 13, 4, 30.5);
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,  // Next Day test objects (2)
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a2, 5, 16, 25, 20.0, 15.0M);
            TwoDayAirPackage  tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test objects (2)
                                                           80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a3, a1, 50, 20, 35, 25, TwoDayAirPackage.Delivery.Early);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Adds letter object to the list
            parcels.Add(letter2); // Adds letter object to the list
            parcels.Add(letter3); // Adds letter object to the list
            parcels.Add(gp1);     // Adds GroundPackage object to the list
            parcels.Add(gp2);     // Adds GroundPackage object to the list
            parcels.Add(gp3);     // Adds GroundPackage object to the list
            parcels.Add(ndap1);   // Adds NextDayAirPackage object to the list
            parcels.Add(ndap2);   // Adds NextDayAirPackage object to the list
            parcels.Add(tdap1);   // Adds TwoDayAirPackage object to the list
            parcels.Add(tdap2);   // Adds TwoDayAirPackage object to the list

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            //default sort
            // displays all parcels in the lsit by Cost in Ascending order
            parcels.Sort();
            Console.Out.WriteLine("Default Sort, Ascending by Cost");

            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
            }

            Pause();

            //descending sort
            //displays all the parcels in the list by Destination Zip in Descending order
            parcels.Sort(new DescendingZipOrder());
            Console.Out.WriteLine("Sorted List, Descending by Destination Zip Code");

            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
            }
            Pause();
        }
Esempio n. 6
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);                // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                       // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                             // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                            // Test Address 4
            Address a5 = new Address("Ivy Cat", "1234 Catnip St.",
                                     "Meowville", "KY", 56789);                           // Test Address 5
            Address a6 = new Address("Mia Dog", "9876 Bone St.",
                                     "Growlsville", "NY", 78463);                         // Test Address 6
            Address a7 = new Address("Rex Paw", "321 Treats Blvd.", "Apt. 6",
                                     "Barksville", "TN", 31254);                          // Test Address 7
            Address a8 = new Address("Athena Slithers", "587 Snake Rd.", "Apt. 23",
                                     "Hissington", "LA", 87436);                          // Test Address 8

            Letter letter1 = new Letter(a1, a2, 3.95M);                                   // Test Letter 1
            Letter letter2 = new Letter(a5, a6, 5M);                                      // Test Letter 2
            Letter letter3 = new Letter(a8, a7, 2.50M);                                   // Test Letter 3
            Letter letter4 = new Letter(a6, a8, 4M);                                      // Test Letter 4

            GroundPackage gp1 = new GroundPackage(a2, a1, 5, 6, 7, 8);                    // Test GroundPackage 1
            GroundPackage gp2 = new GroundPackage(a4, a2, 75, 75, 75, 50);                // Test GroundPackage 2
            GroundPackage gp3 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);               // Test GroundPackage 3
            GroundPackage gp4 = new GroundPackage(a5, a8, 20, 30, 30, 45);                // Test GroundPackage 4

            NextDayAirPackage ndap1 = new NextDayAirPackage(a4, a3, 50, 50, 50, 25, 10);  // Test NextDayAirPackage 1
            NextDayAirPackage ndap2 = new NextDayAirPackage(a1, a3, 25, 25, 25, 100, 8);  // Test NextDayAirPackage 2
            NextDayAirPackage ndap3 = new NextDayAirPackage(a2, a4, 50, 50, 50, 100, 15); // Test NextDayAirPackage 3
            NextDayAirPackage ndap4 = new NextDayAirPackage(a1, a3, 25, 15, 15,           // Test NextDayAirPackage 4
                                                            85, 7.50M);

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a3, a2, 50, 25, 50, 30,   // Test TwoDayAirPackage 1
                                                          TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a4, a1, 10, 10, 10, 10,   // Test TwoDayAirPackage 2
                                                          TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Test TwoDayAirPackage 3
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap4 = new TwoDayAirPackage(a7, a6, 50, 75, 60, 80,   // Test TwoDayAirPackage 4
                                                          TwoDayAirPackage.Delivery.Early);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(letter4);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(gp4);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(ndap4);
            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);
            parcels.Add(tdap4);

            Console.WriteLine("Original List:\n");

            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine("Orders by Destination Address Zip in Descending Order:\n");

            // 1) Select all Parcels and order by destination zip (descending)
            var zipDescending =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            foreach (var p in zipDescending)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine("Orders by Cost in Ascending Order:\n");

            // 2) Select all Parcels and order by cost (ascending)
            var costAscending =
                from p in parcels
                orderby p.CalcCost() ascending
                select p;

            foreach (var p in costAscending)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine("Orders by Parcel Type Ascending and then Cost Descending\n");

            // 3) Select all Parcels and order by Parcel type (ascending) and then cost (descending)
            var typeThenCost =
                from p in parcels
                orderby p.GetType().ToString() ascending, p.CalcCost() descending
            select p;

            foreach (var p in typeThenCost)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine("Selects all AirPackages that are Heavy and orders them by Weight\n");

            // 4) Select all AirPackage objects that are heavy and order by weight (descending)
            var heavyAirPackages =
                from p in parcels
                where p is AirPackage
                let aPackage = (AirPackage)p
                               where aPackage.IsHeavy()
                               orderby aPackage.Weight descending
                               select aPackage;

            foreach (var p in heavyAirPackages)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 7
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);                 // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210);              // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                    // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                   // Test Address 4
            Address a5 = new Address("Stan Marsh", "ShTapa Town", "4321 Your Street",
                                     "Pittsburgh", "Pennsylvania", 15201);       // Test Address 5
            Address a6 = new Address("Eric Cartman", "South Park Elementary", "Detention Room 102",
                                     "New York City", "New York", 10001);        // Test Address 6
            Address a7 = new Address("Kenny McCormick", "SoDoSoapa", "1111 Gheto Avenue",
                                     "South Park", "Colorado", 80019);           // Test Address 7
            Address a8 = new Address("Kyle Broflovski", "The Church of God", "5676 Jewish Lane",
                                     "Jersey City", "New Jersey", 07208);        // Test Address 8

            Letter letter1 = new Letter(a1, a2, 3.95M);                          // Letter 1 test object
            Letter letter2 = new Letter(a2, a3, 4.50M);                          // Letter 2 test object
            Letter letter3 = new Letter(a3, a4, 1.50M);                          // Letter 3 test object
            Letter letter4 = new Letter(a4, a8, .75M);                           // Letter 4 test object

            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);      // Ground 1 test object
            GroundPackage gp2 = new GroundPackage(a5, a7, 10, 5, 2, 50);         // Ground 2 test object
            GroundPackage gp3 = new GroundPackage(a7, a1, 15, 20, 25, 35.8);     // Ground 3 test object
            GroundPackage gp4 = new GroundPackage(a2, a6, 60, 50, 23, 150);      // Ground 4 test object

            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,  // Next Day 1 test object
                                                            85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a5, a6, 20, 10, 5,   // Next Day 2 test object
                                                            80, 10.50M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a1, a8, 15, 40, 32,  // Next Day 3 test object
                                                            95, 4.55M);
            NextDayAirPackage ndap4 = new NextDayAirPackage(a2, a7, 100, 50, 75, // Next Day 4 test object
                                                            70, 20.95M);


            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0,  // Two Day 1 test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a2, a4, 30.2, 19.4, 20.5,  // Two Day 2 test object
                                                          90, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a3, a5, 6.5, 9.54, 30.04,  // Two Day 3 test object
                                                          60.25, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap4 = new TwoDayAirPackage(a6, a8, 40.0, 50.5, 33.33, // Two Day 4 test object
                                                          50.75, TwoDayAirPackage.Delivery.Early);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populates list with 4 letter objects
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(letter4);
            parcels.Add(gp1); // Populates list with 4 ground package objects
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(gp4);
            parcels.Add(ndap1); // Populates list with 4 next day air packages objects
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(ndap4);
            parcels.Add(tdap1); // Populates list with 4 two day air packages objects
            parcels.Add(tdap2);
            parcels.Add(tdap3);
            parcels.Add(tdap4);


            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }

            // selects all Parcels and orders them by destination zip in a descending order
            var destinationZip =
                from destZip in parcels
                orderby destZip.DestinationAddress.Zip descending
                select destZip;

            Console.WriteLine("\nParcels Ordered by Destination Zip"); // displays a header for the query
            Console.WriteLine("----------------------------------");

            // displays all parcels ordered by their destination zip
            foreach (var destZip in destinationZip)
            {
                Console.WriteLine(destZip);
            }

            // selects all Parcels and orders them by their Cost in a ascending order
            var cost =
                from c in parcels
                orderby c.CalcCost()
                select c;

            Console.WriteLine("\nParcels Ordered by Cost"); // displays a header for the query
            Console.WriteLine("-----------------------");

            // displays all parcels ordered by their cost
            foreach (var c in cost)
            {
                Console.WriteLine(c);
            }

            // selects all Parcels and orders them by their type (ascending) and their cost (descending)
            var parcelTypeandCost =
                from pTC in parcels
                orderby pTC.GetType().ToString() ascending, pTC.CalcCost() descending
            select pTC;

            Console.WriteLine("\nParcels Ordered by Type and Cost"); // displays a header for the query
            Console.WriteLine("-----------------------");

            // displays all parcels ordered by their type and cost
            foreach (var pTC in parcelTypeandCost)
            {
                Console.WriteLine(pTC);
            }

            Console.WriteLine("\nHeavy AirPackages Ordered by Weight"); // displays a header for the query
            Console.WriteLine("-----------------------------------");

            // selects all AirPackages in parcels that are heavy and orders them by their weight in a descending order
            var heavyAirPackage =
                from hAP in parcels
                where hAP is AirPackage
                let airPackage = (AirPackage)hAP
                                 where airPackage.IsHeavy() == true
                                 orderby airPackage.Weight descending
                                 select airPackage;

            // displays all Air Package parcels that are heavy and ordered by their weight
            foreach (var airPackage in heavyAirPackage)
            {
                Console.WriteLine(airPackage);
            }
        }
Esempio n. 8
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);        // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);              // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);             // Test Address 4
            Address a5 = new Address("Travis Scott", "3845 Straight Up Avenue", "Apt. 8"
                                     , "Houston", "TX", 77001);            // Test Address 5
            Address a6 = new Address("Kendrick Lamar", "2201 Compton Road",
                                     "Compton", "CA", 90059);              // Test Address 6
            Address a7 = new Address("Jaden Smith", "584 Smith Way",
                                     "Los Angeles", "CA", 90001);          // Test Address 7
            Address a8 = new Address("Paul DeNino", "4304 Poseidon Road",
                                     "Miami", "FL", 33018);                // Test Address 8

            Letter letter1 = new Letter(a1, a2, 3.95M);                    // Letter test objects
            Letter letter2 = new Letter(a5, a6, 1.40M);

            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);   // Ground test objects
            GroundPackage gp2 = new GroundPackage(a7, a8, 14, 9, 4, 10);

            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test objects
                                                            85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a6, 20, 12, 10,
                                                            70, 8.00M);

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a7, 46.5, 39.5, 28.0, // Two Day test objects
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a6, a8, 47.8, 29.3, 32.0,
                                                          75.0, TwoDayAirPackage.Delivery.Early);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel> // Adding Address objects to list parcels
            {
                letter1,
                letter2,
                gp1,
                gp2,
                ndap1,
                ndap2,
                tdap1,
                tdap2
            };
            // Displays the original list of parcels in console
            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // Use LINQ to select all Parcels and order by Destination Zip Code in descending order
            var parcelsOrderedByDestZip =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            // Displays the results for the above in console
            Console.WriteLine("Parcels by Destination Zip Code Descending:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsOrderedByDestZip)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // Use LINQ to select all Parcels and order by Cost in ascending order
            var parcelsOrderedByCost =
                from p in parcels
                orderby p.CalcCost() ascending
                select p;

            // Displays the results for the above in console
            Console.WriteLine("Parcels by Cost Ascending:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsOrderedByCost)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // Use LINQ to select all Parcels and order by Parcel type in ascending order then Cost in descending order
            var parcelsOrderedByTypeAndCost =
                from p in parcels
                orderby p.GetType().ToString() ascending, p.CalcCost() descending
            select p;

            // Displays the results for the above in console
            Console.WriteLine("Parcels by Parcel Type Ascending and then Cost Descending:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsOrderedByTypeAndCost)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // Use LINQ to select all AirPackage objects that are considered Heavy and order by Weight in descending order
            var airPackageIsHeavyAndOrderedByWeight =
                from p in parcels
                where p is AirPackage && ((AirPackage)p).IsHeavy() == true
                orderby((AirPackage)p).Weight descending
                select p;

            // Displays the results for the above in console
            Console.WriteLine("AirPackages that are Heavy and Ordered by Weight Descending:");
            Console.WriteLine("====================");
            foreach (Parcel p in airPackageIsHeavyAndOrderedByWeight)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 9
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);          // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 02101);                      // Test Address 4

            Letter            letter1 = new Letter(a1, a2, 3.95M);                  // Letter test 1
            Letter            letter2 = new Letter(a2, a3, 5.50M);                  // Letter test 2
            Letter            letter3 = new Letter(a4, a1, 2.20M);                  // Letter test 3
            GroundPackage     gp1     = new GroundPackage(a3, a2, 11, 9, 8, 7.5);   // Ground test object 1
            GroundPackage     gp2     = new GroundPackage(a1, a4, 9, 5, 5, 10.5);   // Ground test object 2
            GroundPackage     gp3     = new GroundPackage(a4, a3, 2, 3, 4, 6.3);    // Ground test object 3
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object 1
                                                              65, 5.40M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a2, a1, 15, 13, 17,     // Next Day test object 2
                                                            25, 2.50M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object 1
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a2, a3, 22.5, 35.7, 14.0, // Two Day test object 2
                                                          30.2, TwoDayAirPackage.Delivery.Early);


            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            Console.WriteLine("Original List:"); // outputs original list
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();



            parcels.Sort(); // Sort - uses natural order
            Console.WriteLine("Sorted by Cost (ascending order):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();



            parcels.Sort(new DescendingZipSort()); // Sort - uses specified Comparer class
            Console.WriteLine("Sorted by zip (descending natural order) using Comparer:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 10
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);          // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                      // Test Address 4
            Address a5 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 74838);                      // Test Address 4
            Address a6 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 48392);                      // Test Address 4
            Address a7 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 23456);                      // Test Address 4

            Letter            letter1 = new Letter(a1, a7, 3.95M);                  // Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a6, 14, 10, 5, 12.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a2, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a3, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);

            #region added By D4199
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a4, a4, 146.5, 239.5, 428.0, // Two Day test object
                                                          180.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a4, a5, 16.5, 19.5, 18.0,    // Two Day test object
                                                          10.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap4 = new TwoDayAirPackage(a4, a6, 6.5, 9.5, 8.0,       // Two Day test object
                                                          0.5, TwoDayAirPackage.Delivery.Saver);
            GroundPackage gp2 = new GroundPackage(a4, a4, 16, 10, 5, 12.5);            // Ground test object
            GroundPackage gp3 = new GroundPackage(a3, a5, 143, 20, 35, 2.5);           // Ground test object
            GroundPackage gp4 = new GroundPackage(a3, a6, 165, 120, 15, 12.5);         // Ground test object
            GroundPackage gp5 = new GroundPackage(a3, a7, 9, 10, 5, 12.5);             // Ground test object
            #endregion

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(gp1);
            parcels.Add(ndap1);
            parcels.Add(tdap1);

            #region added By D4199

            //Add in additional Parcels to test our sorter better
            parcels.Add(tdap2);
            parcels.Add(tdap3);
            parcels.Add(tdap4);
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(gp4);
            parcels.Add(gp5);

            //Even add some nulls
            parcels.Add(null);
            parcels.Add(null);

            //First display full list
            Console.WriteLine("Original List:");
            PrintList(parcels, p => Console.WriteLine(p?.ToString()));
            Pause();

            //Then Sort by cost and display, using Parcels CompareTo
            Console.WriteLine("Sorted by Cost:");
            parcels.Sort();
            PrintList(parcels, p => Console.WriteLine(p?.CalcCost()));
            Pause();

            //Then Sort by destination zip and display, using ParcelZipCompaer
            Console.WriteLine("Sorted by Destination Zip:");
            parcels.Sort(new ParcelZipComparer());
            PrintList(parcels, p => Console.WriteLine(p?.DestinationAddress?.Zip));
            Pause();

            //Then Sort by type then cost and display, using ParcelTypeComparer
            Console.WriteLine("Sorted by Type then Cost:");
            parcels.Sort(new ParcelTypeComparer());
            PrintList(parcels, p => Console.WriteLine(p?.GetType().ToString() + ": " + p?.CalcCost()));
            Pause();
            #endregion
        }
Esempio n. 11
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);                     // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210);                  // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                        // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                       // Test Address 4

            Letter            letter1 = new Letter(a1, a2, 3.95M);                   // Letter test object
            Letter            letter2 = new Letter(a2, a1, 90.0M);                   // Second Letter test object
            Letter            letter3 = new Letter(a3, a4, 10.0M);                   // Third Letter test object
            Letter            letter4 = new Letter(a3, a1, 6.0M);                    // Fourth Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5);  // Ground test object
            GroundPackage     gp2     = new GroundPackage(a2, a4, 12, 12, 15, 20.8); // Second Ground test object
            GroundPackage     gp3     = new GroundPackage(a1, a2, 9, 8, 7, 15.0);    // Third Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,    // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a4, a1, 10, 6, 5,        // Second Next Day test object
                                                            7, 80.0M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a1, a4, 46.5, 39.5, 28.0,  // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a4, a3, 5, 6, 7,           // Second Two Day test object
                                                          8.0, TwoDayAirPackage.Delivery.Early);


            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(letter4);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            Console.WriteLine("Original List:");           //Start Original list
            Console.WriteLine("====================");     //Help keep parcel lists seperated in console
            foreach (Parcel p in parcels)                  //start loop to display
            {
                Console.WriteLine(p);                      //Write parcel object to console
                Console.WriteLine("===================="); //help keep parcels seperated in console
            }
            Pause();                                       //Wait for user to review console and hit enter


            parcels.Sort();               //Sort using default/natural order
            Console.WriteLine("Parcels sorted in ascending order by Cost");
            foreach (Parcel p in parcels) //Start loop to write sorted parcels to consol
            {
                Console.WriteLine(p);     //Write parcel object to console
                Console.WriteLine("====================");
            }
            Pause();                                          //wait for user to review consol and hit enter

            parcels.Sort(new ParcelDestZipDescendingOrder()); //sort parcels using the class that lists by descending cost
            Console.WriteLine("Parcels sorted in descending order by Cost");
            foreach (Parcel p in parcels)                     //start loop to write sorted parcels
            {
                Console.WriteLine(p);                         // Write parcel object to console
                Console.WriteLine("====================");
            }
            Pause();                                //wait for user to review consol and hit enter

            parcels.Sort(new ParcelTypeCostSort()); //sort using class that orders by type, then cost
            Console.WriteLine("Parcels sorted by type, then by cost");
            foreach (Parcel p in parcels)           //start loop to write parcels to console
            {
                Console.WriteLine(p);               // Write parcel object to console
                Console.WriteLine("====================");
            }
            Pause();//wait for user to review consol and hit enter
        }
Esempio n. 12
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);          // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                      // Test Address 4
            Address a5 = new Address("Tommy Lee", "8923 Grove Street",
                                     "New York", "NY", 00025);                      // Test Address 5
            Address a6 = new Address("Joe Stanton", "1 Rowena Rd", "Apt. 6",
                                     "Las Vegas", "Nevada", 12345);                 // Test Address 6
            Address a7 = new Address("Michael Pineda", "6402 Normandy Way",
                                     "Jacksonville", "IN", 59215);                  // Test Address 7
            Address a8 = new Address("Jack Stone", "888 Laguna Drive", "Unit 4A",
                                     "NeverLand", "GA", 86358);                     // Test Address 8

            Letter            letter1 = new Letter(a1, a2, 3.95M);                  // Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a5, a6, 56.1, 24.8, 23.6, // Two Day test object
                                                          15.7, TwoDayAirPackage.Delivery.Early);
            NextDayAirPackage ndp2 = new NextDayAirPackage(a7, a8, 67.7, 20, 33.3,  // Next Day test object
                                                           78, 9.50M);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(gp1);
            parcels.Add(ndap1);
            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(ndp2);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // Holds the List ordered by Zipcodes
            var sortDestZip = from d in parcels
                              orderby d.DestinationAddress.Zip descending
                              select d;

            Console.WriteLine("===============Sort by Zip List============");
            Console.WriteLine("====================");
            foreach (Parcel parcel in sortDestZip)
            {
                Console.WriteLine(parcel);
                Console.WriteLine("====================");
            }
            Pause();

            // Holds the List ordered by CalcCost
            var sortCost = from d in parcels
                           orderby d.CalcCost() ascending
                           select d;

            Console.WriteLine("===============Sort by Cost List============");
            Console.WriteLine("====================");
            foreach (Parcel parcel in sortCost)
            {
                Console.WriteLine(parcel);
                Console.WriteLine("====================");
            }
            Pause();

            // Holds the list ordered by Parcel Type
            var sortParcelType = from d in parcels
                                 orderby d.GetType().ToString() ascending, d.CalcCost() descending
            select d;

            Console.WriteLine("===============Sort by Parel Type List============");
            Console.WriteLine("====================");
            foreach (Parcel parcel in sortParcelType)
            {
                Console.WriteLine(parcel);
                Console.WriteLine("====================");
            }
            Pause();

            // Holds the List of Air Packages ordered by Weight
            var sortWeight = from d in parcels
                             let dp = d as AirPackage
                                      where (dp != null) && (dp.IsHeavy())
                                      orderby dp.Weight
                                      select d;

            Console.WriteLine("===============Sort by Weight List============");
            Console.WriteLine("====================");
            foreach (var parcel in sortWeight)
            {
                Console.WriteLine(parcel);
                Console.WriteLine("====================");
            }
        }
Esempio n. 13
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);          // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                      // Test Address 4

            Letter            letter1 = new Letter(a1, a2, 3.95M);                  // Letter test object
            Letter            letter2 = new Letter(a4, a3, 1.50M);                  // Letter test object
            Letter            letter3 = new Letter(a2, a3, 8.25M);                  // Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object
            GroundPackage     gp2     = new GroundPackage(a1, a4, 20, 20, 12, 50);  // Ground test object
            GroundPackage     gp3     = new GroundPackage(a3, a2, 8, 32, 18, 32);   // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a2, a1, 5, 35, 26,      // Next Day test object
                                                            62, 12.25M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a3, a4, 34.8, 27.9, 14.8, // Two Day test object
                                                          37.25, TwoDayAirPackage.Delivery.Early);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(gp1);
            parcels.Add(ndap1);
            parcels.Add(tdap1);
            parcels.Add(letter2);
            parcels.Add(gp2);
            parcels.Add(ndap2);
            parcels.Add(tdap2);
            parcels.Add(letter3);
            parcels.Add(gp3);

            Console.WriteLine("Original List:\n");
            Console.WriteLine("====================");

            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }

            Pause();

            //sorts ascending by cost
            parcels.Sort();
            Console.WriteLine("List sorted by cost:\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }

            Pause();

            //sorts decending by zip code
            parcels.Sort(new DecreasingZipCode());
            Console.WriteLine("List Sorted Decending by destination zip code:\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }

            Pause();

            //sorts by type and descending by cost
            parcels.Sort(new ParcelSort());
            Console.WriteLine("List Sorted by Parcel type, then descending by cost:\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
        }
Esempio n. 14
0
        private List <Parcel> parcelList;   // The list of parcels

        // Precondition:  None
        // Postcondition: The form's GUI is prepared for display. A few test addresses are
        //                added to the list of addresses
        public Prog2Form()
        {
            InitializeComponent();

            addressList = new List <Address>();
            parcelList  = new List <Parcel>();

            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);                       // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210);                    // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                          // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                         // Test Address 4
            Address a5 = new Address("John Doe", "111 Market St.", "",
                                     "Jeffersonville", "IN", 47130);                   // Test Address 5
            Address a6 = new Address("Jane Smith", "55 Hollywood Blvd.", "Apt. 9",
                                     "Los Angeles", "CA", 90212);                      // Test Address 6
            Address a7 = new Address("Captain Robert Crunch", "21 Cereal Rd.", "Room 987",
                                     "Bethesda", "MD", 20810);                         // Test Address 7
            Address a8 = new Address("Vlad Dracula", "6543 Vampire Way", "Apt. 1",
                                     "Bloodsucker City", "TN", 37210);                 // Test Address 8

            Letter            letter1 = new Letter(a1, a2, 3.95M);                     // Letter test object
            Letter            letter2 = new Letter(a3, a4, 4.25M);                     // Letter test object
            GroundPackage     gp1     = new GroundPackage(a5, a6, 14, 10, 5, 12.5);    // Ground test object
            GroundPackage     gp2     = new GroundPackage(a7, a8, 8.5, 9.5, 6.5, 2.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,      // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a5, 9.5, 6.0, 5.5,     // Next Day test object
                                                            5.25, 5.25M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a2, a7, 10.5, 6.5, 9.5,    // Next Day test object
                                                            15.5, 5.00M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a5, a7, 46.5, 39.5, 28.0,    // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a8, a1, 15.0, 9.5, 6.5,      // Two Day test object
                                                          75.5, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a6, a4, 12.0, 12.0, 6.0,     // Two Day test object
                                                          5.5, TwoDayAirPackage.Delivery.Saver);


            addressList.Add(a1); // Populate list
            addressList.Add(a2);
            addressList.Add(a3);
            addressList.Add(a4);
            addressList.Add(a5);
            addressList.Add(a6);
            addressList.Add(a7);
            addressList.Add(a8);

            parcelList.Add(letter1); // Populate list
            parcelList.Add(letter2);
            parcelList.Add(gp1);
            parcelList.Add(gp2);
            parcelList.Add(ndap1);
            parcelList.Add(ndap2);
            parcelList.Add(ndap3);
            parcelList.Add(tdap1);
            parcelList.Add(tdap2);
            parcelList.Add(tdap3);
        }
Esempio n. 15
0
        // Precondition:  None
        // Postcondition: Parcels have been created and selected
        //                LINQ results are displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);        // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);              // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);             // Test Address 4
            Address a5 = new Address("Charlotte Jones", "123 Maple St. ",
                                     "Clarksville", "IN", 47129);          // Test Address 5
            Address a6 = new Address("Kayla Kay", "989 Chipp Avenue", "Apt. 2",
                                     "Salem", "IN", 52143);                // Test Address 6
            Address a7 = new Address("Hunter Ansleigh", "554 Herrick Way",
                                     "Jeffersonville", "IN", 47130);       // Test Address 7
            Address a8 = new Address("Mckenzie Caldwell", "2201 Morgan Avenue",
                                     "Charlestown", "KY", 42450);          // Test Address 8


            Letter            letter1 = new Letter(a1, a2, 3.95M);                     // Letter test object 1
            Letter            letter2 = new Letter(a8, a4, 2.05M);                     // Letter test object 2
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5);    // Ground test object 1
            GroundPackage     gp2     = new GroundPackage(a7, a6, 22, 15, 16, 28);     // Ground test object 2
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,      // Next Day test object 1
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a6, a5, 50, 20, 15,        // Next Day test object 2
                                                            120, 9.75M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0,    // Two Day test object 1
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a1, a7, 20.75, 16.20, 20.50, // Two Day test object 2
                                                          120.75, TwoDayAirPackage.Delivery.Early);



            // List of test parcels
            List <Parcel> parcels;

            parcels = new List <Parcel>();

            // Populate list
            parcels.Add(letter1);
            parcels.Add(letter2);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            //Output Original List
            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }



            //Output LINQ query sorted by destination zip in descending order
            Console.WriteLine("Sort By Destination Zip:");
            Console.WriteLine("====================");

            // Holds results of LINQ to sort invoices by destination
            // address zip in descending order
            var sortByDest =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            // foreach loop outputs each parcel selected by query
            foreach (Parcel p in sortByDest)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }



            // Output LINQ query sorted by cost in ascending order
            Console.WriteLine("Sorted by Cost:");
            Console.WriteLine("====================");

            // Holds results of LINQ to sort invoices by cost
            // in ascending order
            var sortByPrice =
                from p in parcels
                orderby p.CalcCost()
                select p;

            // foreach loop outputs each parcel selected by query
            foreach (Parcel p in sortByPrice)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }



            //Output LINQ query sorted by type and cost
            Console.WriteLine("Sorted by Type and Cost List:");
            Console.WriteLine("====================");

            // Holds results of LINQ to sort invoices by Type
            // in ascending order and sorts again by cost in
            // descending order
            var sortByTypeAndCost =
                from p in parcels
                orderby p.GetType().ToString(), p.CalcCost() descending
            select p;

            // foreach loop outputs each parcel selected by query
            foreach (Parcel p in sortByTypeAndCost)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }



            //Output LINQ query sorted by package type and then by weight
            Console.WriteLine("Sorted by Airpackage and Weight");
            Console.WriteLine("====================");

            // Holds results of LINQ to select only AirPackages
            // if they are heavy and then sorts them by weight
            // in descending order
            var sortByWeight =
                from p in parcels
                let ap = p as AirPackage
                         where (ap != null) &&
                         ap.IsHeavy()
                         orderby ap.Weight descending
                         select ap;


            // foreach loop outputs each parcel selected by query
            foreach (Parcel p in sortByWeight)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }



            Pause();
        }
Esempio n. 16
0
    // Precondition:  None
    // Postcondition: Small list of Parcels is created and displayed
    static void Main(string[] args)
    {
        Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                 "  Louisville   ", "  KY   ", 40202); // Test Address 1
        Address a2 = new Address("Jane Doe", "987 Main St.",
                                 "Beverly Hills", "CA", 90210);        // Test Address 2
        Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                 "El Paso", "TX", 79901);              // Test Address 3
        Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                 "Portland", "ME", 04101);             // Test Address 4



        GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);
        GroundPackage gp2 = new GroundPackage(a1, a3, 10, 12, 2, 50);
        GroundPackage gp3 = new GroundPackage(a2, a1, 100, 15, 7, 20);
        GroundPackage gp4 = new GroundPackage(a4, a2, 5, 2, 11, 2);

        NextDayAirPackage na1 = new NextDayAirPackage(a1, a3, 25, 15, 15, 85, 7.5m);
        NextDayAirPackage na2 = new NextDayAirPackage(a2, a1, 10, 10, 10, 10, 10m);
        NextDayAirPackage na3 = new NextDayAirPackage(a3, a4, 45, 125, 15, 85, 0m);
        NextDayAirPackage na4 = new NextDayAirPackage(a4, a2, 25, 5, 5, 15, 50m);


        TwoDayAirPackage ta1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28, 80.5, TwoDayAirPackage.Delivery.Saver);
        TwoDayAirPackage ta2 = new TwoDayAirPackage(a1, a3, 10, 10, 10, 10, TwoDayAirPackage.Delivery.Early);
        TwoDayAirPackage ta3 = new TwoDayAirPackage(a2, a4, 5, 5, 5, 50, TwoDayAirPackage.Delivery.Saver);
        TwoDayAirPackage ta4 = new TwoDayAirPackage(a3, a2, 30, 40, 28, 20, TwoDayAirPackage.Delivery.Early);

        List <GroundPackage>     groundPackages     = new List <GroundPackage>();     // Test list of parcels
        List <NextDayAirPackage> nextDayAirPackages = new List <NextDayAirPackage>(); // Test list of parcels
        List <TwoDayAirPackage>  twoDayAirPackages  = new List <TwoDayAirPackage>();  // Test list of parcels


        groundPackages.Add(gp1);
        groundPackages.Add(gp2);
        groundPackages.Add(gp3);
        groundPackages.Add(gp4);

        nextDayAirPackages.Add(na1);
        nextDayAirPackages.Add(na2);
        nextDayAirPackages.Add(na3);
        nextDayAirPackages.Add(na4);

        twoDayAirPackages.Add(ta1);
        twoDayAirPackages.Add(ta2);
        twoDayAirPackages.Add(ta3);
        twoDayAirPackages.Add(ta4);

        foreach (GroundPackage p in groundPackages)
        {
            WriteLine(p);
            WriteLine("--------------------");
        }
        WriteLine("//////////////////////////////////////////////////////////////////////////");
        foreach (NextDayAirPackage p in nextDayAirPackages)
        {
            WriteLine(p);
            WriteLine("--------------------");
        }
        WriteLine("//////////////////////////////////////////////////////////////////////////");
        foreach (TwoDayAirPackage p in twoDayAirPackages)
        {
            WriteLine(p);
            WriteLine("--------------------");
        }
    }
Esempio n. 17
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);    // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);      // Test Address 4

            //Addresses 5-8 updated by Megan Balcom
            Address a5 = new Address("Erik Davis", "2700 Potomac Mills Circle",
                                     "", "Woodbridge", "VA", 22192);             //Test Address 5
            Address a6 = new Address("Luke Skywalker", "100 Death Star Rd",
                                     "Apt 2", "Galaxy", "CA", 90001);            //Test Address 6
            Address a7 = new Address("Sarah Balcom", "6610 Shelburn Dr",
                                     "", "Crestwood", "KY", 40014);              //Test Address 7
            Address a8 = new Address("Katherine Freid", "956 Treasure Ct",
                                     "", "Fort Mill", "SC", 29708);              //Test Address 8

            Letter letter1 = new Letter(a1, a2, 3.95M);                          // Letter test object
            Letter letter2 = new Letter(a5, a8, 2.45M);                          // added by Megan
            Letter letter3 = new Letter(a6, a7, 6.5M);                           // added by Megan

            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);      // Ground test object
            GroundPackage gp2 = new GroundPackage(a6, a5, 16, 5, 12, 4.7);       // added by Megan
            GroundPackage gp3 = new GroundPackage(a8, a7, 4, 6, 8, 10);          // added by Megan

            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,  // Next Day test object
                                                            85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a5, a7, 10, 3.2, 14, // added by Megan
                                                            6, 6.75M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a3, a8, 2, 2.5, 5,   // added by Megan
                                                            6, 3.5M);

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a7, a8, 5, 10, 15,        // added by Megan
                                                          20, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a5, a6, 8, 5, 9,          // added by Megan
                                                          4.5, TwoDayAirPackage.Delivery.Saver);


            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);

            // LINQ query that selects parcels by their zip code
            var sortDestZip = // Holds the results of this query
                              from p in parcels
                              orderby p.DestinationAddress.Zip descending
                              select p;

            // Outputs the query result to the console
            Console.WriteLine("Sort parcels by Destination Zip:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // LINQ query that sorts parcels by their cost
            var sortByCost = // Holds the results of this query
                             from p in parcels
                             orderby p.CalcCost()
                             select p;

            // Outputs the query result to the console
            Console.WriteLine("Sort parcels by Cost:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // LINQ query that that selects parcels by their type
            // and  then orders them by descending cost
            var sortParcelType = //Holds the results of this query
                                 from p in parcels
                                 orderby p.GetType().ToString(), p.CalcCost() descending
            select p;

            // Outputs the query result to the console
            Console.WriteLine("Sort parcels by Parcel Type and Descending Cost:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // LINQ query that selects Air Packages and
            // orders they by descending weight
            var apHeavyByWeight = // Holds the results of this query
                                  from p in parcels
                                  let ap = p as AirPackage
                                           where ap != null && ap.IsHeavy()
                                           orderby ap.Weight descending
                                           select ap;

            // Outputs the query result to the console
            Console.WriteLine("Sort Air Packages by Descending Weight:");
            Console.WriteLine("====================");
            foreach (var ap in parcels)
            {
                Console.WriteLine(ap);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 18
0
        // Precondition:  None
        // Postcondition: Parcels have been created and reports generated using LINQ
        static void Main(string[] args)
        {
            // Verbose Setting - true means complete output of parcel data
            //                   false means only relevant data output
            bool VERBOSE = false;

            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                "Louisville", "KY", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                "El Paso", "TX", 79901); // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                "Portland", "ME", 04101); // Test Address 4
            Address a5 = new Address("John Doe", "111 Market St.", "",
                "Jeffersonville", "IN", 47130); // Test Address 5
            Address a6 = new Address("Jane Smith", "55 Hollywood Blvd.", "Apt. 9",
                "Los Angeles", "CA", 90212); // Test Address 6
            Address a7 = new Address("Captain Robert Crunch", "21 Cereal Rd.", "Room 987",
                "Bethesda", "MD", 20810); // Test Address 7
            Address a8 = new Address("Vlad Dracula", "6543 Vampire Way", "Apt. 1",
                "Bloodsucker City", "TN", 37210); // Test Address 8

            Letter letter1 = new Letter(a1, a2, 3.95M);                            // Letter test object
            Letter letter2 = new Letter(a3, a4, 4.25M);                            // Letter test object
            GroundPackage gp1 = new GroundPackage(a5, a6, 14, 10, 5, 12.5);        // Ground test object
            GroundPackage gp2 = new GroundPackage(a7, a8, 8.5, 9.5, 6.5, 2.5);     // Ground test object
            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,    // Next Day test object
                85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a5, 9.5, 6.0, 5.5, // Next Day test object
                5.25, 5.25M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a2, a7, 10.5, 6.5, 9.5, // Next Day test object
                15.5, 5.00M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a5, a7, 46.5, 39.5, 28.0, // Two Day test object
                80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a8, a1, 15.0, 9.5, 6.5,   // Two Day test object
                75.5, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a6, a4, 12.0, 12.0, 6.0,  // Two Day test object
                5.5, TwoDayAirPackage.Delivery.Saver);

            List<Parcel> parcels;      // List of test parcels

            parcels = new List<Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);

            Console.WriteLine("Original List Cost:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine("{0,-17} {1,8:C}", p.GetType().ToString(),
                    p.CalcCost());
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort();// Sort - uses natural order
            Console.WriteLine("Parcels by cost (ascending) (default):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine("{0,-17} {1,8:C}", p.GetType().ToString(),
                        p.CalcCost());
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine("Original List Zip:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine("{0,-17} {1,8}", p.GetType().ToString(),
                    p.DestinationAddress.Zip);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new OrderByDesZip());// Sort - uses specified Comparer class
            Console.WriteLine("Parcels by destination Zip (descending):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine("{0,-17} {1,8}", p.GetType().ToString(),
                        p.DestinationAddress.Zip);
                Console.WriteLine("====================");
            }
            Pause();

            Console.WriteLine("Original List Type and Cost:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine("{0,-17} {1,8:c}", p.GetType().ToString(),
                        p.CalcCost());
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new SortByTypeThenCost());// Sort - uses specified Comparer class
            Console.WriteLine("Parcels by Type (ascending) then cost (descending):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine("{0,-17} {1,8:c}", p.GetType().ToString(),
                        p.CalcCost());
                Console.WriteLine("====================");
            }
            Pause();
        }
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                "Louisville", "KY", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                "El Paso", "TX", 79901); // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                "Portland", "ME", 04101); // Test Address 4

            Letter letter1 = new Letter(a1, a2, 3.95M);                            // Letter test object
            Letter letter2 = new Letter(a2, a3, 4.4M);                             // Letter test object
            Letter letter3 = new Letter(a3, a4, 5.5M);                             // Letter test object
            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);        // Ground test object
            GroundPackage gp2 = new GroundPackage(a1, a2, 15, 11, 6, 13.5);        // Groud test object
            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,    // Next Day test object
                85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a2, a4, 35, 25, 25,    // Next Day test object
                95, 8.5M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a3, a2, 47.5, 40.5, 29,   // Two Day test object
                81.5, TwoDayAirPackage.Delivery.Early);

            List<Parcel> parcels;      // List of test parcels

            parcels = new List<Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort();

            Console.WriteLine("Items sorted in natural order (asc by Cost):\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new DescByDestZip());

            Console.WriteLine("Parcels sorted descending by destination zip:\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new AscsTypeDescCost());

            Console.WriteLine("Parcels sorted ascending by type then sorted descending by cost:\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                "Louisville", "KY", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                "El Paso", "TX", 79901); // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                "Portland", "ME", 04101); // Test Address 4
            Address a5 = new Address("Luke Skywalker", "101 dessert way", "Hut 1",
                "Mos Eisley", "TA", 12345); // Test Address 5
            Address a6 = new Address("Bilbo Baggins", "202 Bagshot Row", "Bag End",
                "Hobbiton", "TS", 12346);   // Test Address 6
            Address a7 = new Address("Jon Snow", "303 Kings Rd", "",
                "Winterfell", "TN", 12347); // Test Address 7
            Address a8 = new Address("Sherlock Holmes", "221B Baker St", "",
                "London", "GL", 12348);     // Test Address 8

            Letter letter1 = new Letter(a1, a2, 3.95M);                            // Letter test object
            Letter letter2 = new Letter(a8, a7, 4.1M);                             // Letter test object
            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);        // Ground test object
            GroundPackage gp2 = new GroundPackage(a7, a6, 10, 12, 4, 20.5);        // Ground test object
            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,    // Next Day test object
                85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a6, a5, 26, 16, 16,    // Next Day test object
                86, 8.5M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a5, a4, 47.7, 40.5, 29.0, // Two Day test object
                81.5, TwoDayAirPackage.Delivery.Early);

            List<Parcel> parcels;      // List of test parcels

            parcels = new List<Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            var parcelsByZip =      // Parcels sorted by zip code
              from p in parcels
              orderby p.DestinationAddress.Zip descending
              select p;

            Console.WriteLine("Parcels sorted by zip code");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsByZip)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            var parcelsByCost =     // Parcels sorted by cost
               from p in parcels
               orderby p.CalcCost() ascending
               select p;

            Console.WriteLine("Parcels sorted by cost");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsByCost)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            var parcelsByType =     // Parcels sorted by type
             from p in parcels
             orderby p.GetType().ToString() ascending
             select p;

            var parcelsByCost2 =    // Sorted by type parcels sorted by cost
                from p in parcelsByType
                orderby p.CalcCost() descending
                select p;

            Console.WriteLine("Parcels sorted by type then cost");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsByCost2)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            var airPackages =       // Parcels that are air packages and heavy
                from p in parcels
                where p is AirPackage && ((AirPackage)p).IsHeavy()
                orderby ((AirPackage)p).Weight
                select p;

            Console.WriteLine("Heavy air packages sorted by weight");
            Console.WriteLine("====================");
            foreach (Parcel p in airPackages)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 21
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);                    // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                      // Test Address 4
            Address a5 = new Address("Ryan Leezer", "666 Spring St", "",
                                     "New York CIty", "NY", 37219);                 //Test Address 5
            Address a6 = new Address("Jessica Lewis", "100 7th St", "",
                                     "Tampa", "FL", 57611);                         //Test Address 6
            Address a7 = new Address("Mark Hunt", "123 11th St", "Apt. 2",
                                     "Phoenix", "AZ", 21399);                       //Test Address 7
            Address a8 = new Address("Mary Gates", "2838 W Jefferson St", "",
                                     "Atlanta", "GA", 18042);                       //Test Address 8

            Letter            letter1 = new Letter(a1, a2, 3.95M);                  // Letter test object 1
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object 1
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object 1
                                                              85, 7.50M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object 1
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            Letter            letter2 = new Letter(a6, a8, 2.50M);                  //Letter test object 2
            GroundPackage     gp2     = new GroundPackage(a1, a6, 7, 5, 5, 10);     //Ground test object 2
            NextDayAirPackage ndap2   = new NextDayAirPackage(a3, a8, 20, 18, 15,   //Next Day test object 2
                                                              40, 5.5M);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a2, a7, 40, 30, 30,       //Two Day test object 2
                                                          61, TwoDayAirPackage.Delivery.Saver);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(gp1);
            parcels.Add(ndap1);
            parcels.Add(tdap1);
            parcels.Add(letter2);
            parcels.Add(gp2);
            parcels.Add(ndap2);
            parcels.Add(tdap2);

            //LINQ query sorted by destination address zip
            var sortDestZip =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            // Display the query thorugh a foreach loop.
            Console.WriteLine("Parcels sorted by dest zip:");
            Console.WriteLine("=============================");
            foreach (var P in sortDestZip)
            {
                Console.WriteLine(P.DestinationAddress.Zip);
            }
            Console.WriteLine();

            //LINQ query sorted by cost
            var sortByCost =
                from p in parcels
                orderby p.CalcCost()
                select p;

            // Display the query thorugh a foreach loop.
            Console.WriteLine("Parcels sorted by cost:");
            Console.WriteLine("=============================");
            foreach (var P in sortByCost)
            {
                Console.WriteLine(P.CalcCost());
            }
            Console.WriteLine();

            //LINQ query sorted by type, then cost
            var sortByTypeCost =
                from p in parcels
                orderby p.GetType().ToString(), p.CalcCost() descending
            select p;

            // Display the query thorugh a foreach loop.
            Console.WriteLine("Parcels sorted by type, then cost:");
            Console.WriteLine("====================================");
            foreach (var P in sortByTypeCost)
            {
                Console.WriteLine(P.GetType() + ": " + P.CalcCost());
            }
            Console.WriteLine();

            //LINQ query sorted by the weight of heavy Air Packages
            var sortByAirPackageWeight =
                from p in parcels
                where p is AirPackage
                let P = (AirPackage)p
                        where P.IsHeavy() == true
                        orderby P.Weight descending
                        select P;

            // Display the query thorugh a foreach loop.
            Console.WriteLine("Heavy Air Packages sorted by weight:");
            Console.WriteLine("====================================");
            foreach (var P in sortByAirPackageWeight)
            {
                Console.WriteLine(P.Weight);
            }
            Pause();
        }
Esempio n. 22
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);          // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                      // Test Address 4

            Letter            letter1 = new Letter(a1, a2, 3.95M);                  // Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a3, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            Letter            letter2 = new Letter(a4, a3, 3.22M);                  // Letter test object
            GroundPackage     gp2     = new GroundPackage(a3, a2, 10, 12, 4, 22.5); // Ground test object
            NextDayAirPackage ndap2   = new NextDayAirPackage(a1, a4, 15, 5, 5,     // Next Day test object
                                                              85, 7.90M);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a2, a4, 50.5, 42.5, 22.0, // Two Day test object
                                                          90.5, TwoDayAirPackage.Delivery.Saver);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a1, a3
                                                            , 15, 5, 5,             // Next Day test object
                                                            85, 7.90M);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a2, a3, 50.5, 42.5, 22.0, // Two Day test object
                                                          90.5, TwoDayAirPackage.Delivery.Saver);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(gp1);
            parcels.Add(ndap1);
            parcels.Add(tdap1);
            parcels.Add(letter2);
            parcels.Add(gp2);
            parcels.Add(ndap2);
            parcels.Add(tdap2);
            parcels.Add(ndap3);
            parcels.Add(tdap3);

            //displays list
            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            //displays list in the general sort that is of the calcCost method
            parcels.Sort();
            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            //displays list in the comparerclasses override of the zipcode method and bases it upon zip code in descending order
            parcels.Sort(new ComparerClass());
            Console.WriteLine("Sorted List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 23
0
        // Precondition:  None
        // Postcondition: Parcels have been created and reports generated using LINQ
        static void Main(string[] args)
        {
            // Verbose Setting - true means complete output of parcel data
            //                   false means only relevant data output
            bool VERBOSE = false;

            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);                       // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210);                    // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                          // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                         // Test Address 4
            Address a5 = new Address("John Doe", "111 Market St.", "",
                                     "Jeffersonville", "IN", 47130);                   // Test Address 5
            Address a6 = new Address("Jane Smith", "55 Hollywood Blvd.", "Apt. 9",
                                     "Los Angeles", "CA", 90212);                      // Test Address 6
            Address a7 = new Address("Captain Robert Crunch", "21 Cereal Rd.", "Room 987",
                                     "Bethesda", "MD", 20810);                         // Test Address 7
            Address a8 = new Address("Vlad Dracula", "6543 Vampire Way", "Apt. 1",
                                     "Bloodsucker City", "TN", 37210);                 // Test Address 8

            Letter            letter1 = new Letter(a1, a2, 3.95M);                     // Letter test object
            Letter            letter2 = new Letter(a3, a4, 4.25M);                     // Letter test object
            GroundPackage     gp1     = new GroundPackage(a5, a6, 14, 10, 5, 12.5);    // Ground test object
            GroundPackage     gp2     = new GroundPackage(a7, a8, 8.5, 9.5, 6.5, 2.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,      // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a5, 9.5, 6.0, 5.5,     // Next Day test object
                                                            5.25, 5.25M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a2, a7, 10.5, 6.5, 9.5,    // Next Day test object
                                                            15.5, 5.00M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a5, a7, 46.5, 39.5, 28.0,    // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a8, a1, 15.0, 9.5, 6.5,      // Two Day test object
                                                          75.5, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a6, a4, 12.0, 12.0, 6.0,     // Two Day test object
                                                          5.5, TwoDayAirPackage.Delivery.Saver);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // Parcels by Destination Zip (desc)
            var parcelsByDestZip =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            Console.WriteLine("Parcels by Destination Zip (desc):");
            Console.WriteLine("====================");

            foreach (Parcel p in parcelsByDestZip)
            {
                if (VERBOSE)
                {
                    Console.WriteLine(p);
                }
                else
                {
                    Console.WriteLine("{0:D5}", p.DestinationAddress.Zip);
                }

                Console.WriteLine("====================");
            }
            Pause();

            // Parcels by cost
            var parcelsByCost =
                from p in parcels
                orderby p.CalcCost()
                select p;

            Console.WriteLine("Parcels by Cost:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsByCost)
            {
                if (VERBOSE)
                {
                    Console.WriteLine(p);
                }
                else
                {
                    Console.WriteLine("{0,8:C}", p.CalcCost());
                }

                Console.WriteLine("====================");
            }
            Pause();

            // Parcels by type and cost (desc)
            var parcelsByTypeCost =
                from p in parcels
                orderby p.GetType().ToString(), p.CalcCost() descending
            select p;

            Console.WriteLine("Parcels by Type and Cost (desc):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsByTypeCost)
            {
                if (VERBOSE)
                {
                    Console.WriteLine(p);
                }
                else
                {
                    Console.WriteLine("{0,-17} {1,8:C}", p.GetType().ToString(),
                                      p.CalcCost());
                }

                Console.WriteLine("====================");
            }
            Pause();

            // Heavy AirPackages by Weight (desc)
            var heavyAirPackagesByWeight =
                from p in parcels
                let ap = p as AirPackage                    // Downcast if AirPackage, null otherwise
                         where (ap != null) && ap.IsHeavy() // Safe because of short-circuit
                         orderby ap.Weight descending
                         select p;

            // Alternate Solutions

            //var heavyAirPackagesByWeight =
            //    from p in parcels
            //    where (p is AirPackage) && ((AirPackage)p).IsHeavy() // Safe downcast
            //    orderby ((AirPackage)p).Weight descending            // Safe downcast
            //    select p;

            // AirPackages first
            //var airPackages =
            //    from p in parcels
            //    where p is AirPackage
            //    select (AirPackage) p;

            // Filter from AirPackages
            //var heavyAirPackagesByWeight =
            //    from ap in airPackages
            //    where ap.IsHeavy()
            //    orderby ap.Weight descending
            //    select ap;

            Console.WriteLine("Heavy AirPackages by Weight (desc):");
            Console.WriteLine("====================");
            foreach (AirPackage ap in heavyAirPackagesByWeight)
            {
                if (VERBOSE)
                {
                    Console.WriteLine(ap);
                }
                else
                {
                    Console.WriteLine("{0,-17} {1,4:F1}", ap.GetType().ToString(),
                                      ap.Weight);
                }

                Console.WriteLine("====================");
            }
        }
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);        // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);              // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);             // Test Address 4
            Address a5 = new Address("Lester Joy", "156 Hunters Place",
                                     "Benton", "KY", 40114);               // Test Address 5
            Address a6 = new Address("Ben Polly", "67 Young Street",
                                     "Danville", "CA", 92108);             // Test Address 6
            Address a7 = new Address("Hillary Mont", "791 Prog Ave",
                                     "Polar", "AL", 56123);                // Test Address 7
            Address a8 = new Address("Monica Key", "091 Mice Ave",
                                     "Welro", "MI", 40981);                // Test Address 8


            Letter letter1 = new Letter(a1, a2, 3.95M);                            // Letter test object
            Letter letter2 = new Letter(a8, a6, 8.67M);

            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);        // Ground test object
            GroundPackage gp2 = new GroundPackage(a5, a7, 65, 43, 87, 115);

            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,    // Next Day test object
                                                            85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a2, a3, 34, 23, 56,
                                                            180, 9.80M);

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          300, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a5, a8, 40.5, 45.3, 82.5,
                                                          400, TwoDayAirPackage.Delivery.Early);


            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            //Query that sorts destination zips in descending order
            var sortZip =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            Console.WriteLine("Parcels by descending Destination Address");
            Console.WriteLine("====================");

            //displays the results of all parcels but zips are
            //in descending order
            foreach (Parcel p in sortZip)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            //Query sorts cost of packages in ascending order
            var costAsc =
                from p in parcels
                orderby p.CalcCost() ascending
                select p;

            Console.WriteLine("Parcels by ascending Cost");
            Console.WriteLine("====================");

            //displays cost of packages in ascending order
            foreach (Parcel p in costAsc)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            //Query orders by Parcel type (ascending) and then cost (descending)
            var parcelType =
                from p in parcels
                orderby p.GetType().ToString() ascending, p.CalcCost() descending
            select p;

            Console.WriteLine("Parcels by ascending Parcel Type and " +
                              "descending Cost");
            Console.WriteLine("====================");

            //displays Parcel Type (ascending and Cost (descending)
            foreach (Parcel p in parcelType)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            var isHeavy =
                from AirPackage in parcels
                orderby AirPackage
        }
Esempio n. 25
0
        // Precondition:  None
        // Postcondition: Parcels have been created and reports generated using LINQ
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);                       // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210);                    // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                          // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                         // Test Address 4
            Address a5 = new Address("John Doe", "111 Market St.", "",
                                     "Jeffersonville", "IN", 47130);                   // Test Address 5
            Address a6 = new Address("Jane Smith", "55 Hollywood Blvd.", "Apt. 9",
                                     "Los Angeles", "CA", 90212);                      // Test Address 6
            Address a7 = new Address("Captain Robert Crunch", "21 Cereal Rd.", "Room 987",
                                     "Bethesda", "MD", 20810);                         // Test Address 7
            Address a8 = new Address("Vlad Dracula", "6543 Vampire Way", "Apt. 1",
                                     "Bloodsucker City", "TN", 37210);                 // Test Address 8

            Letter            letter1 = new Letter(a1, a2, 3.95M);                     // Letter test object
            Letter            letter2 = new Letter(a3, a4, 4.25M);                     // Letter test object
            GroundPackage     gp1     = new GroundPackage(a5, a6, 14, 10, 5, 12.5);    // Ground test object
            GroundPackage     gp2     = new GroundPackage(a7, a8, 8.5, 9.5, 6.5, 2.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,      // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a5, 9.5, 6.0, 5.5,     // Next Day test object
                                                            5.25, 5.25M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a2, a7, 10.5, 6.5, 9.5,    // Next Day test object
                                                            15.5, 5.00M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a5, a7, 46.5, 39.5, 28.0,    // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a8, a1, 15.0, 9.5, 6.5,      // Two Day test object
                                                          75.5, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a6, a4, 12.0, 12.0, 6.0,     // Two Day test object
                                                          5.5, TwoDayAirPackage.Delivery.Saver);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)//displays the original original list
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort();//calls the parcel class, compareto method
            Console.WriteLine("Sorted List (by CalcCost in Ascending Order)");
            Console.WriteLine("===============================================");
            foreach (Parcel p in parcels)//displays the sorted data
            {
                Console.WriteLine(p);
                Console.WriteLine("=======================");
            }
            Pause();

            parcels.Sort(new ReverseZipOrder());//sorts the data according to the reverse zip order class, compare method
            Console.WriteLine("Sorted in Reverse Order");
            Console.WriteLine("========================");
            foreach (Parcel p in parcels)//displays the sorted data
            {
                Console.WriteLine(p);
                Console.WriteLine("==================");
            }
            Pause();

            parcels.Sort(new MultiLevelSort());//sorts the data according to the multilevel sort class, compare method
            Console.WriteLine("Multilevel Sort");
            Console.WriteLine("================");
            foreach (Parcel p in parcels)//displays the sorted data
            {
                Console.WriteLine(p);
                Console.WriteLine("===================");
            }
            Pause();
        }
Esempio n. 26
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);          // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                      // Test Address 4
            Address a5 = new Address("John Stamos", "3483 Golden Gate Way", "Apt. 1",
                                     "San Francisco", "CA", 94016);                 // Test Address 5

            Letter            letter1 = new Letter(a1, a2, 3.95M);                  // Letter test object
            Letter            letter2 = new Letter(a3, a5, 5.25M);                  // Letter test object
            Letter            letter3 = new Letter(a2, a5, 4.24M);                  // Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object
            GroundPackage     gp2     = new GroundPackage(a2, a5, 13, 8, 4, 12.3);  // Ground test object
            GroundPackage     gp3     = new GroundPackage(a1, a5, 12, 5, 3, 11.25); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a2, a5, 24, 18, 6,      // Next Day test object
                                                            57, 7.62M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a2, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a5, a1, 40, 45, 29.3,     // Two Day test object
                                                          74.2, TwoDayAirPackage.Delivery.Early);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>
            {
                letter1, // Populate list
                letter2,
                letter3,
                gp1,
                gp2,
                gp3,
                ndap1,
                ndap2,
                tdap1,
                tdap2
            };

            Console.WriteLine("Original List:"); // Shows original list of Parcels for each object in the list
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(); // Sorts the list of parcels in its natural order, which is ascending order by cost, stated in the Parcel class
            Console.WriteLine("Sorted list of parcels in natural order (ascending by cost):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new DescendByDestZip()); // Sort the list of Parcels in descending order by destination zip code using the DescendByDestZip comparer
            Console.WriteLine("Parcels sorted by destination zip code in descending order:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 27
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);          // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                      // Test Address 4
            Address a5 = new Address("John Doe", "111 Market St.", "",
                                     "Jeffersonville", "IN", 47130);                // Test Address 5
            Address a6 = new Address("Jane Smith", "55 Hollywood Blvd.", "Apt. 9",
                                     "Los Angeles", "CA", 90212);                   // Test Address 6
            Address a7 = new Address("Captain Robert Crunch", "21 Cereal Rd.", "Room 987",
                                     "Bethesda", "MD", 20810);                      // Test Address 7
            Address a8 = new Address("Vlad Dracula", "6543 Vampire Way", "Apt. 1",
                                     "Bloodsucker City", "TN", 37210);              // Test Address 8

            Letter            letter1 = new Letter(a1, a2, 3.95M);                  // Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            Letter            letter2 = new Letter(a5, a6, 2.99m);
            GroundPackage     gp2     = new GroundPackage(a7, a8, 9, 11, 7, 10.99);
            NextDayAirPackage ndap2   = new NextDayAirPackage(a3, a7, 39, 13, 9, 92, 4.85M);
            TwoDayAirPackage  tdap2   = new TwoDayAirPackage(a8, a1, 56.2, 28.7, 30, 79.4, TwoDayAirPackage.Delivery.Early);
            Letter            letter3 = new Letter(a4, a6, 5.67m);
            Letter            letter4 = new Letter(a2, a7, 4.99m);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(gp1);
            parcels.Add(ndap1);
            parcels.Add(tdap1);
            parcels.Add(letter2);
            parcels.Add(gp2);
            parcels.Add(ndap2);
            parcels.Add(tdap2);
            parcels.Add(letter3);
            parcels.Add(letter4);

            parcels.Sort();

            Console.WriteLine("Natural Order:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new DescendingParcelZip());

            Console.WriteLine("Sorted list (descending by destination zip) using Comparer:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);        // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);              // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);             // Test Address 4

            Letter            letter1 = new Letter(a1, a2, 3.95M);
            Letter            letter2 = new Letter(a4, a3, 4.24M);
            Letter            letter3 = new Letter(a2, a4, 6.28M);// Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5);
            GroundPackage     gp2     = new GroundPackage(a1, a3, 10, 24, 8, 18.6);
            GroundPackage     gp3     = new GroundPackage(a3, a2, 12, 18, 7, 20.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a4, a1, 23, 24, 25, 50, 2.89M);
            TwoDayAirPackage  tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                           80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a1, a2, 43, 44, 68, 70, TwoDayAirPackage.Delivery.Early);
            List <Parcel>    parcels;  // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1);
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(); // Sort - cost ascending
            Console.WriteLine("Cost ascending: ");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();


            parcels.Sort(new ZipCode()); // Sort - zip descending (something went wrong here)
            Console.WriteLine("Zip descending: ");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 29
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);        // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);              // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);             // Test Address 4

            Letter letter1 = new Letter(a1, a2, 3.95M);                    // Letter test objects
            Letter letter2 = new Letter(a2, a3, 7.00M);
            Letter letter3 = new Letter(a3, a4, 10.00M);

            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);        // Ground test objects
            GroundPackage gp2 = new GroundPackage(a1, a2, 20, 15, 30, 70);

            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,    // Next Day test objects
                                                            85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a2, a4, 30, 30, 30, 30, 8.00M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a1, a2, 2, 2, 2, 2, 1.00M);

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test objects
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a3, a2, 6, 6, 6, 6, TwoDayAirPackage.Delivery.Early);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(tdap1);
            parcels.Add(tdap2);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort();

            Console.WriteLine("Items sorted in natural order (asc by Cost):\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new DescByDestZip());

            Console.WriteLine("Parcels sorted descending by destination zip:\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            parcels.Sort(new AscsTypeDescCost());

            Console.WriteLine("Parcels sorted ascending by type then sorted descending by cost:\n");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();
        }
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);          // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                      // Test Address 4

            Letter            letter1 = new Letter(a1, a2, 3.95M);                  // Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15,   // Next Day test object
                                                              85, 7.50M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);

            Letter letter2 = new Letter(a3, a2, 4.00M);
            Letter letter3 = new Letter(a3, a4, 5.00M);
            Letter letter4 = new Letter(a4, a1, 6.00M);

            TwoDayAirPackage days = new TwoDayAirPackage(a1, a2, 50, 66, 75, 80, TwoDayAirPackage.Delivery.Saver);

            NextDayAirPackage next = new NextDayAirPackage(a4, a3, 100, 45, 20, 55, 45);

            GroundPackage hola = new GroundPackage(a2, a1, 100, 100, 20, 345);


            List <Parcel> parcels;         // List of test parcels

            parcels = new List <Parcel>(); // List of Parcel objects for sorting
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(letter4);
            parcels.Add(letter1);
            parcels.Add(gp1);
            parcels.Add(ndap1);
            parcels.Add(tdap1);
            parcels.Add(days);
            parcels.Add(next);
            parcels.Add(hola);

            WriteLine("Original List:"); // Outputing
            WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                WriteLine(p);
                WriteLine("====================");
            }

            Console.ReadLine();                   // After  pressing enter button, the data will be sorted by cost in ascending order
            Pause();                              // After ENTER List of Parcels will be shown before sort and in Ascending Order

            Console.WriteLine("Before Sorting:"); // Outputing costs without sorting
            Console.WriteLine("===============");
            foreach (Parcel g in parcels)
            {
                Console.WriteLine(g.CalcCost());
            }

            Console.WriteLine();

            parcels.Sort(); // Ascending Sort order
            Console.WriteLine("Ascending List By Cost:");
            Console.WriteLine("=======================");
            foreach (Parcel z in parcels)
            {
                Console.WriteLine(z.CalcCost());
            }

            Console.ReadLine(); // Press Enter to proceed to the next sorting
            Pause();

            Console.WriteLine("Before Sorting"); // Destination Zip before sorting
            Console.WriteLine("==============");
            foreach (Parcel g in parcels)
            {
                Console.WriteLine(g.DestinationAddress.Zip);
            }

            Console.WriteLine();

            parcels.Sort(new Descending_Order()); // Descending order by destination zip
            Console.WriteLine("Descending Order By Destination Zip:");
            Console.WriteLine("====================================");
            foreach (Parcel z in parcels)
            {
                Console.WriteLine(z.DestinationAddress.Zip);
            }

            Console.ReadLine(); // Press Enter to proceed to the next sorting
            Pause();

            Console.WriteLine("Before Sorting");
            Console.WriteLine("==============");
            foreach (Parcel g in parcels)
            {
                Console.WriteLine(g);
                Console.WriteLine("====================");
            }

            Console.WriteLine();              // Space between sorts

            parcels.Sort(new Extra_Credit()); // Extra Credit Sort
            Console.WriteLine("Extra Credit Sorting");
            Console.WriteLine("====================");
            foreach (Parcel z in parcels)
            {
                Console.WriteLine(z);
            }
        }
Esempio n. 31
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ", "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "Beverly Hills", "CA", 90210);                                 // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321", "El Paso", "TX", 79901);                 // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7", "Portland", "ME", 04101);                      // Test Address 4
            Address a5 = new Address("[Redacted]", "000 X Street", "Layer 10", "Duckwater", "NV", 00001);                       // Test Address 5
            Address a6 = new Address("Mike", "1 Mike Street", "The Mike Zone", "Mike Peak", "MN", 75892);                       // Test Address 6

            Letter            letter1 = new Letter(a1, a2, 3.95M);                                                              // Letter test object
            GroundPackage     gp1     = new GroundPackage(a3, a4, 14, 10, 5, 12.5);                                             // Ground test object
            NextDayAirPackage ndap1   = new NextDayAirPackage(a1, a3, 25, 15, 15, 85, 7.50M);                                   // Next Day test object
            TwoDayAirPackage  tdap1   = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, 80.5, TwoDayAirPackage.Delivery.Saver);  // Two Day test object
            Letter            letter2 = new Letter(a3, a5, 0.00M);                                                              // Letter test object
            TwoDayAirPackage  tdap2   = new TwoDayAirPackage(a3, a2, 5, 4, 2, 8, TwoDayAirPackage.Delivery.Saver);              // Two Day test object
            TwoDayAirPackage  tdap3   = new TwoDayAirPackage(a4, a6, 50, 40, 20, 80, TwoDayAirPackage.Delivery.Early);          // Two Day test object
            Letter            letter3 = new Letter(a1, a2, 0.58M);                                                              // Letter test object
            Letter            letter4 = new Letter(a3, a4, 9.00M);                                                              // Letter test object
            Letter            letter5 = new Letter(a5, a6, 1.25M);                                                              // Letter test object
            Letter            letter6 = new Letter(a6, a5, 125.125M);                                                           // Letter test object

            List <Parcel> parcels = new List <Parcel>();                                                                        // List of test parcels

            // Populate list
            parcels.Add(letter1);   // 1
            parcels.Add(gp1);       // 2
            parcels.Add(ndap1);     // 3
            parcels.Add(tdap1);     // 4
            parcels.Add(letter2);   // 5
            parcels.Add(tdap2);     // 6
            parcels.Add(tdap3);     // 7
            parcels.Add(letter3);   // 8
            parcels.Add(letter4);   // 9
            parcels.Add(letter5);   // 10
            parcels.Add(letter6);   // 11


            // ------------------------------------------------------------- Original List

            // no sorting
            WriteLine("Original List:");
            WriteLine("====================");
            sortedList(parcels); // lists parcels

            // ------------------------------------------------------------- Default Sort: ascending cost

            parcels.Sort(); // default sort
            WriteLine("Cost Ascending (Default Sort):");
            WriteLine("====================");
            sortedList(parcels); // lists parcels based on default sort

            // ------------------------------------------------------------- Descending ZIP

            parcels.Sort(new Parcel_DescZipSort()); // sorts based on the specified class (descending destination zip)
            WriteLine("Destination Zip Descending:");
            WriteLine("====================");
            sortedList(parcels); // lists parcels based on specified sort above

            // ------------------------------------------------------------- Extra Credit

            parcels.Sort(new Parcel_TypeCostSort()); // sorts based on the specified class (asc. type, desc. cost)
            WriteLine("Type Ascending, Cost Descending:");
            WriteLine("====================");
            sortedList(parcels); // lists parcels based on specified sort above
        }
Esempio n. 32
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);    // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);      // Test Address 4

            //extra Address objects added
            Address a5 = new Address("Todd Lasley", "550 Ruggles Place", "Apt. 6",
                                     "Louisville", "KY", 40208);    // Test Address 5
            Address a6 = new Address("Michael Myers", "42 Elm Ave.", "",
                                     "San Francisco", "CA", 85742); // Test Address 6
            Address a7 = new Address("Jared Taylor", "127 St. Route 271", "",
                                     "Hawesville", "KY", 42348);    // Test Address 7
            Address a8 = new Address("Smitty Werbenjagermanjensen", "401 That St.", "Apt. 5",
                                     "Cincinatti", "OH", 12354);    // Test Address 8

            // Letter test objects
            Letter letter1 = new Letter(a1, a2, 3.95M); //letter1
            Letter letter2 = new Letter(a3, a6, 4.58M); //letter2
            Letter letter3 = new Letter(a4, a5, 7.5M);  //letter3
            Letter letter4 = new Letter(a5, a2, 5.8M);  //letter4

            // Ground test objects
            GroundPackage gp1 = new GroundPackage(a5, a8, 14, 10, 5, 12.5);  //ground 1
            GroundPackage gp2 = new GroundPackage(a3, a4, 24, 16, 7, 54);    //ground 2
            GroundPackage gp3 = new GroundPackage(a6, a3, 30, 8, 7.5, 24);   //ground 3
            GroundPackage gp4 = new GroundPackage(a7, a8, 21, 17, 12.5, 41); //ground 4

            // Next Day test objects
            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a2, 24, 17, 30, //next day 1
                                                            83, 4.53M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a4, a1, 18, 12, 19, //next day 2
                                                            67, 5.86M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a7, a8, 30, 3, 21,  //next day 3
                                                            23, 9.24M);
            NextDayAirPackage ndap4 = new NextDayAirPackage(a1, a6, 22, 16, 17, //next day 4
                                                            78, 6.88M);

            // Two Day test objects
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, //two day 1
                                                          60.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a3, a1, 57.3, 27.7, 23.0, //two day 2
                                                          78.4, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a8, a2, 28.4, 23.9, 19.8, //two day 3
                                                          80.5, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap4 = new TwoDayAirPackage(a5, a3, 60.2, 31.8, 26.8, //two day 4
                                                          35.7, TwoDayAirPackage.Delivery.Saver);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(letter4);

            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(gp4);

            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(ndap4);

            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);
            parcels.Add(tdap4);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            //Select all Parcels and order by destination zip (descending)
            Console.WriteLine("Select all Parcels and order by destination zip (descending)");
            Console.WriteLine("====================");

            //LINQ query used to order by destination zip (descending)
            var zips =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            foreach (var zip in zips)
            {
                Console.WriteLine(zip);
                Console.WriteLine("====================");
            }
            Pause();

            //Select all Parcels and order by cost (ascending)
            Console.WriteLine("Select all Parcels and order by cost (ascending)");
            Console.WriteLine("====================");

            //LINQ query used to order by destination zip (descending)
            var costs =
                from p in parcels
                orderby p.CalcCost()
                select p;

            foreach (var cost in costs)
            {
                Console.WriteLine(cost);
                Console.WriteLine("====================");
            }
            Pause();

            //Select all Parcels and order by Parcel type (ascending) and then cost (descending)
            Console.WriteLine("Select all Parcels and order by Parcel type (ascending)\n and then cost (descending)");
            Console.WriteLine("====================");

            //LINQ query used to order by Parcel type (ascending) and then cost (descending)
            var types =
                from p in parcels
                orderby p.GetType().ToString(), p.CalcCost() descending
            select p;

            foreach (var type in types)
            {
                Console.WriteLine(type);
                Console.WriteLine("====================");
            }
            Pause();

            //Select all AirPackage objects that are heavy and order by weight (descending)
            Console.WriteLine("Select all AirPackage objects that are heavy and order by weight (descending)");
            Console.WriteLine("====================");

            //LINQ query used to select AirPackages and list them by weight in descending order
            var airpackages =
                from p in parcels
                let ap = p as AirPackage //downcasting so it will only select objects of type AirPackage
                         where p == ap && ap.IsHeavy()
                         orderby ap.Weight descending
                         select ap;

            foreach (var airpackage in airpackages)
            {
                Console.WriteLine(airpackage);
                Console.WriteLine("====================");
            }
            Pause();
        }
Esempio n. 33
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        // linq query results are displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                                     "Louisville", "KY", 40202);    // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                                     "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);       // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);      // Test Address 4
            Address a5 = new Address("John Rolfe", "3142 Drivy Drive", "Apt. 9",
                                     "Springfield", "IL", 11111);   // Test Address 5
            Address a6 = new Address("Alex Anderson", "2354 IDC Road", "Apt. 10",
                                     "Bucket", "LA", 22222);        // Test Address 6
            Address a7 = new Address("Ricky Robinson", "7465 Nowhere BLVD", "Suit 54",
                                     "Glendale", "FL", 33333);      // Test Address 7
            Address a8 = new Address("Bob Lob Law", "8765 Don't Care Parkway", "Apt. 1",
                                     "dat boi", "NY", 45445);

            Letter letter1 = new Letter(a1, a2, 3.95M);                         // Letter test object
            Letter letter2 = new Letter(a2, a3, 4.95M);                         // Test Letter 2
            Letter letter3 = new Letter(a3, a4, 5.95M);                         // Test Letter 3
            Letter letter4 = new Letter(a4, a5, 6.95M);                         // Test Letter 4

            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);     // Ground test object
            GroundPackage gp2 = new GroundPackage(a4, a5, 10, 10, 10, 10);      // Test GroundPackage 2
            GroundPackage gp3 = new GroundPackage(a5, a6, 11, 11, 11, 11);      // Test GroundPackage 3
            GroundPackage gp4 = new GroundPackage(a6, a7, 12, 12, 12, 12);      // Test GroundPackage 4

            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15, // Next Day test object
                                                            85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a5, a6, 13, 13, 13,
                                                            13, 7.95M);             // Test NextDayAirPackage 2
            NextDayAirPackage ndap3 = new NextDayAirPackage(a6, a7, 10, 20, 40,
                                                            80, 8.95M);             // Test NextDayAirPackage 3
            NextDayAirPackage ndap4 = new NextDayAirPackage(a7, a8, 80, 90, 100,
                                                            200, 9.95M);            // Test NextDayAirPackage 4

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a8, a1, 14, 14, 14,
                                                          14, TwoDayAirPackage.Delivery.Early); // Test TwoDayAirPackage 2
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a7, a2, 16, 14, 16,
                                                          14, TwoDayAirPackage.Delivery.Saver); // Test TwoDayAirPackage 3
            TwoDayAirPackage tdap4 = new TwoDayAirPackage(a6, a3, 40, 56, 67,
                                                          31, TwoDayAirPackage.Delivery.Early);


            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            // Populate list
            parcels.Add(letter1);
            parcels.Add(letter2);
            parcels.Add(letter3);
            parcels.Add(letter4);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(gp3);
            parcels.Add(gp4);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(ndap4);
            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);
            parcels.Add(tdap4);

            Console.WriteLine("Original List\n");

            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("===============");
            }
            Pause();

            // Select all Parcels and order by destination zip (descending)
            Console.WriteLine("Descending Destination Zip\n");

            var descendingZip =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            // display descendingZip
            foreach (Parcel p in descendingZip)
            {
                Console.WriteLine(p.DestinationAddress.Zip);
                Console.WriteLine();
            }
            Pause();

            // Select all Parcels and order by cost (ascending)
            Console.WriteLine("Ascending Costs\n");

            var ascendingCosts =
                from p in parcels
                orderby p.CalcCost()
                select p;

            // display ascendingCosts
            foreach (Parcel p in ascendingCosts)
            {
                Console.WriteLine(p.CalcCost().ToString("C2"));
                Console.WriteLine();
            }
            Pause();

            // Select all Parcels and order by Parcel type (ascending) and then cost (descending)
            Console.WriteLine("Ascending Type");
            Console.WriteLine("Descending Cost\n");

            var typeThenCost =
                from p in parcels
                orderby p.GetType().ToString(), p.CalcCost() descending
            select p;

            // display typeThenCost
            foreach (Parcel p in typeThenCost)
            {
                Console.WriteLine(p.GetType().ToString());
                Console.WriteLine(p.CalcCost().ToString("C2"));
                Console.WriteLine();
            }
            Pause();

            // Select all AirPackage objects that are heavy and order by weight (descending)
            Console.WriteLine("Heavy Air Packages Sorted By Weight\n");

            var heavyAirPackageByWeight =
                from p in parcels
                where p is AirPackage
                let apkg = (AirPackage)p        // downcaste to AirPackage
                           where apkg.IsHeavy() // gain access to AirPackage methods
                           orderby apkg.Weight
                           select apkg;

            // display heavyAirPackageByWeight
            foreach (AirPackage apkg in heavyAirPackageByWeight)
            {
                Console.WriteLine(apkg.GetType().ToString());
                Console.WriteLine(apkg.Weight);
                Console.WriteLine();
            }
        }
Esempio n. 34
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202);       // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);              // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);                    // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);                   // Test Address 4
            Address a5 = new Address("Luke Skywalker", "123 Desert Rd",
                                     "Tattoine", "TA", 20495);                   // Test Address 5
            Address a6 = new Address("Darth Vader", "1 Death Star Rd",
                                     "Death Star", "DS", 05953);                 // Test Address 6
            Address a7 = new Address("Obi-Wan Kenobi", "69 Hello There St.",
                                     "Judland Wastes", "TA", 95302);             // Test Address 7
            Address a8 = new Address("Padme Amidala", "10 Will To Live Dr.",
                                     "Mustafar", "MU", 20193);                   // Test Address 8

            Letter letter1 = new Letter(a1, a2, 3.95M);                          // Letter test object
            Letter letter2 = new Letter(a2, a1, 4.8M);                           // Letter test object
            Letter letter3 = new Letter(a3, a7, 6.99M);                          // Letter test object

            GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5);      // Ground test object
            GroundPackage gp2 = new GroundPackage(a3, a4, 4, 1, 2, 1.5);         // Ground test object
            GroundPackage gp3 = new GroundPackage(a3, a4, 32, 33, 13, 23);       // Ground test object

            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,  // Next Day test object
                                                            85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a4, a6, 55, 14, 155, // Next Day test object
                                                            8, 7.50M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a7, a8, 25, 3, 12,   // Next Day test object
                                                            82, 7.50M);

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object
                                                          80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a8, a3, 4.5, 34, 44,      // Two Day test object
                                                          20.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a4, a5, 20.5, 32.5, 20,   // Two Day test object
                                                          50.5, TwoDayAirPackage.Delivery.Saver);


            List <Parcel> parcels = new List <Parcel>();       // List of test parcels

            // Populate list
            parcels.Add(letter1);
            parcels.Add(letter2);
            parcels.Add(letter3);

            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(gp3);

            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);

            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);

            //Selects all Parcels and orders by destination zip (descending)
            var byZip =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            //Selects all Parcels and orders by cost (ascending)
            var byCost =
                from p in parcels
                orderby p.CalcCost()//orders by cost using CalcCost method
                select p;

            //Selects all Parcels and orders them by type (ascending), and then cost (descending
            var byTypeThenCost =
                from p in parcels
                orderby p.GetType().ToString(), p.CalcCost() descending
            select p;

            //Selects all AirPackages that are heavy and orders them by weight (descending)
            var heavyByWeight =
                from p in parcels
                where ((p is AirPackage) && (p as AirPackage).IsHeavy()) //making sure only airpackages that are heavy show up
                let ap = p as AirPackage
                         where (ap != null) && ap.IsHeavy()              //filtering so that no null airpackages show up and they are heavy
                         orderby ap.Weight descending
                         select ap;

            //displaying the output of byZip
            foreach (var p in byZip)
            {
                WriteLine(p);
                WriteLine("=================");
            }
            WriteLine("========================================================");
            //displaying the output of byCost
            foreach (var p in byCost)
            {
                WriteLine(p);
                WriteLine("=================");
            }
            WriteLine("========================================================");
            //displaying the output of byTypeThenCost
            foreach (var p in byTypeThenCost)
            {
                WriteLine(p);
                WriteLine("=================");
            }
            WriteLine("========================================================");
            //displaying the output of heavyByWeight
            foreach (var p in heavyByWeight)
            {
                WriteLine(p);
                WriteLine("=================");
            }
            Pause();
        }
Esempio n. 35
0
        // Precondition:  None
        // Postcondition: Parcels have been created and reports generated using LINQ
        static void Main(string[] args)
        {
            // Verbose Setting - true means complete output of parcel data
            //                   false means only relevant data output
            bool VERBOSE = false;

            // Test Data - Magic Numbers OK
            Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45",
                "Louisville", "KY", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.", "",
                "Beverly Hills", "CA", 90210); // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                "El Paso", "TX", 79901); // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                "Portland", "ME", 04101); // Test Address 4
            Address a5 = new Address("John Doe", "111 Market St.", "",
                "Jeffersonville", "IN", 47130); // Test Address 5
            Address a6 = new Address("Jane Smith", "55 Hollywood Blvd.", "Apt. 9",
                "Los Angeles", "CA", 90212); // Test Address 6
            Address a7 = new Address("Captain Robert Crunch", "21 Cereal Rd.", "Room 987",
                "Bethesda", "MD", 20810); // Test Address 7
            Address a8 = new Address("Vlad Dracula", "6543 Vampire Way", "Apt. 1",
                "Bloodsucker City", "TN", 37210); // Test Address 8

            Letter letter1 = new Letter(a1, a2, 3.95M);                            // Letter test object
            Letter letter2 = new Letter(a3, a4, 4.25M);                            // Letter test object
            GroundPackage gp1 = new GroundPackage(a5, a6, 14, 10, 5, 12.5);        // Ground test object
            GroundPackage gp2 = new GroundPackage(a7, a8, 8.5, 9.5, 6.5, 2.5);     // Ground test object
            NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15,    // Next Day test object
                85, 7.50M);
            NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a5, 9.5, 6.0, 5.5, // Next Day test object
                5.25, 5.25M);
            NextDayAirPackage ndap3 = new NextDayAirPackage(a2, a7, 10.5, 6.5, 9.5, // Next Day test object
                15.5, 5.00M);
            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a5, a7, 46.5, 39.5, 28.0, // Two Day test object
                80.5, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage tdap2 = new TwoDayAirPackage(a8, a1, 15.0, 9.5, 6.5,   // Two Day test object
                75.5, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage tdap3 = new TwoDayAirPackage(a6, a4, 12.0, 12.0, 6.0,  // Two Day test object
                5.5, TwoDayAirPackage.Delivery.Saver);

            List<Parcel> parcels;      // List of test parcels

            parcels = new List<Parcel>();

            parcels.Add(letter1); // Populate list
            parcels.Add(letter2);
            parcels.Add(gp1);
            parcels.Add(gp2);
            parcels.Add(ndap1);
            parcels.Add(ndap2);
            parcels.Add(ndap3);
            parcels.Add(tdap1);
            parcels.Add(tdap2);
            parcels.Add(tdap3);

            Console.WriteLine("Original List:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
                Console.WriteLine("====================");
            }
            Pause();

            // Parcels by Destination Zip (desc)
            var parcelsByDestZip =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            Console.WriteLine("Parcels by Destination Zip (desc):");
            Console.WriteLine("====================");

            foreach (Parcel p in parcelsByDestZip)
            {
                if (VERBOSE)
                    Console.WriteLine(p);
                else
                    Console.WriteLine("{0:D5}", p.DestinationAddress.Zip);

                Console.WriteLine("====================");
            }
            Pause();

            // Parcels by cost
            var parcelsByCost =
                from p in parcels
                orderby p.CalcCost()
                select p;

            Console.WriteLine("Parcels by Cost:");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsByCost)
            {
                if (VERBOSE)
                    Console.WriteLine(p);
                else
                    Console.WriteLine("{0,8:C}", p.CalcCost());

                Console.WriteLine("====================");
            }
            Pause();

            // Parcels by type and cost (desc)
            var parcelsByTypeCost =
                from p in parcels
                orderby p.GetType().ToString(), p.CalcCost() descending
                select p;

            Console.WriteLine("Parcels by Type and Cost (desc):");
            Console.WriteLine("====================");
            foreach (Parcel p in parcelsByTypeCost)
            {
                if (VERBOSE)
                    Console.WriteLine(p);
                else
                    Console.WriteLine("{0,-17} {1,8:C}", p.GetType().ToString(),
                        p.CalcCost());

                Console.WriteLine("====================");
            }
            Pause();

            // Heavy AirPackages by Weight (desc)
            var heavyAirPackagesByWeight =
                from p in parcels
                let ap = p as AirPackage // Downcast if AirPackage, null otherwise
                where (ap != null) && ap.IsHeavy() // Safe because of short-circuit
                orderby ap.Weight descending
                select p;

            // Alternate Solutions

            //var heavyAirPackagesByWeight =
            //    from p in parcels
            //    where (p is AirPackage) && ((AirPackage)p).IsHeavy() // Safe downcast
            //    orderby ((AirPackage)p).Weight descending            // Safe downcast
            //    select p;

            // AirPackages first
            //var airPackages =
            //    from p in parcels
            //    where p is AirPackage
            //    select (AirPackage) p;

            // Filter from AirPackages
            //var heavyAirPackagesByWeight =
            //    from ap in airPackages
            //    where ap.IsHeavy()
            //    orderby ap.Weight descending
            //    select ap;

            Console.WriteLine("Heavy AirPackages by Weight (desc):");
            Console.WriteLine("====================");
            foreach (AirPackage ap in heavyAirPackagesByWeight)
            {
                if (VERBOSE)
                    Console.WriteLine(ap);
                else
                    Console.WriteLine("{0,-17} {1,4:F1}", ap.GetType().ToString(),
                        ap.Weight);

                Console.WriteLine("====================");
            }
        }
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            // Test Data - Magic Numbers OK
            Address a1 = new Address("  John Smith  ", "   123 Any St.   ", "  Apt. 45 ",
                                     "  Louisville   ", "  KY   ", 40202); // Test Address 1
            Address a2 = new Address("Jane Doe", "987 Main St.",
                                     "Beverly Hills", "CA", 90210);        // Test Address 2
            Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321",
                                     "El Paso", "TX", 79901);              // Test Address 3
            Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7",
                                     "Portland", "ME", 04101);             // Test Address 4
            Address a5 = new Address("Nicholas Goodridge", "1234 1st Street", "Apt #207",
                                     "Louisville", "KY", 12345);
            Address a6 = new Address("Derrek Baxter", "5678 2nd Street",
                                     "Cinncinatti", "OH", 67890);
            Address a7 = new Address("Eric Hoeweler", "0987 3rd Street",
                                     "Chicago", "IL", 45678);
            Address a8 = new Address("Lynnzee Kazee", "6543 4th Street",
                                     "Apt #456", "Panama", "KY", 10293);


            Letter l1 = new Letter(a1, a3, 0.50M); // Test Letter 1
            Letter l2 = new Letter(a2, a4, 1.20M); // Test Letter 2
            Letter l3 = new Letter(a4, a1, 1.70M); // Test Letter 3

            GroundPackage g1 = new GroundPackage(a5, a6, 5, 5, 5, 10);
            GroundPackage g2 = new GroundPackage(a7, a8, 3.3, 4.4, 5.5, 6.6);
            GroundPackage g3 = new GroundPackage(a8, a5, 4, 5, 6, 1);

            NextDayAirPackage n1 = new NextDayAirPackage(a1, a8, 5, 5, 5, 10, 5);
            NextDayAirPackage n2 = new NextDayAirPackage(a2, a7, 40, 40, 40, 6, 10);
            NextDayAirPackage n3 = new NextDayAirPackage(a3, a6, 10, 10, 10, 75, 20);
            NextDayAirPackage n4 = new NextDayAirPackage(a4, a5, 40, 40, 40, 100, 30);

            TwoDayAirPackage t1 = new TwoDayAirPackage(a2, a5, 5, 5, 5, 10, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage t2 = new TwoDayAirPackage(a4, a7, 40, 40, 40, 6, TwoDayAirPackage.Delivery.Saver);

            List <Parcel> parcels;      // List of test parcels

            parcels = new List <Parcel>();

            parcels.Add(l1); // Populate list
            parcels.Add(l2);
            parcels.Add(l3);
            parcels.Add(g1);
            parcels.Add(g2);
            parcels.Add(g3);
            parcels.Add(n1);
            parcels.Add(n2);
            parcels.Add(n3);
            parcels.Add(n4);
            parcels.Add(t1);
            parcels.Add(t2);


            Console.WriteLine("Select all Parcels and order by destination zip(descending)\n");
            var part1 =
                from p in parcels
                orderby p.DestinationAddress.Zip descending
                select p;

            foreach (Parcel p in part1)
            {
                Console.WriteLine($"{p.DestinationAddress.Zip:D5}");
            }

            Console.WriteLine("\n\nSelect all Parcels and order by cost (ascending)\n");
            var part2 =
                from p in parcels
                orderby p.CalcCost() ascending
                select p;

            foreach (Parcel p in part2)
            {
                Console.WriteLine($"{p.CalcCost():C}");
            }

            Console.WriteLine("\n\nSelect all Parcels and order by Parcel type (ascending) and then cost (descending)\n");
            var part3 =
                from p in parcels
                orderby p.GetType().ToString() ascending, p.CalcCost() descending
            select p;

            foreach (Parcel p in part3)
            {
                Console.WriteLine($"type: {p.GetType().ToString()} \tcost: {p.CalcCost():C}");
            }

            Console.WriteLine("Select all AirPackage objects that are heavy and order by weight (descending)\n");
            var part4 =
                from p in parcels
                let ap = p as AirPackage
                         where ap != null && ap.IsHeavy()
                         orderby ap.Weight descending
                         select ap;

            foreach (Parcel p in part4)
            {
                Console.WriteLine(p);
            }
        }