public static void main(string[] args) { // create five-element Employee array Employee[] employees = new Employee[4]; // initialize array with Employees employees[0] = new SalariedEmployee("John", "Smith", "111-11-1111", 800M); employees[1] = new HourlyEmployee("Karen", "Price", "222-22-2222", 16.75M, 40M); employees[2] = new CommissionEmployee("Sue", "Jones", "333-33-3333", 10000M, .06M); employees[3] = new BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", 5000M, .04M, 300M); Console.WriteLine("Employees processed polymorphically:\n"); // generically process each element in array employees foreach (var currentEmployee in employees) { Console.WriteLine(currentEmployee); // invokes ToString Console.WriteLine("earned {0:C}\n", currentEmployee.GetPaymentAmount()); } // end foreach Console.Read(); }
public static void Main(string[] args) { IPayable[] payableObjects = new IPayable[7]; payableObjects[0] = new Invoice("01234", "seat", 2, 375.00M ); payableObjects[1] = new Invoice("56789", "tire", 4, 79.95M); payableObjects[ 2 ] = new HourlyEmployee( "John", "Smith", "111-11-1111", 15.75M, 40); payableObjects[ 3 ] = new SalariedEmployee( "Lisa", "Barnes", "888-88-8888", 1200.00M); payableObjects[4] = new CommissionEmployee("Kory", "Barnes", "777-77-7777", 1800.00M, .75M); payableObjects[5] = new BasePlusCommissionEmployee("Grant", "Brick", "555-55-5555", 5000.00M, .5M, 80000.00M); payableObjects[6] = new PieceWorker("Greg", "Jones", "999-99-999", 80.00M, 800.00M); Console.Write( "Invoices and Employees processed polymoprhically:\n"); foreach(var currentPayable in payableObjects) { Console.WriteLine("{0}\npayment due: {1:C}\n", currentPayable, currentPayable.GetPaymentAmount()); } }