Пример #1
0
        static void Main(string[] args)
        {
            //Employee 1
            string   firstName           = "Juan";
            string   lastName            = "Pérez";
            string   phoneNumber         = "664-123-4567";
            decimal  salaryRate          = 50000m;
            int      vacationDays        = 10;
            FullTime newEmployeeFullTime = new FullTime(firstName, lastName, phoneNumber, salaryRate, vacationDays);

            // Employee emo = new Employee(firstName, lastName, phoneNumber);

            //Employee 2
            string   firstName2          = "Pepito";
            string   lastName2           = "Toro";
            string   phoneNumber2        = "123-456-7890";
            decimal  hourlyRate          = 15.00m;
            PartTime newEmployeePartTime = new PartTime(firstName2, lastName2, phoneNumber2, hourlyRate);

            /*Polymorphism*/
            List <Employee> list = new List <Employee>();

            list.Add(newEmployeeFullTime);
            list.Add(newEmployeePartTime);

            foreach (Employee employee in list)
            {
                Console.WriteLine(employee.ToString());
                employee.PayRoll();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var bill = new FullTime
            {
                FirstName = "Bill",
                LastName = "Gates",
                YearsEmployed = 5
            };

            bill.ShowFullName();

            Debug.Assert(bill.ShowFullName() == "Bill Gates");
            Debug.Assert(bill.YearsEmployed == 5);

            var steve = new PartTime
            {
                FirstName = "Steve",
                LastName = "Jobs",
                MonthsEmployed = 2
            };

            Debug.Assert(steve.ShowFullName() == "Steve Jobs");
            Debug.Assert(steve.MonthsEmployed == 2);



        }
Пример #3
0
        static void Main(string[] args)
        {
            //Variables that you wish to pass to your constructors

            //Employee 1
            string  firstName    = "John";
            string  lastName     = "Smith";
            string  phone        = "555-999-5555";
            decimal salary       = 50000M;
            int     vacationDays = 10;
            //Instance of a derviced class using an object creation statement
            FullTime newEmp = new FullTime(firstName, lastName, phone, salary, vacationDays);

            // Employee 2:
            string  firstName2 = "Sara";
            string  lastName2  = "Jones";
            string  phone2     = "656-999-4444";
            decimal rate       = 15.00M;
            //Instance of a derviced class using an object creation statement
            PartTime newPT = new PartTime(firstName2, lastName2, phone2, rate);

            //Polymorphism Example: Write as little code as possible to solve
            // Create loop that looks for base class objects for an employee and return the ToString Objects that are inside
            // List collection

            List <Employee> lists = new List <Employee>();

            lists.Add(newEmp);
            lists.Add(newPT);


            foreach (Employee emp in lists)
            {
                Console.WriteLine(emp.ToString());
                //Call the RUNPAYROLL abstract method polymorphically.
                emp.RunPayroll();
            }

            Console.ReadKey();
        }