public static void Main(string[] args)
    {
        // instantiate BasePlusCommissionEmployee object
        BasePlusCommissionEmployee basePlusCommissionEmployee =
            new BasePlusCommissionEmployee("Bob", "Lewis",
                                           "333-33-3333", 5000.00M, .04M, 300.00M);

        // display BasePlusCommissionEmployee's data
        Console.WriteLine(
            "Employee information obtained by properties and methods: \n");
        Console.WriteLine("First name is {0}",
                          basePlusCommissionEmployee.FirstName);
        Console.WriteLine("Last name is {0}",
                          basePlusCommissionEmployee.LastName);
        Console.WriteLine("Social security number is {0}",
                          basePlusCommissionEmployee.SocialSecurityNumber);
        Console.WriteLine("Gross sales are {0:C}",
                          basePlusCommissionEmployee.GrossSales);
        Console.WriteLine("Commission rate is {0:F2}",
                          basePlusCommissionEmployee.CommissionRate);
        Console.WriteLine("Earnings are {0:C}",
                          basePlusCommissionEmployee.Earnings());
        Console.WriteLine("Base salary is {0:C}",
                          basePlusCommissionEmployee.BaseSalary);

        basePlusCommissionEmployee.BaseSalary = 1000.00M; // set base salary

        Console.WriteLine("\n{0}:\n\n{1}",
                          "Updated employee information obtained by ToString",
                          basePlusCommissionEmployee);
        Console.WriteLine("Earnings: {0:C}",
                          basePlusCommissionEmployee.Earnings());
    } // end Main
Example #2
0
    static void Main()
    {
        // instantiate BasePlusCommissionEmployee object
        var employee = new BasePlusCommissionEmployee("Bob", "Lewis",
                                                      "333-33-3333", 5000.00M, .04M, 300.00M);

        // display BasePlusCommissionEmployee's data
        Console.WriteLine(
            "Employee information obtained by properties and methods: \n");
        Console.WriteLine($"First name is {employee.FirstName}");
        Console.WriteLine($"Last name is {employee.LastName}");
        Console.WriteLine(
            $"Social security number is {employee.SocialSecurityNumber}");
        Console.WriteLine($"Gross sales are {employee.GrossSales:C}");
        Console.WriteLine(
            $"Commission rate is {employee.CommissionRate:F2}");
        Console.WriteLine($"Earnings are {employee.Earnings():C}");
        Console.WriteLine($"Base salary is {employee.BaseSalary:C}");

        employee.BaseSalary = 1000.00M; // set base salary

        Console.WriteLine(
            "\nUpdated employee information obtained by ToString:\n");
        Console.WriteLine(employee);
        Console.WriteLine($"earnings: {employee.Earnings():C}");
    }
    public static void Main( string[] args )
    {
        // instantiate BasePlusCommissionEmployee object
          BasePlusCommissionEmployee basePlusCommissionEmployee =
         new BasePlusCommissionEmployee( "Bob", "Lewis",
         "333-33-3333", 5000.00M, .04M, 300.00M );

          // display BasePlusCommissionEmployee's data
          Console.WriteLine(
         "Employee information obtained by properties and methods: \n" );
          Console.WriteLine( "First name is {0}",
         basePlusCommissionEmployee.FirstName );
          Console.WriteLine( "Last name is {0}",
         basePlusCommissionEmployee.LastName );
          Console.WriteLine( "Social security number is {0}",
         basePlusCommissionEmployee.SocialSecurityNumber );
          Console.WriteLine( "Gross sales are {0:C}",
         basePlusCommissionEmployee.GrossSales );
          Console.WriteLine( "Commission rate is {0:F2}",
         basePlusCommissionEmployee.CommissionRate );
          Console.WriteLine( "Earnings are {0:C}",
         basePlusCommissionEmployee.Earnings() );
          Console.WriteLine( "Base salary is {0:C}",
         basePlusCommissionEmployee.BaseSalary );

          basePlusCommissionEmployee.BaseSalary = 1000.00M; // set base salary

          Console.WriteLine( "\n{0}:\n\n{1}",
         "Updated employee information obtained by ToString",
         basePlusCommissionEmployee );
          Console.WriteLine( "earnings: {0:C}",
         basePlusCommissionEmployee.Earnings() );
    }
Example #4
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()}");
        }
    }
Example #5
0
    public static void Main(string[] args)
    {
        BasePlusCommissionEmployee employee = new BasePlusCommissionEmployee("Bob", "Lewis", "333-33-3333", 5000.00M, .04M, 300.00M);

        Console.WriteLine("Employee information obtained by properties and methods: \n");
        Console.WriteLine("{0} {1}", "First name is", employee.FirstName);
        Console.WriteLine("{0} {1}", "Last name is", employee.LastName);
        Console.WriteLine("{0} {1}", "Social security number is", employee.SocialSecurityNumber);
        Console.WriteLine("{0} {1:C}", "Gross sales are", employee.GrossSales);
        Console.WriteLine("{0} {1:C}", "Commission rate is", employee.CommissionRate);
        Console.WriteLine("{0} {1:C}", "Earnings are", employee.Earnings());
        Console.WriteLine("{0} {1:C}", "Base salary is", employee.BaseSalary);

        employee.BaseSalary = 1000.00M;

        Console.WriteLine("\n{0}:\n\n{1}", "Updated employee information obtained ToString", employee);
        Console.Write("earnings: {0:C}", employee.Earnings());
        Console.ReadKey();
    }
Example #6
0
        public void Earnings()
        {
            BasePlusCommissionEmployee myEmp =
                new BasePlusCommissionEmployee("AAA", "BB", "123", 540.00M, 0.3M, 30000.0M);

            decimal expValue = 30162.0M;

            // NUnit
            Assert.AreEqual(expValue, myEmp.Earnings());
        }
Example #7
0
 //Show the parameters to the user
 public static void DisplayResults(BasePlusCommissionEmployee employee)
 {
     Console.WriteLine("\t First Name: " + employee.Commission1.FirstName);
     Console.WriteLine("\t Last Name: " + employee.Commission1.LastName);
     Console.WriteLine("\t Social Security: " + employee.Commission1.SocialSecurityNumber);
     Console.WriteLine("\t Gross Sales: " + employee.Commission1.GrossSales);
     Console.WriteLine("\t Commission Rate: " + employee.Commission1.CommissionRate);
     Console.WriteLine("\t Base Salary: " + employee.BaseSalary);
     Console.WriteLine("\t Earnings: " + employee.Earnings());
     Console.WriteLine();
 }
    public static void Main()
    {
        BasePlusCommissionEmployee employee = new BasePlusCommissionEmployee("Nordine", "Sebkhi", "999-99-9999", 5000.00M, 0.06M, 300.00M);

        Console.WriteLine("Employee info obtained by properties and methods: \n");
        Console.WriteLine("{0} {1}", "First name is", employee.FirstName);
        Console.WriteLine("{0} {1}", "Last name is", employee.LastName);
        Console.WriteLine("{0} {1}", "SSN is", employee.SocialSecurityNumber);
        Console.WriteLine("{0} {1:C}", "Gross sale is", employee.GrossSales);
        Console.WriteLine("{0} {1:F2}", "Commission rate is", employee.CommissionRate);
        Console.WriteLine("{0} {1:C}", "Earnings are", employee.Earnings());
        Console.WriteLine("{0} {1:C}", "Base salary is", employee.BaseSalary);

        employee.BaseSalary = 100.00M;

        Console.WriteLine("\n{0}:\n\n{1}", "Updated employee info obtained by ToString", employee);
        Console.WriteLine("Earnings: {0:C}", employee.Earnings());

        Console.ReadLine();
    } // end class Main
    static void Main()
    {
        Console.WriteLine("(02) Empleado por Comision + Sueldo Base\n");

        var employee = new BasePlusCommissionEmployee("Bob", "Lewis",
                                                      "333-33-3333", 5000.00M, .04M, 300.00M);

        Console.WriteLine("Informacion del Empleado obtenido por Propiedades y Metodos: \n");
        Console.WriteLine("Nombre                       : " + employee.FirstName);
        Console.WriteLine("Apellido                     : " + employee.LastName);
        Console.WriteLine("Numero de Seguro Social      : " + employee.SocialSecurityNumber);
        Console.WriteLine("Ventas Brutas                : " + employee.GrossSales);
        Console.WriteLine("Porcentaje de Comision       : " + employee.CommissionRate);
        Console.WriteLine("Ganancias                    : " + employee.Earnings());
        Console.WriteLine("Salario Base                 : " + employee.BaseSalary);

        employee.BaseSalary = 1000.00M; // Se actualiza el salario base

        Console.WriteLine("\nInformacion actualizada obtenida por ToString:\n");
        Console.WriteLine(employee);
        Console.WriteLine("Ganancias                    : " + employee.Earnings() + "\n");
    }
Example #10
0
    static void Main()
    {
        // assign base-class reference to base-class variable
        var commissionEmployee = new CommissionEmployee(
            "Sue", "Jones", "222-22-2222", 10000.00M, .06M);

        // assign derived-class reference to derived-class variable
        var basePlusCommissionEmployee = new BasePlusCommissionEmployee(
            "Bob", "Lewis", "333-33-3333", 5000.00M, .04M, 300.00M);

        // invoke ToString and Earnings on base-class object
        // using base-class variable
        Console.WriteLine(
            "Call CommissionEmployee's ToString and Earnings methods " +
            "with base-class reference to base class object\n");
        Console.WriteLine(commissionEmployee.ToString());
        Console.WriteLine($"earnings: {commissionEmployee.Earnings()}\n");

        // invoke ToString and Earnings on derived-class object
        // using derived-class variable
        Console.WriteLine("Call BasePlusCommissionEmployee's ToString and" +
                          " Earnings methods with derived class reference to" +
                          " derived-class object\n");
        Console.WriteLine(basePlusCommissionEmployee.ToString());
        Console.WriteLine(
            $"earnings: {basePlusCommissionEmployee.Earnings()}\n");

        // invoke ToString and Earnings on derived-class object
        // using base-class variable
        CommissionEmployee commissionEmployee2 = basePlusCommissionEmployee;

        Console.WriteLine(
            "Call BasePlusCommissionEmployee's ToString and Earnings " +
            "methods with base class reference to derived-class object\n");
        Console.WriteLine(commissionEmployee2.ToString());
        Console.WriteLine(
            $"earnings: {basePlusCommissionEmployee.Earnings()}\n");
    }
Example #11
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());
            }
        }
Example #12
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();
        }
Example #13
0
    public static void Main(string[] args)
    {
        // assign base class reference to base class variable
        CommissionEmployee commissionEmployee = new CommissionEmployee(
            "Sue", "Jones", "222-22-2222", 10000.00M, .06M);

        // assign derived class reference to derived class variable
        BasePlusCommissionEmployee basePlusCommissionEmployee =
            new BasePlusCommissionEmployee("Bob", "Lewis",
                                           "333-33-3333", 5000.00M, .04M, 300.00M);

        // invoke ToString and Earnings on base class object
        // using base class variable
        Console.WriteLine("{0} {1}:\n\n{2}\n{3}: {4:C}\n",
                          "Call CommissionEmployee's ToString and Earnings methods",
                          "with base class reference to base class object",
                          commissionEmployee.ToString(),
                          "Earnings", commissionEmployee.Earnings());

        // invoke ToString and Earnings on derived class object
        // using derived class variable
        Console.WriteLine("{0} {1}:\n\n{2}\n{3}: {4:C}\n",
                          "Call BasePlusCommissionEmployee's ToString and Earnings",
                          "methods with derived class reference to derived class object",
                          basePlusCommissionEmployee.ToString(),
                          "Earnings", basePlusCommissionEmployee.Earnings());

        // invoke ToString and Earnings on derived class object
        // using base class variable
        CommissionEmployee commissionEmployee2 =
            basePlusCommissionEmployee;

        Console.WriteLine("{0} {1}:\n\n{2}\n{3}: {4:C}",
                          "Call BasePlusCommissionEmployee's ToString and Earnings",
                          "methods with base class reference to derived class object",
                          commissionEmployee2.ToString(), "Earnings",
                          commissionEmployee2.Earnings());
    } // 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
    }
Example #15
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();
    }
Example #16
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
Example #18
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