예제 #1
0
        // Precondition:  None
        // Postcondition: Parcels have been created and displayed
        static void Main(string[] args)
        {
            //  creates ten Address objects
            Address ad1A = new Address("Rrose Selavy", "5454 Dada Ave.", "Apt. 66", "New York", "Ny", 10019);
            Address ad1B = new Address("Leonora Carrington", "9632 Hyena Blvd.", "Ojai", "CA", 90322);
            Address ad2A = new Address("Meret Oppenheim", "54 Teacup Ln.", "Apt. 3", "Chicago", "IL", 34998);
            Address ad2B = new Address("Joan Miro", "9021 Sculpture Dr.", "Portland", "OR", 98069);
            Address ad3A = new Address("Hugo Ball", "901 Century Ct.", "Miami", "FL", 20001);
            Address ad3B = new Address("Leonor Fini", "306 Lake Pl.", "Unit 4C", "Denver", "CO", 76663);
            Address ad4A = new Address("Tristan Tzara", "5050 Paris St.", "Omaha", "NE", 55091);
            Address ad4B = new Address("Marcel Duchamp", "669 R. Mutt NE", "Woodinville", "WA", 99886);
            Address ad5A = new Address("Hannah Hoch", "22019 Gingko St.", "Apt. 60", "Austin", "TX", 78704);
            Address ad5B = new Address("Andre Breton", "9077 Basil Ave.", "New Orleans", "LA", 43329);

            //  creates three Letter objects
            Letter post1 = new Letter(ad1A, ad1B, 3.95M);
            Letter post2 = new Letter(ad2A, ad2B, 3.95M);
            Letter post3 = new Letter(ad3A, ad3B, 3.95M);

            //  creates three Ground Package objects
            GroundPackage ground1 = new GroundPackage(ad1B, ad1A, 10, 5.5, 2, 2);
            GroundPackage ground2 = new GroundPackage(ad2B, ad2A, 7, 3, 1.5, 3);
            GroundPackage ground3 = new GroundPackage(ad3B, ad3A, 20, 36, 15, 45);

            //  creates three Next Day Air objects
            NextDayAirPackage nextDayAir1 = new NextDayAirPackage(ad5A, ad5B, 10, 12, 6.5, 9, 15M);
            NextDayAirPackage nextDayAir2 = new NextDayAirPackage(ad2A, ad2B, 30, 24, 12, 83, 15M);
            NextDayAirPackage nextDayAir3 = new NextDayAirPackage(ad3A, ad1B, 55, 15, 35, 27, 15M);

            //  creates three Two Day Air objects
            TwoDayAirPackage twoDayAir1 = new TwoDayAirPackage(ad3A, ad3B, 24, 13.5, 3, 77, TwoDayAirPackage.Delivery.Saver);
            TwoDayAirPackage twoDayAir2 = new TwoDayAirPackage(ad4A, ad4B, 36, 36, 36, 45, TwoDayAirPackage.Delivery.Early);
            TwoDayAirPackage twoDayAir3 = new TwoDayAirPackage(ad5A, ad2B, 8, 14, 3, 15, TwoDayAirPackage.Delivery.Saver);

            //  creates List to store Parcel objects
            var parcels = new List <Parcel>()
            {
                post1,
                post2,
                post3,
                ground1,
                ground2,
                ground3,
                nextDayAir1,
                nextDayAir2,
                nextDayAir3,
                twoDayAir1,
                twoDayAir2,
                twoDayAir3
            };

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

            parcels.Sort(); // Sort by cost - ascending (default)
            Console.Out.WriteLine("Sorted list (natural order: by cost - ascending):");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine($"{p.GetType().Name}: {p.CalcCost():C}");
            }
            Pause();

            parcels.Sort(new DescendingZip()); // Sort by destination zip - descending

            Console.Out.WriteLine("Sorted list (descending destination zip code) using Comparer:");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine($"{p.GetType().Name}: {p.DestinationAddress.Zip}");
            }
            Pause();

            parcels.Sort(new AscendingTypeDescendingCost()); // Sort by type - ascending, then cost - descending

            Console.Out.WriteLine("Sorted list (ascending type, descending cost) using Comparer:");
            foreach (Parcel p in parcels)
            {
                Console.WriteLine($"{p.GetType().Name}: {p.CalcCost():C}");
            }
            Pause();
        }
예제 #2
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

            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

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

            // Add test data to list
            parcels.Add(l1);
            parcels.Add(l2);
            parcels.Add(l3);

            foreach (Parcel p in parcels)
            {
                Console.WriteLine(p);
            }
            // Display data
            Console.WriteLine("Program 1A - List of Parcels\n");

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

            Console.WriteLine("Ground Package: ");
            Console.WriteLine();
            GroundPackage package1 = new GroundPackage(a2, a1, 1, 2, 2, 10);

            Console.WriteLine(package1);
            Console.WriteLine("--------------------");
            Console.WriteLine();

            Console.WriteLine("Next Day Air Package: ");
            Console.WriteLine();
            NextDayAirPackage air1 = new NextDayAirPackage(a2, a1, 30, 30, 40, 75, 10M);

            Console.WriteLine(air1);
            Console.WriteLine("--------------------");
            Console.WriteLine();


            Console.WriteLine("Two Day Air Package: ");
            Console.WriteLine();
            TwoDayAirPackage air2 = new TwoDayAirPackage(a2, a1, 30, 30, 40, 75, TwoDayAirPackage.Delivery.Saver);

            Console.WriteLine(air2);
            Console.WriteLine("--------------------");
            Console.WriteLine();

            Console.WriteLine("Another Two Day Air Package: ");
            Console.WriteLine();
            TwoDayAirPackage air3 = new TwoDayAirPackage(a2, a1, 30, 30, 40, 75, TwoDayAirPackage.Delivery.Saver);

            Console.WriteLine(air3);
            Console.WriteLine("--------------------");
            Console.WriteLine();
        }