Example #1
0
        } // end Main

        /// <summary>
        /// Displays the contents of the IPayable array
        /// </summary>
        /// <param name="payableObjects">Parameter that contains the IPayable array.</param>
        static void displayResult(IPayable[] payableObjects)
        {
            foreach (IPayable currentEmployee in payableObjects)
            {
                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
        }
Example #2
0
        public static void Main(string[] args)
        {
            bool programEnd = false;

            // create derived class objects
            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);

            while (!programEnd)
            {
                Console.WriteLine("1. Sort by last name");
                Console.WriteLine("2. Sort by pay");
                Console.WriteLine("3. Sort by social security number");
                Console.WriteLine("4. Exit the program");

                Console.Write("Please select an option from the Employee menu: ");
                int input = Convert.ToInt16(Console.ReadLine());
                Console.WriteLine();

                if (input == 1)
                {
                    Array.Sort(payableObjects);
                    Console.WriteLine("\nEmployees sorted by last name: ");
                    displayResult(payableObjects);
                }

                else if (input == 2)
                {
                    Array.Sort(payableObjects, Employee.sortByPay.sortPayAscending());
                    Console.WriteLine("\nEmployees sorted by pay: ");
                    displayResult(payableObjects);
                }

                else if (input == 3)
                {
                    selectionSort(payableObjects, SSN_Comparision);
                    Console.WriteLine("\nEmployees sorted by SSN: ");
                    displayResult(payableObjects);
                }

                else if (input == 4)
                {
                    Console.WriteLine("Thank you for using the program! Exiting.....");
                    programEnd = true;
                }

                else
                {
                    Console.WriteLine("Invalid input. Please enter a valid option from the menu.");
                }
            }

            Console.Read();
        } // end Main