Ejemplo n.º 1
0
    static void Main()
    {
        // create derived-class objects
        var salariedEmployee = new SalariedEmployee("John", "Smith",
                                                    "111-11-1111", 800.00M);
        var hourlyEmployee = new HourlyEmployee("Karen", "Price",
                                                "222-22-2222", 16.75M, 40.0M);
        var commissionEmployee = new CommissionEmployee("Sue", "Jones",
                                                        "333-33-3333", 10000.00M, .06M);
        var basePlusCommissionEmployee =
            new BasePlusCommissionEmployee("Bob", "Lewis",
                                           "444-44-4444", 5000.00M, .04M, 300.00M);

        Console.WriteLine("Employees processed individually:\n");

        Console.WriteLine($"{salariedEmployee}\nearned: " +
                          $"{salariedEmployee.Earnings():C}\n");
        Console.WriteLine(
            $"{hourlyEmployee}\nearned: {hourlyEmployee.Earnings():C}\n");
        Console.WriteLine($"{commissionEmployee}\nearned: " +
                          $"{commissionEmployee.Earnings():C}\n");
        Console.WriteLine($"{basePlusCommissionEmployee}\nearned: " +
                          $"{basePlusCommissionEmployee.Earnings():C}\n");

        // create List<Employee> and initialize with employee objects
        var employees = new List <Employee>()
        {
            salariedEmployee,
            hourlyEmployee, commissionEmployee, basePlusCommissionEmployee
        };

        Console.WriteLine("Employees processed polymorphically:\n");

        // generically process each element in employees
        foreach (var currentEmployee in employees)
        {
            Console.WriteLine(currentEmployee); // invokes ToString

            // determine whether element is a BasePlusCommissionEmployee
            if (currentEmployee is BasePlusCommissionEmployee)
            {
                // downcast Employee reference to
                // BasePlusCommissionEmployee reference
                var employee = (BasePlusCommissionEmployee)currentEmployee;

                employee.BaseSalary *= 1.10M;
                Console.WriteLine("new base salary with 10% increase is: " +
                                  $"{employee.BaseSalary:C}");
            }

            Console.WriteLine($"earned: {currentEmployee.Earnings():C}\n");
        }

        // get type name of each object in employees
        for (int j = 0; j < employees.Count; j++)
        {
            Console.WriteLine(
                $"Employee {j} is a {employees[j].GetType()}");
        }
    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Employee salariedEmployee               = new SalariedEmployee("John Smith", "111-11-1111", 800);
            Employee hourlyEmployee                 = new HourlyEmployee("Karen Price", "222-22-2222", 16.75m, 40d);
            Employee commissionEmployee             = new CommissionEmployee("Sue Jones", "333-33-3333", 10_000m, 0.06d);
            Employee salariedPlusCommissionEmployee = new SalariedPlusCommissionEmployee("Bob Lewis", "444-44-4444", 5_000, 0.04d, 300);

            SalariedPlusCommissionEmployee salariedPlusCommissionEmployeeWith10PercentReward = (SalariedPlusCommissionEmployee)salariedPlusCommissionEmployee;

            salariedPlusCommissionEmployeeWith10PercentReward.BaseSalary *= 1.1M;


            Console.WriteLine("Employees processed individually:");
            Console.WriteLine("-----------------------------------------------------------------------------------------");

            Console.WriteLine($"{salariedEmployee}\nEarned: {salariedEmployee.Earnings()}");
            Console.WriteLine("-----------------------------------------------------------------------------------------");
            Console.WriteLine($"{hourlyEmployee}\nEarned: {hourlyEmployee.Earnings()}");
            Console.WriteLine("-----------------------------------------------------------------------------------------");
            Console.WriteLine($"{commissionEmployee}\nEarned: {commissionEmployee.Earnings()}");
            Console.WriteLine("-----------------------------------------------------------------------------------------");
            Console.WriteLine($"{salariedPlusCommissionEmployee}\nEarned: {salariedPlusCommissionEmployee.Earnings()}");
            Console.WriteLine("-----------------------------------------------------------------------------------------");


            List <Employee> employees = new List <Employee>
            {
                salariedEmployee, hourlyEmployee, commissionEmployee, salariedPlusCommissionEmployee
            };

            Console.WriteLine("Employees processed polymorphically:");
            Console.WriteLine("-----------------------------------------------------------------------------------------");

            foreach (var employee in employees)
            {
                Console.WriteLine(employee);

                if (employee is SalariedPlusCommissionEmployee salariedPlusCommissionEmployee1)
                {
                    salariedPlusCommissionEmployee1.BaseSalary *= 1.1m;
                    Console.WriteLine($"new base salary with 10% increase is: {salariedPlusCommissionEmployee1.BaseSalary}");
                }

                Console.WriteLine($"Earned {employee.Earnings()}");
                Console.WriteLine("-----------------------------------------------------------------------------------------");
            }

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            SalariedEmployee salariedEmployee =
                new SalariedEmployee("John", "Smith", "111-11-1111", 800.00M);
            HourlyEmployee hourlyEmployee =
                new HourlyEmployee("Karen", "Price", "222-22-2222", 16.75M, 40.0M);
            CommissionEmployee commissionEmployee =
                new CommissionEmployee("Sue", "Jonse", "333-33-333", 10000.00M, .06M);
            BasePlusCommissionEmployee basePlusCommissionEmployee =
                new BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", 5000.00M, .04M, 300.00M);

            Console.WriteLine("Employees processed individually:\n");

            Console.WriteLine("{0}\nearned: {1:C}\n", salariedEmployee, salariedEmployee.Earnings());
            Console.WriteLine("{0}\nearned: {1:C}\n", hourlyEmployee, hourlyEmployee.Earnings());
            Console.WriteLine("{0}\nearned: {1:C}\n", commissionEmployee, commissionEmployee.Earnings());
            Console.WriteLine("{0}\nearned: {1:C}\n", basePlusCommissionEmployee, basePlusCommissionEmployee.Earnings());

            Employee[] employees = new Employee[4];

            employees[0] = salariedEmployee;
            employees[1] = hourlyEmployee;
            employees[2] = commissionEmployee;
            employees[3] = basePlusCommissionEmployee;

            Console.WriteLine("Employees processed polymorphically:\n");

            foreach (Employee currentEmployee in employees)
            {
                Console.WriteLine(currentEmployee);

                if (currentEmployee is BasePlusCommissionEmployee)
                {
                    BasePlusCommissionEmployee employee =
                        (BasePlusCommissionEmployee)currentEmployee;

                    employee.BaseSalary *= 1.10M;

                    Console.WriteLine("new base salary with 10% increase is:{0:C}", employee.BaseSalary);
                }
                Console.WriteLine("earned {0:C}\n", currentEmployee.Earnings());
            }

            for (int j = 0; j < employees.Length; j++)
            {
                Console.WriteLine("Employee {0} is a {1}", j, employees[j].GetType());
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //  Test each class by entering employee via constructor and printing details
            HourlyEmployee Hire1 = new HourlyEmployee("Joe","Dunn","070723889",1000,40);
            Console.WriteLine(Hire1);
            Console.WriteLine("{0}\t {1}\n","Total earnings:",Hire1.Earnings());

            SalariedEmployee Hire2 = new SalariedEmployee("John", "Rex", "970723889", 80000);
            Console.WriteLine(Hire2);
            Console.WriteLine("{0}\t {1}\n", "Total earnings:", Hire2.Earnings());

            BasePlusCommissionEmployee Hire3 = new BasePlusCommissionEmployee("Reg", "Smith", "370723889", 10000, 1/5, 40000);
            Console.WriteLine(Hire3);
            Console.WriteLine("{0}\t {1}\n", "Total earnings:", Hire3.Earnings());

            CommissionEmployee Hire4 = new CommissionEmployee("Lisa", "Pepper", "170723889", 100000, 1 / 5);
            Console.WriteLine(Hire4);
            Console.WriteLine("{0}\t {1}\n", "Total earnings:", Hire4.Earnings());

            Console.Read();
        }
Ejemplo n.º 5
0
    static void Main()
    {
        // create derived-class objects
        var salariedEmployee = new SalariedEmployee("John", "Smith",
                                                    "111-11-1111", 800.00M);
        var hourlyEmployee = new HourlyEmployee("Karen", "Price",
                                                "222-22-2222", 16.75M, 40.0M);
        var commissionEmployee = new CommissionEmployee("Sue", "Jones",
                                                        "333-33-3333", 10000.00M, .06M);
        var basePlusCommissionEmployee =
            new BasePlusCommissionEmployee("Bob", "Lewis",
                                           "444-44-4444", 5000.00M, .04M, 300.00M);

        Console.WriteLine("Employees processed individually:\n");

        Console.WriteLine($"{salariedEmployee}\nearned: " +
                          $"{salariedEmployee.Earnings():C}\n");
        Console.WriteLine(
            $"{hourlyEmployee}\nearned: {hourlyEmployee.Earnings():C}\n");
        Console.WriteLine($"{commissionEmployee}\nearned: " +
                          $"{commissionEmployee.Earnings():C}\n");
        Console.WriteLine($"{basePlusCommissionEmployee}\nearned: " +
                          $"{basePlusCommissionEmployee.Earnings():C}\n");

        // create List<Employee> and initialize with employee objects
        var employees = new List <Employee>()
        {
            salariedEmployee,
            hourlyEmployee, commissionEmployee, basePlusCommissionEmployee
        };

        Console.WriteLine("Employees processed polymorphically:\n");

        // generically process each element in employees
        foreach (var currentEmployee in employees)
        {
            Console.WriteLine(currentEmployee); // invokes ToString

            // determine whether element is a BasePlusCommissionEmployee
            if (currentEmployee is BasePlusCommissionEmployee)
            {
                // downcast Employee reference to
                // BasePlusCommissionEmployee reference
                var employee = (BasePlusCommissionEmployee)currentEmployee;

                employee.BaseSalary *= 1.10M;
                Console.WriteLine("new base salary with 10% increase is: " +
                                  $"{employee.BaseSalary:C}");
            }

            Console.WriteLine($"earned: {currentEmployee.Earnings():C}\n");
        }

        // get type name of each object in employees
        for (int j = 0; j < employees.Count; j++)
        {
            Console.WriteLine(
                $"Employee {j} is a {employees[j].GetType()}");
        }

        Console.WriteLine("-----------------Beginnig of Question 3 answer");
        Console.WriteLine("-----------------by Jovane Marques - 300982100");
        var employeesNewSalary = employees.Select(e =>
                                                  new
        {
            FullName = e.FirstName + " " + e.LastName,
            Salary   = e is BasePlusCommissionEmployee ? ((e as BasePlusCommissionEmployee).BaseSalary * Decimal.Parse("1.1")) : e.Earnings()
        });

        foreach (var emp in employeesNewSalary)
        {
            Console.WriteLine("Employee: " + emp.FullName + ", Salary = " + emp.Salary);
        }
        Console.WriteLine("-----------------End of Question 3 answer");

        Console.ReadKey();
    }
Ejemplo n.º 6
0
    static void Main()
    {
        var date1                      = new Date(1, 1, 1989);
        var birthday                   = new Date(2, 9, 1989);
        var salariedEmployee           = new SalariedEmployee("John", "Smith", "111-11-1111", 800.00m, birthday);
        var hourlyEmployee             = new HourlyEmployee("Karen", "Price", "222-22-2222", 16.75m, 40.0m, birthday);
        var commissionEmployee         = new CommissionEmployee("Sue", "Jones", "333-33-3333", 10000.00m, .06m, birthday);
        var basePlusCommissionEmployee = new BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", 5000.00m, .04m, 300.00m, birthday);
        var pieceWorker2               = new PieceWorker("Brian", "Briansen", "555-55-5555", .40m, 1000, birthday);

        birthday = new Date(4, 9, 1989);
        var pieceWorker = new PieceWorker("Brian", "Briansen", "555-55-5555", .40m, 1000, birthday);

        Console.WriteLine("Employees processed individually:\n");

        Console.WriteLine($"{salariedEmployee}\nearned: " +
                          $"{salariedEmployee.Earnings():C}\n");
        Console.WriteLine($"{hourlyEmployee}\nearned: " +
                          $"{hourlyEmployee.Earnings():C}\n");
        Console.WriteLine($"{commissionEmployee}\nearned: " +
                          $"{commissionEmployee.Earnings():C}\n");
        Console.WriteLine($"{basePlusCommissionEmployee}\nearned: " +
                          $"{basePlusCommissionEmployee.Earnings():C}\n");
        Console.WriteLine($"{pieceWorker}\nearned: " +
                          $"{pieceWorker.Earnings():C}");

        var employees = new List <Employee>()
        {
            salariedEmployee, hourlyEmployee, commissionEmployee, basePlusCommissionEmployee, pieceWorker2, pieceWorker
        };

        Console.WriteLine("\nEmployees processed polymorphically: \n");
        for (int month = 1; month < 12; month++)
        {
            foreach (var currentEmployee in employees)
            {
                Console.WriteLine(currentEmployee);
                if (currentEmployee is BasePlusCommissionEmployee)
                {
                    var employee = (BasePlusCommissionEmployee)currentEmployee;

                    employee.BaseSalary *= 1.10m;
                    Console.WriteLine("new base salary with 10% increase is: " +
                                      $"{employee.BaseSalary:C}");
                }
                if (month == currentEmployee.Birthday.Month)
                {
                    Console.WriteLine("Birthday Bonus: 100.00");
                    Console.WriteLine($"earned {currentEmployee.Earnings() + 100:C}\n");
                }
                else
                {
                    Console.WriteLine($"earned {currentEmployee.Earnings():C}\n");
                }
            }
        }


        for (int j = 0; j < employees.Count; j++)
        {
            Console.WriteLine($"Employee {j} is a {employees[j].GetType()}");
        }

        Console.ReadLine();
    }
    public static void Main(string[] args)
    {
        // create derived class objects
        SalariedEmployee salariedEmployee =
            new SalariedEmployee("John", "Smith", "111-11-1111", 800.00M);
        HourlyEmployee hourlyEmployee =
            new HourlyEmployee("Karen", "Price",
                               "222-22-2222", 16.75M, 40.0M);
        CommissionEmployee commissionEmployee =
            new CommissionEmployee("Sue", "Jones",
                                   "333-33-3333", 10000.00M, .06M);
        BasePlusCommissionEmployee basePlusCommissionEmployee =
            new BasePlusCommissionEmployee("Bob", "Lewis",
                                           "444-44-4444", 5000.00M, .04M, 300.00M);

        Console.WriteLine("Employees processed individually:\n");

        Console.WriteLine("{0}\nearned: {1:C}\n",
                          salariedEmployee, salariedEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          hourlyEmployee, hourlyEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          commissionEmployee, commissionEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          basePlusCommissionEmployee,
                          basePlusCommissionEmployee.Earnings());

        // create four-element Employee array
        Employee[] employees = new Employee[4];

        // initialize array with Employees of derived types
        employees[0] = salariedEmployee;
        employees[1] = hourlyEmployee;
        employees[2] = commissionEmployee;
        employees[3] = basePlusCommissionEmployee;

        Console.WriteLine("Employees processed polymorphically:\n");

        // generically process each element in array employees
        processEmployees(employees);

        // get type name of each object in employees array
        for (int j = 0; j < employees.Length; j++)
        {
            Console.WriteLine("Employee {0} is a {1}", j,
                              employees[j].GetType());
        }

        Console.WriteLine("\nEMPLOYEES PROCESSED BY IPAYABLE\n");

        //Create IPayable array
        IPayable[] payableObjects = new IPayable[8];
        payableObjects[0] = new SalariedEmployee(
            "John", "Smith", "111-11-1111", 700M);
        payableObjects[1] = new SalariedEmployee(
            "Antonio", "Smith", "555-55-5555", 800M);
        payableObjects[2] = new SalariedEmployee(
            "Victor", "Smith", "444-44-4444", 600M);
        payableObjects[3] = new HourlyEmployee(
            "Karen", "Price", "222-22-2222", 16.75M, 40M);
        payableObjects[4] = new HourlyEmployee(
            "Ruben", "Zamora", "666-66-6666", 20.00M, 40M);
        payableObjects[5] = new CommissionEmployee(
            "Sue", "Jones", "333-33-3333", 10000M, .06M);
        payableObjects[6] = new BasePlusCommissionEmployee(
            "Bob", "Lewis", "777-77-7777", 5000M, .04M, 300M);
        payableObjects[7] = new BasePlusCommissionEmployee(
            "Lee", "Duarte", "888-88-888", 5000M, .04M, 300M);

        // generically process each element in array employees
        processEmployees(payableObjects);

        //bubble sort and pointer
        Console.WriteLine("\nIPAYABLES SORTED BY SSN:\n");
        BubbleSort(payableObjects, SSNAscending);
        foreach (Employee currentEmployee in payableObjects)
        {
            Console.WriteLine(currentEmployee); // invokes ToString
            Console.WriteLine(
                "earned {0:C}\n", currentEmployee.Earnings());
        } // end foreach

        //IComparer
        Console.WriteLine("\nIPAYABLES SORTED BY LAST NAME ASCENDING\n");
        ArrayList comparerSample = new ArrayList();

        //populate ArrayList for IComparer and IComprable
        foreach (IPayable currentPayable in payableObjects)
        {
            comparerSample.Add(currentPayable);
        }//end foreach
        IComparer lastAscend = new SortLastNAscending();

        comparerSample.Sort(lastAscend);
        foreach (Employee currentEmployee in comparerSample)
        {
            Console.WriteLine(currentEmployee); // invokes ToString
            Console.WriteLine(
                "earned {0:C}\n", currentEmployee.Earnings());
        } // end foreach

        //IComparable implementation
        Console.WriteLine("\nIPAYABLES SORTED BY SALARY DESCEDNING\n");
        comparerSample.Sort();
        foreach (Employee currentEmployee in comparerSample)
        {
            Console.WriteLine(currentEmployee); // invokes ToString
            Console.WriteLine(
                "earned {0:C}\n", currentEmployee.Earnings());
        } // end foreach
    }     // end Main
    public static void Main(string[] args)
    {
        // create derived class objects
        SalariedEmployee salariedEmployee =
           new SalariedEmployee("John", "Smith", "111-11-1111", 800.00M);
        HourlyEmployee hourlyEmployee =
           new HourlyEmployee("Karen", "Price",
           "222-22-2222", 16.75M, 40.0M);
        CommissionEmployee commissionEmployee =
           new CommissionEmployee("Sue", "Jones",
           "333-33-3333", 10000.00M, .06M);
        BasePlusCommissionEmployee basePlusCommissionEmployee =
           new BasePlusCommissionEmployee("Bob", "Lewis",
           "444-44-4444", 5000.00M, .04M, 300.00M);

        Console.WriteLine("Employees processed individually:\n");

        Console.WriteLine("{0}\nearned: {1:C}\n",
           salariedEmployee, salariedEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
           hourlyEmployee, hourlyEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
           commissionEmployee, commissionEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
           basePlusCommissionEmployee,
           basePlusCommissionEmployee.Earnings());

        // create four-element Employee array
        Employee[] employees = new Employee[4];

        // initialize array with Employees of derived types
        employees[0] = salariedEmployee;
        employees[1] = hourlyEmployee;
        employees[2] = commissionEmployee;
        employees[3] = basePlusCommissionEmployee;

        Console.WriteLine("Employees processed polymorphically:\n");

        // generically process each element in array employees
        processEmployees(employees);

        // get type name of each object in employees array
        for (int j = 0; j < employees.Length; j++)
            Console.WriteLine("Employee {0} is a {1}", j,
               employees[j].GetType());

        Console.WriteLine("\nEMPLOYEES PROCESSED BY IPAYABLE\n");

        //Create IPayable array
        IPayable[] payableObjects = new IPayable[8];
        payableObjects[0] = new SalariedEmployee(
                "John", "Smith", "111-11-1111", 700M);
        payableObjects[1] = new SalariedEmployee(
                "Antonio", "Smith", "555-55-5555", 800M);
        payableObjects[2] = new SalariedEmployee(
                "Victor", "Smith", "444-44-4444", 600M);
        payableObjects[3] = new HourlyEmployee(
                "Karen", "Price", "222-22-2222", 16.75M, 40M);
        payableObjects[4] = new HourlyEmployee(
                "Ruben", "Zamora", "666-66-6666", 20.00M, 40M);
        payableObjects[5] = new CommissionEmployee(
                "Sue", "Jones", "333-33-3333", 10000M, .06M);
        payableObjects[6] = new BasePlusCommissionEmployee(
                "Bob", "Lewis", "777-77-7777", 5000M, .04M, 300M);
        payableObjects[7] = new BasePlusCommissionEmployee(
                "Lee", "Duarte", "888-88-888", 5000M, .04M, 300M);

        // generically process each element in array employees
        processEmployees(payableObjects);

        //bubble sort and pointer
        Console.WriteLine("\nIPAYABLES SORTED BY SSN:\n");
        BubbleSort(payableObjects, SSNAscending);
        foreach (Employee currentEmployee in payableObjects)
        {
            Console.WriteLine(currentEmployee); // invokes ToString
            Console.WriteLine(
               "earned {0:C}\n", currentEmployee.Earnings());
        } // end foreach

        //IComparer
        Console.WriteLine("\nIPAYABLES SORTED BY LAST NAME ASCENDING\n");
        ArrayList comparerSample = new ArrayList();
        //populate ArrayList for IComparer and IComprable
        foreach (IPayable currentPayable in payableObjects)
        {
            comparerSample.Add(currentPayable);
        }//end foreach
        IComparer lastAscend = new SortLastNAscending();
        comparerSample.Sort(lastAscend);
        foreach (Employee currentEmployee in comparerSample)
        {
            Console.WriteLine(currentEmployee); // invokes ToString
            Console.WriteLine(
               "earned {0:C}\n", currentEmployee.Earnings());
        } // end foreach

        //IComparable implementation
        Console.WriteLine("\nIPAYABLES SORTED BY SALARY DESCEDNING\n");
        comparerSample.Sort();
        foreach (Employee currentEmployee in comparerSample)
        {
            Console.WriteLine(currentEmployee); // invokes ToString
            Console.WriteLine(
               "earned {0:C}\n", currentEmployee.Earnings());
        } // end foreach
    }
Ejemplo n.º 9
0
    public static void Main(string[] args)
    {
        // create derived class objects
        SalariedEmployee salariedEmployee =
            new SalariedEmployee("John", "Smith", "111-11-1111", 800.00M);
        HourlyEmployee hourlyEmployee =
            new HourlyEmployee("Karen", "Price",
                               "222-22-2222", 16.75M, 40.0M);
        CommissionEmployee commissionEmployee =
            new CommissionEmployee("Sue", "Jones",
                                   "333-33-3333", 10000.00M, .06M);
        BasePlusCommissionEmployee basePlusCommissionEmployee =
            new BasePlusCommissionEmployee("Bob", "Lewis",
                                           "444-44-4444", 5000.00M, .04M, 300.00M);
        HourlyShiftEmployee hourlyShiftEmployee1 = new HourlyShiftEmployee("Nick", "Schuler", "111-22-3333", 10.00m, 30, 2);
        HourlyShiftEmployee hourlyShiftEmployee2 = new HourlyShiftEmployee("George", "Of The Jungle", "000-00-0000", 20.00m, 40, 3);

        Console.WriteLine("Employees processed individually:\n");

        Console.WriteLine("{0}\nearned: {1:C}\n",
                          salariedEmployee, salariedEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          hourlyEmployee, hourlyEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          commissionEmployee, commissionEmployee.Earnings());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          basePlusCommissionEmployee,
                          basePlusCommissionEmployee.Earnings());
        Console.WriteLine("{0}\nEarned: {1:C}\n",
                          hourlyShiftEmployee1, hourlyShiftEmployee1.Earnings());
        Console.WriteLine("{0}\nEarned: {1:C}\n", hourlyShiftEmployee2, hourlyShiftEmployee2.Earnings());

        // create four-element Employee array
        Employee[] employees = new Employee[6];

        // initialize array with Employees of derived types
        employees[0]  = salariedEmployee;
        employees[1]  = hourlyEmployee;
        employees[2]  = commissionEmployee;
        employees[3]  = basePlusCommissionEmployee;
        employees [4] = hourlyShiftEmployee1;
        employees [5] = hourlyShiftEmployee2;

        Console.WriteLine("Employees processed polymorphically:\n");

        // generically process each element in array employees
        foreach (Employee currentEmployee in employees)
        {
            Console.WriteLine(currentEmployee); // invokes ToString

            // determine whether element is a BasePlusCommissionEmployee
            if (currentEmployee is BasePlusCommissionEmployee)
            {
                // downcast Employee reference to
                // BasePlusCommissionEmployee reference
                BasePlusCommissionEmployee employee =
                    ( BasePlusCommissionEmployee )currentEmployee;

                employee.BaseSalary *= 1.10M;
                Console.WriteLine(
                    "new base salary with 10% increase is: {0:C}",
                    employee.BaseSalary);
            } // end if

            Console.WriteLine(
                "earned {0:C}\n", currentEmployee.Earnings());
        } // end foreach

        // get type name of each object in employees array
        for (int j = 0; j < employees.Length; j++)
        {
            Console.WriteLine("Employee {0} is a {1}", j,
                              employees[j].GetType());
        }
    } // end Main