// 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);

            // Display data
            Console.WriteLine("Program 1A - List of Parcels\n");

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

            TwoDayAirPackage tdap1 = new TwoDayAirPackage(a1, a2, 20, 50, 10, 90, 0);   //Test two day air package

            Console.WriteLine(tdap1);                                                   // Display

            GroundPackage gp1 = new GroundPackage(a1, a2, 5, 7, 8, 80);                 // Test GroundPackage

            Console.WriteLine(gp1);                                                     // Display

            NextDayAirPackage ndap1 = new NextDayAirPackage(a3, a4, 50, 50, 50, 50, 5); // Test Next day air package

            Console.WriteLine(ndap1);                                                   // Display
        }
        // 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);

            //// Display data
            //Console.WriteLine("Program 0 - List of Parcels\n");

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



            //Testing classes
            GroundPackage     gp = new GroundPackage(a1, a2, 10, 12.24, 13.3, 16.56);
            NextDayAirPackage nd = new NextDayAirPackage(a1, a2, 10, 12.24, 13.3, 16.56, 50);
            TwoDayAirPackage  td = new TwoDayAirPackage(a1, a2, 10, 12.24, 13.3, 16.56, DeliveryEnum.Saver);

            Console.WriteLine(gp.ToString());
            Console.WriteLine(nd.ToString());
            Console.WriteLine(td.ToString());
        }
Esempio n. 3
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);

            // Display data
            Console.WriteLine("Program 0 - List of Parcels\n");

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

            //Test data for ground packages:

            GroundPackage g1 = new GroundPackage(a1, a2, 5, 5, 5, 10);
            GroundPackage g2 = new GroundPackage(a3, a4, 3.3, 4.4, 5.5, 6.6);
            GroundPackage g3 = new GroundPackage(a4, a1, 4, 5, 6, 1);

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

            // Add test data to list
            groundPackages.Add(g1);
            groundPackages.Add(g2);
            groundPackages.Add(g3);

            // Display data
            Console.WriteLine("\nProgram 1A - List of Ground Packages\n");

            foreach (GroundPackage g in groundPackages)
            {
                Console.WriteLine(g);
                Console.WriteLine("--------------------");
            }

            //Test data for NextDayAirPackage:

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


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

            // Add test data to list
            nextDayAirPackages.Add(n1);
            nextDayAirPackages.Add(n2);
            nextDayAirPackages.Add(n3);
            nextDayAirPackages.Add(n4);

            // Display data
            Console.WriteLine("\nProgram 1A - List of Next day Air Packages\n");

            foreach (NextDayAirPackage n in nextDayAirPackages)
            {
                Console.WriteLine(n);
                Console.WriteLine("--------------------");
            }

            //Test data for TwoDayAirPackage:

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

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

            // Add test data to list
            twoDayAirPackages.Add(t1);
            twoDayAirPackages.Add(t2);

            // Display data
            Console.WriteLine("\nProgram 1A - List of Two day Air Packages\n");

            foreach (TwoDayAirPackage n in twoDayAirPackages)
            {
                Console.WriteLine(n);
                Console.WriteLine("--------------------");
            }
        }
        // Precondition:  None
        // Postcondition: Small list of Parcels is created and displayed
        static void Main(string[] args)
        {
            //Define some wacky addresses to send packages to and fro
            var addresses = new Address[]
            {
                new Address("Bruce Wayne", "123 Lane Ave", "Apt 10", "Louisville", "KY", 40023),
                new Address("Steve Rogers", "Street Lane", "Gilbertsville", "KY", 42044),
                new Address("Bojack Horesman", "203 Stree", "Apt 178", "Los Angles", "CA", 90210),
                new Address("Optimus Prime", "This is a road Rd", "Abie", "NE", 68001),
                new Address("Princess Carolyn", "Pince Lane", "Apt 56", "Pocatello", "ID", 83201),
                new Address("Megaman", "Blaster Street", "Biddeford", "ME", 04005),
                new Address("Boaty McBoatFace", "Waterway", "Apt 6", "Orange Park", "FL", 32003),
                new Address("Gary Gary", "Garys Street, go away", "Allenton", "MI", 48002),
            };

            List <Parcel> parcels = new List <Parcel>();

            //Loop through and create each Parcel type 10 times, I may have duplicates of parcels to addresses
            for (var i = 0; i < 5; i++)
            {
                //Get the index of our addresses, this way we can make sure they arent the same
                int oValue = getRandomInt(addresses.Length);
                int dValue = getRandomInt(addresses.Length, oValue);

                //Use the index to grab the addresses
                Address origin      = addresses[oValue];
                Address destination = addresses[dValue];

                GroundPackage gp = new GroundPackage(origin, destination, getRandomDouble(5),
                                                     getRandomDouble(5), getRandomDouble(5), getRandomDouble(5));
                parcels.Add(gp);

                NextDayAirPackage ndap = new NextDayAirPackage(origin, destination,
                                                               getRandomDouble(14), getRandomDouble(14), getRandomDouble(14), getRandomDouble(140), 50m);
                parcels.Add(ndap);

                TwoDayAirPackage tdap = new TwoDayAirPackage(origin, destination, getRandomDouble(180), getRandomDouble(14),
                                                             getRandomDouble(16), getRandomDouble(6), (DeliveryEnum)getRandomInt(1));
                parcels.Add(tdap);
            }

            //Lets force some heavy packages, cause I'm too lazy to make a better randomizer
            TwoDayAirPackage heavy_tdap = new TwoDayAirPackage(addresses[2], addresses[6], getRandomDouble(180), getRandomDouble(14),
                                                               getRandomDouble(16), 250, (DeliveryEnum)getRandomInt(1));

            parcels.Add(heavy_tdap);

            NextDayAirPackage heavy_ndap = new NextDayAirPackage(addresses[6], addresses[2],
                                                                 getRandomDouble(14), getRandomDouble(14), getRandomDouble(14), 200, 50m);

            parcels.Add(heavy_ndap);


            //Log the full list
            logParcels(parcels);

            //Part one Select all parcles and order by destination zip (desc)
            Console.WriteLine("-----------------------------------------------       Part 1");
            var descDest = from parcel in parcels orderby parcel.DestinationAddress.Zip descending select parcel;

            logParcels(descDest.ToList());


            //select all and order by cost (ascending)
            Console.WriteLine("-----------------------------------------------       Part 2");
            var byCost = from parcel in parcels orderby parcel.CalcCost() select parcel;

            logParcels(byCost.ToList());


            //select all parcels and orby parcel type then by cost (desc)
            Console.WriteLine("-----------------------------------------------       Part 3");
            var byTypeThenCost = from parcel in parcels orderby parcel.GetType().ToString() orderby parcel.CalcCost() descending select parcel;

            logParcels(byTypeThenCost.ToList());

            //select all air packages that are heavy and order by weight (desc)
            Console.WriteLine("-----------------------------------------------       Part 4");
            var heavyAirPackageByWeight = from airpackage in (from parcel in parcels
                                                              where parcel.GetType().Equals(typeof(NextDayAirPackage)) || parcel.GetType().Equals(typeof(AirPackage))
                                                              select(AirPackage) parcel) where airpackage.isHeavy() orderby airpackage.Weight descending
                                          select airpackage;

            logParcels(heavyAirPackageByWeight.ToList());


            var airpackages = from airp in parcels where airp is AirPackage select airp as AirPackage;
            var here        = from airpackage in airpackages where airpackage.isHeavy() orderby airpackage.Weight descending select airpackage;

            logParcels(here.ToList());

            Console.ReadLine();
        }