Exemplo n.º 1
0
        static void Main(string[] args)
        {
            OvernightPackage overnight = new OvernightPackage("James", "Stuart", "Ogun State", "Hacob", "Brown", "Ibadan", 5.0, 5000M, "OverNight Package");
            TwoDayPackage    twoDay    = new TwoDayPackage("Jeremy", "Stutgartt", "Oyo State", "Hamman", "Bronze", "Ota", 6.0, 4000M, "Two Day Package");

            Console.WriteLine("\n Packages processed polymorphically...\n");
            Package[] packages = new Package[2] {
                overnight, twoDay
            };
            decimal sum = 0M;

            foreach (Package package in packages)
            {
                sum = sum + package.CalculateCost();
                Console.WriteLine($"{package}\nShipping Cost: {package.CalculateCost():C}\n");
            }
            Console.WriteLine($"Total Shipping Cost = {sum:C}");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            TwoDayPackage    twoDayPackage    = new TwoDayPackage("Akande", "Olufunmi", "5,Abooluwa,magodo,Lagos", "Inioluwa", "Okunade", "8,Ebutemeta street,Lagos", 20.0, 3.0, 300m);
            OvernightPackage overnightPackage = new OvernightPackage("Ibrahim", "Babatunde", "7,Idioro Street,Ibadan", "Adebowale", "Bolanle", "5,Taiwo street,Boluwaji,Ibadan", 12.0, 3.0, 250m);

            List <Package> packages = new List <Package>()
            {
                twoDayPackage, overnightPackage
            };


            decimal Total = 0m;

            foreach (var package in packages)
            {
                Console.WriteLine(package.ToString());
                Total += package.CalculateCost();

                Console.WriteLine($"\nThe cost of Shipping is: {package.CalculateCost():C}");
            }

            Console.WriteLine($"\nThe total cost for the two shippings is: {Total}");
        }