示例#1
0
    public static void Main( string[] args )
    {
        // instantiate CommissionEmployee object
          CommissionEmployee employee = new CommissionEmployee( "Sue",
         "Jones", "222-22-2222", 10000.00M, .06M );

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

          employee.GrossSales = 5000.00M; // set gross sales
          employee.CommissionRate = .1M; // set commission rate

          Console.WriteLine( "\n{0}:\n\n{1}",
         "Updated employee information obtained by ToString", employee );
          Console.WriteLine( "earnings: {0:C}", employee.Earnings() );
    }
示例#2
0
    public static void Main( string[] args )
    {
        // create five-element Employee array
          Employee[] employees = new Employee[ 5 ];

          // 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 );
          employees[4] = new PieceWorker("Tony", "Rosella", "555-55-5555", 15.50M, 20M);

           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.Earnings() );
          } // end foreach
    }
 public static void Main()
 {
     Employee clerk = new Employee();
       CommissionEmployee salesperson = new CommissionEmployee();
       clerk.EmpNum = 234;
       salesperson.EmpNum = 345;
       DisplayGreeting(clerk);
       DisplayGreeting(salesperson);
 }
 //Constructor
 public PayrollSystemTest()
 {
     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);
 }
 public static void Main()
 {
     CommissionEmployee salesperson = new CommissionEmployee();
       salesperson.EmpNum = 345;
       salesperson.EmpSal = 20000;
       salesperson.CommissionRate = 0.07;
       Console.WriteLine("Salesperson #{0} makes {1} per year",
      salesperson.EmpNum,
      salesperson.EmpSal.ToString("C"));
       Console.WriteLine("...plus {0} commission on all sales",
      salesperson.CommissionRate.ToString("P"));
 }
示例#6
0
        static void Main(string[] args)
        {
            //toast er gud udhsaoiudjiuashdoias
            Console.WriteLine("Hourley:");
            Console.Writeline("Kagemand 45");
            HourlyEmployee mads = new HourlyEmployee("Mads", "Rasmussen", 10, 100M);
            HourlyEmployee emil = new HourlyEmployee("Emil", "Cordsen", 168, 200000);
            HourlyEmployee jack = new HourlyEmployee("jack", "Thomsen", 127, 20000);

            Console.WriteLine(mads.ToString() + "\n");

            Console.WriteLine(emil.ToString() + "\n");

            Console.WriteLine(jack.ToString() + "\n");

            Console.WriteLine("Fixed:");
            FixedEmployee morten = new FixedEmployee("Morten", "Hejn", 1000);
            FixedEmployee daniel = new FixedEmployee("Daniel", "Giversen", 20000);
            FixedEmployee emil2  = new FixedEmployee("Emil", "Cordsen", 200000);

            Console.WriteLine(morten.ToString() + "\n");

            Console.WriteLine(daniel.ToString() + "\n");

            Console.WriteLine(emil2.ToString() + "\n");



            Console.WriteLine("Commision:");
            CommissionEmployee jens  = new CommissionEmployee("Jens", "Clausen", 200, 0.05);
            CommissionEmployee mads2 = new CommissionEmployee("Mads", "Andersen", 400, 0.10);
            CommissionEmployee emil3 = new CommissionEmployee("Emil", "Cordsen", 999, 120);

            Console.WriteLine(jens.ToString() + "\n");

            Console.WriteLine(mads2.ToString() + "\n");

            Console.WriteLine(emil3.ToString() + "\n");

            Console.WriteLine("CommisionAndBasic:");
            BasicAndCommissionEmployee jens2 = new BasicAndCommissionEmployee("Jens", "Clausen", 200, 0.05, 200);
            BasicAndCommissionEmployee mads3 = new BasicAndCommissionEmployee("Mads", "Andersen", 400, 0.10, 400);
            BasicAndCommissionEmployee emil4 = new BasicAndCommissionEmployee("Emil", "Cordsen", 999, 120, 800);

            Console.WriteLine(jens2.ToString() + "\n");

            Console.WriteLine(mads3.ToString() + "\n");

            Console.WriteLine(emil4.ToString() + "\n");

            Console.ReadKey();
        }
    static void Main()
    {
        CommissionEmployee salesperson = new CommissionEmployee();

        salesperson.EmpNum         = 345;
        salesperson.EmpSal         = 20000;
        salesperson.CommissionRate = 0.07;
        Console.WriteLine("Salesperson #{0} makes {1} per year",
                          salesperson.EmpNum,
                          salesperson.EmpSal.ToString("C"));
        Console.WriteLine("...plus {0} commission on all sales",
                          salesperson.CommissionRate.ToString("P"));
    }
示例#8
0
        static void Main(string[] args)
        {
            SalariedEmployee           salariedEmployee           = new SalariedEmployee("Peter", "Parker", "SPIDER001", 10.0M);
            HourlyEmployee             hourlyEmployee             = new HourlyEmployee("Bruce", "Wayne", "BAT001", 15.0M, 45);
            CommissionEmployee         commissionEmployee         = new CommissionEmployee("David", "Banner", "HULK001");
            BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee("Clark", "Kent", "SUPER001");



            Console.WriteLine(hourlyEmployee.ToString());
            Console.WriteLine(salariedEmployee.ToString());
            Console.WriteLine(commissionEmployee.ToString());
            Console.WriteLine(basePlusCommissionEmployee.ToString());
        }
        public void WhenRateNotSpecified_ThrowsException()
        {
            // Arrange

            Action action = () => CommissionEmployee.CreateNew(
                new EmployeeId("foo"),
                new Name("bar", null, "boo", null, null),
                new FakeAddress(new FakeName(), "l1", "city", "country"),
                null,
                new Money(new FakeCurrency(), new MoneyValue(100000m)));

            // Act & Assert

            action.Should().Throw <EmployeeDomainException>().WithMessage("Commission rate must not be null.");
        }
示例#10
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());
            }
        }
示例#11
0
    public static void Main( string [] args)
    {
        bool loop = true;
            while(loop == true)
            {
                Console.WriteLine("Welcome to Employee Builder: ");
                Console.Read();

                //instantiate Employee Array
                Employee[] Employees = new Employee[5];

                //fill array with different 'Employee' Derived Types all functioning under their own version of the 'Employee' Methods.
                Employees[0] = new BasePlusCommissionEmployee("Jerry", "Redmond", "000-00-0000", 500.00M, .8M, 700M);
                Employees[1] = new CommissionEmployee("Carlos", "Reese", "111-11-1111", 999.00M, .45M);
                Employees[2] = new HourlyEmployee("Mike", "Luongo", "222-22-2222", 15.00M, 45M);
                Employees[3] = new PieceWorker("Marcus", "Shepherd", "333-33-3333", 3.50M, 100M);
                Employees[4] = new SalariedEmployee("Larry", "Peters", "444-44-4444", 75000M);
                //Employees[5] = new PieceWorker("Hakeem", "Rogers", "555-55-5555", 5.0M,1);

                Console.WriteLine("Employees Earnings & System Signature through ToString: \n\n{0}\t\t{1}", "Earnings:", "String:");

                foreach(Employee employee in Employees)
                {
                    Console.WriteLine( employee.GetPaymentAmount() );
                }//end foreach

                for (int i = 0; i <= 4; i++)
                {

                    if (Employees[i].GetType is BasePlusCommissionEmployee)
                    {
                        BasePlusCommissionEmployee employee =
                            (BasePlusCommissionEmployee)Employees[i];

                            employee.BaseSalary =  employee.BaseSalary * 1.1M;

                    }//end if

                    Console.WriteLine("\n" + Employees[i].GetPaymentAmount() /* + "\t\t" + Employees[i].Earnings() + Employees[i].*/);
                }//end for statement printing GetPaymentAmount

                Console.ReadLine();

            }//End while
    }
示例#12
0
        public void EmployeeDerivedClassesTest()
        {
            // Arrange:
            CommissionEmployee c1 = new CommissionEmployee(5, 10000, 50000, "mads", "lol");
            HourlyEmployee     h1 = new HourlyEmployee(300, 200, "mads", "sam");
            double             expectedMonthlyIncomec1 = 50500;
            double             expectedMonthlyIncomeh1 = 60000;
            double             actualMonthlyIncomec1;
            double             actualMonthlyIncomeh1;

            // Act:
            actualMonthlyIncomec1 = c1.MonthlyIncome;
            actualMonthlyIncomeh1 = h1.MonthlyIncome;

            // Assert:
            Assert.AreEqual(expectedMonthlyIncomec1, actualMonthlyIncomec1);
            Assert.AreEqual(expectedMonthlyIncomeh1, actualMonthlyIncomeh1);
        }
示例#13
0
    public static void Main(string[] args)
    {
        SalariedEmployee salariedEmployee =
            new SalariedEmployee("Daniel", "Oszczapinski", "123-12-1234", 200M);
        HourlyEmployee hourlyEmployee =
            new HourlyEmployee("Stan", "live", "000-00-0000", 10M, 13M);
        CommissionEmployee commissionEmployee =
            new CommissionEmployee("lane", "peter", "112-12-1122", 100M, .1M);
        BaseCommissionEmployee baseCommissionEmployee =
            new BaseCommissionEmployee("Jane", "Dove", "133-33-4433", 20M, .2M, 40M);

        Employee[] employeses = new Employee[4];

        Employee[0] = salariedEmployee;
        Employee[1] = hourlyEmployee;
        Employee[2] = commissionEmployee;
        Employee[3] = baseCommissionEmployee;
    }
示例#14
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);
            var pieceWorkEmployee = new PieceWorkEmployee("Penny", "Parker",
                                                          "555-55-5555", 1.75M, 600);

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

            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");
            }
        }
    public static void Main(string[] args)
    {
        CommissionEmployee employee = new CommissionEmployee("Sue", "Jones", "222-22-222", 10000.00M, .06M);

        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}", "Gross sales are", employee.GrossSales);
        Console.WriteLine("{0} {1}", "Commission rate is", employee.CommissionRate);
        Console.WriteLine("{0} {1}", "Earnings are", employee.Earnings());

        employee.GrossSales     = 5000.00M;
        employee.CommissionRate = .1M;

        Console.WriteLine("\n{0}:\n\n{1}", "Updated employee information obtained by ToString", employee);
        Console.WriteLine("earnings: {0:C}", employee.Earnings());
        Console.ReadKey();
    }
        public void CreateNew_CreatesCommissionEmployee()
        {
            // Arrange
            EmployeeId     employeeId = new EmployeeId("foo");
            Name           name       = new Name("fee", null, "fo", null, null);
            FakeAddress    address    = new FakeAddress(new FakeName(), "l1", "city", "country");
            CommissionRate rate       = new CommissionRate(new CommissionRateValue(0.03m));
            Money          salary     = new Money(new FakeCurrency(), new MoneyValue(100000m));

            // Act
            var employee = CommissionEmployee.CreateNew(employeeId, name, address, rate, salary);

            // Assert
            employee.EmployeeId.Should().Be(employeeId);
            employee.Name.Should().Be(name);
            employee.Address.Should().Be(address);
            employee.Rate.Should().Be(rate);
            employee.Salary.Should().Be(salary);
        }
    public static void Main(string[] args)
    {
        // create six-element IPayable array
          IPayable[] payableObjects = new IPayable[6];

          // populate array with objects that implement IPayable
          payableObjects[0] = new Invoice("01234", "seat", 2, 375.00M);
          payableObjects[1] = new Invoice("56789", "tire", 4, 79.95M);
          payableObjects[2] = new SalariedEmployee("John", "Smith",
         "111-11-1111", 800.00M);

          /***** Modified code for assignment *****/

          // Add three new payable objects
          payableObjects[3] = new HourlyEmployee("Robert", "Millsaps", "222-22-2222", 12.5M, 20M);
          payableObjects[4] = new CommissionEmployee("Albert", "Einstein", "333-33-3333", 1000M, 0.314159M);
          payableObjects[5] = new BasePlusCommissionEmployee("Bill", "Gates", "444-44-4444", 1000M, 0.314159M, 1000000M);

          // Iterate over all payable objects
          foreach (IPayable currentPayable in payableObjects)
          {
         // Output string representation
         Console.WriteLine(currentPayable);

         // Increase base salary by 10% for Base Plus Commission Employee
         if (currentPayable is BasePlusCommissionEmployee)
         {
            BasePlusCommissionEmployee employee = (BasePlusCommissionEmployee)currentPayable;
            employee.BaseSalary *= 1.10M;
            // Output new base salary
            Console.WriteLine("new base salary with 10% increase is: {0:C}", employee.BaseSalary);
         }

         // Output payment for each payable object
         Console.WriteLine("payment due: {0:C}", currentPayable.GetPaymentAmount());
         Console.WriteLine();
          }

          // Freeze console window
          Console.ReadLine();

          /***** End Modified code for assignment *****/
    }
        static void Main()
        {
            Employee           clerk       = new Employee();
            CommissionEmployee salesperson = new CommissionEmployee();

            clerk.EmpNum               = 123;
            clerk.EmpSal               = 30000.00;
            salesperson.EmpNum         = 234;
            salesperson.EmpSal         = 20000;
            salesperson.CommissionRate = 0.07;
            Console.WriteLine("\n" + clerk.GetGreeting());
            Console.WriteLine("Clerk #{0} salary: {1} per year", clerk.EmpNum, clerk.EmpSal.ToString("C"));
            Console.WriteLine("\n" + salesperson.GetGreeting());
            Console.WriteLine("Salesperson #{0} salary: {1} per year", salesperson.EmpNum, salesperson.EmpSal.ToString("C"));
            Console.WriteLine("...plus {0} comission on all sales", salesperson.CommissionRate.ToString("P"));
            //  CommissionEmployee salesperson = new CommissionEmployee();
            salesperson.EmpNum = 345;
            Console.WriteLine(salesperson.GetGreeting());
            Console.ReadLine();
        }
示例#19
0
 public static void Main()
 {
     Employee clerk = new Employee();
       CommissionEmployee salesperson = new CommissionEmployee();
       clerk.EmpNum = 123;
       clerk.EmpSal = 30000.00;
       salesperson.EmpNum = 234;
       salesperson.EmpSal = 20000;
       salesperson.CommissionRate = 0.07;
       Console.WriteLine("\n" + clerk.GetGreeting());
       Console.WriteLine("Clerk #{0} salary: {1} per year",
      clerk.EmpNum,
      clerk.EmpSal.ToString("C"));
       Console.WriteLine("\n" + salesperson.GetGreeting());
       Console.WriteLine("Salesperson #{0} salary: {1} per year",
      salesperson.EmpNum,
      salesperson.EmpSal.ToString("C"));
       Console.WriteLine("...plus {0} commission on all sales",
      salesperson.CommissionRate.ToString("P"));
 }
示例#20
0
        void InitGrid()
        {
            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);

            payableObjects[8]  = new SalariedEmployee("John", "Smith", "111-11-1111", 700M);
            payableObjects[9]  = new SalariedEmployee("Antonio", "Smith", "555-55-5555", 800M);
            payableObjects[10] = new SalariedEmployee("Victor", "Smith", "444-44-4444", 600M);
            payableObjects[11] = new HourlyEmployee("Karen", "Price", "222-22-2222", 16.75M, 40M);
            payableObjects[12] = new HourlyEmployee("Ruben", "Zamora", "666-66-6666", 20.00M, 40M);
            payableObjects[13] = new CommissionEmployee("Sue", "Jones", "333-33-3333", 10000M, .06M);
            payableObjects[14] = new BasePlusCommissionEmployee("Bob", "Lewis", "777-77-7777", 5000M, .04M, 300M);
            payableObjects[15] = new BasePlusCommissionEmployee("Lee", "Duarte", "888-88-888", 5000M, .04M, 300M);
        }
示例#21
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();
        }
    public static void Main(string[] args)
    {
        // create derived class objects
        SalariedEmployee salariedEmployee1 =
            new SalariedEmployee("John", "Smith", "111-11-1111", 800.00M);
        HourlyEmployee hourlyEmployee1 =
            new HourlyEmployee("Karen", "Price", "222-22-2222", 16.75M, 40);
        SalariedEmployee salariedEmployee2 =
            new SalariedEmployee("Sue", "Jones", "333-33-3333", 1000.00M);
        HourlyEmployee hourlyEmployee2 =
            new HourlyEmployee("Bob", "Lewis", "444-44-4444", 50.00M, 45);

        // Create 2 CommissionEmployee objects here
        CommissionEmployee commissionEmployee1 =
            new CommissionEmployee("Max", "Rain", "555-55-5555", 400m, 0.8m);
        CommissionEmployee commissionEmployee2 =
            new CommissionEmployee("Alaa", "Bob", "666-66-6666", 6600m, 0.6m);

        // Change to 6 to hold 2 new CommissionEmployee objects
        Employee[] employees = new Employee[6];

        // initialize array with Employees of derived types
        employees[0] = salariedEmployee1;
        employees[1] = hourlyEmployee1;
        employees[2] = salariedEmployee2;
        employees[3] = hourlyEmployee2;
        employees[4] = commissionEmployee1;
        employees[5] = commissionEmployee2;
        // Add 2 CommissionEmployee objects to array here

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

        // generically process each element in array employees
        foreach (Employee currentEmployee in employees)
        {
            Console.WriteLine(currentEmployee); // invokes ToString implicitly
            Console.WriteLine("earned " + currentEmployee.CalcEarnings().ToString("C"));
            Console.WriteLine();
        } // end foreach
    }     // end Main
示例#23
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);
        var pieceWorkerEmployee =
            new PieceWorkerEmployee("Spencer", "Dee", "111-11-1111"
                                    , 300M, 5000.000M);

        new PieceWorkerEmployee("Andrew", "Wright", "222-22-2222", 400M, 3000M);

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

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

        // generically process each element in employees
        foreach (var currentEmployee in employees)
        {
            WriteLine(currentEmployee); // invokes ToString
            WriteLine($"earned: {currentEmployee.Earnings():C}\n");
        }

        // get type name of each object in employees
        for (int j = 0; j < employees.Count; j++)
        {
            WriteLine($"Employee {j} is a {employees[j].GetType()}");
        }
    }
示例#24
0
    static void Main()
    {
        Console.WriteLine("(01) Empleado por Comision\n");

        var employee = new CommissionEmployee("Sue", "Jones",
                                              "222-22-2222", 1000.00M, .06M);

        Console.WriteLine("Informacion del empleado obtenida por las propiedades y metodos: \n");
        Console.WriteLine("Nombre                  : {0}", employee.FirstName);
        Console.WriteLine("Apellido                : {0}", employee.LastName);
        Console.WriteLine("Numero de Seguro Social : {0}", employee.SocialSecurityNumber);
        Console.WriteLine("Ventas Brutas           : {0}", employee.GrossSales);
        Console.WriteLine("Porcentaje de Comision  : {0}", employee.CommissionRate);
        Console.WriteLine("Ganancias               : {0}", employee.Earnings());

        employee.GrossSales     = 5000.00M; // Se actualiza las ventas brutas del empleado
        employee.CommissionRate = .1M;      // Se actualiza el porcentaje de comision del empleado

        Console.WriteLine("\n" + "Informacion actualizada obtenida por :" + "\n" + employee.ToString() + "\n");
        Console.WriteLine(employee);
        Console.WriteLine("Ganancias               : {0}\n", employee.Earnings());
    }
示例#25
0
        static void Main(string[] args)
        {
            Console.WriteLine("Payroll....");
            //Employee ee = new Employee("Bruce", "Wayne", "BAT001");
            //Console.WriteLine(ee);

            HourlyEmployee he = new HourlyEmployee("Diana", "Ross", "WW001");

            Console.WriteLine(he);

            CommissionEmployee ce = new CommissionEmployee("Peter", "Parker", "SPIDER001");

            Console.WriteLine(ce);

            SalariedEmployee se = new SalariedEmployee("Bruce", "Banner", "HULK001");

            Console.WriteLine(se);

            BasePlusCommissionEmployee bce = new BasePlusCommissionEmployee("Tony", "Stark", "IRON001");

            Console.WriteLine(bce);
        }
    public static void Main(string [] args)
    {
        // create four-element IPayable array
        IPayable[] payableObjects = new IPayable[6];

        // populate array with objects that implement IPayable
        payableObjects[0] = new Invoice("01234", "seat", 2, 375.00M);
        payableObjects[1] = new Invoice("56789", "tire", 4, 79.95M);
        payableObjects[2] = new SalariedEmployee("John", "Smith", "111-11-1111", 800.00M);
        payableObjects[3] = new HourlyEmployee("Bob", "Bobson", "222-22-2222", 16.75M, 40M );
        payableObjects[4] = new CommissionEmployee("Sally", "Seashore", "333-33-3333", 10000M, .06M );
        payableObjects[5] = new BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", 5000M, .04M, 300M, .1M);

        Console.WriteLine("Invoices and Employees process polymorphically:\n");

        // generically process each element in array payableObjects
        foreach (var currentPayable in payableObjects)
        {
            // output currentPayable and its appropriate payment amount
            Console.WriteLine("{0}\npayment due: {1:C}\n", currentPayable, currentPayable.GetPaymentAmount());
        } // end foreach
    }
示例#27
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");
    }
示例#28
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
示例#29
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Payroll......");

            //Employee ee = new Employee("Bruce", "Wayne", "BAT001");
            //Console.WriteLine(ee.ToString());

            HourlyEmployee he = new HourlyEmployee("Diane", "Carter", "WW001");

            Console.WriteLine(he.ToString());

            SalariedEmployee se = new SalariedEmployee("Barry", "Allen", "FLASH001");

            Console.WriteLine(se.ToString());

            CommissionEmployee ce = new CommissionEmployee("Peter", "Parker", "SPIDER001");

            Console.WriteLine(ce.ToString());

            BasePlusCommissionEmployee bce = new BasePlusCommissionEmployee("Clark", "Kent", "SUPER001");

            Console.WriteLine(bce.ToString());
        }
        public void CommissionEmployees_WhenEqual_HaveSameHashCode()
        {
            // Arrange
            var employee1 = CommissionEmployee.CreateNew(
                new EmployeeId("foo"),
                new Name("f", null, "l", null, null),
                new FakeAddress(),
                new CommissionRate(new CommissionRateValue(0.05m)),
                new Money(new FakeCurrency(), new MoneyValue(100000m)));

            var employee2 = CommissionEmployee.CreateNew(
                new EmployeeId("foo"),
                new Name("f", null, "l", null, null),
                new FakeAddress(),
                new CommissionRate(new CommissionRateValue(0.05m)),
                new Money(new FakeCurrency(), new MoneyValue(100000m)));

            // Act
            var hashCodesEqual = employee1.GetHashCode() == employee2.GetHashCode();

            // Assert
            hashCodesEqual.Should().BeTrue();
        }
        public void CommissionEmployees_AreNotEqual()
        {
            // Arrange
            var employee1 = CommissionEmployee.CreateNew(
                new EmployeeId("foo"),
                new Name("f", null, "l", null, null),
                new FakeAddress(),
                new CommissionRate(new CommissionRateValue(0.05m)),
                new Money(new FakeCurrency(), new MoneyValue(100000m)));

            var employee2 = CommissionEmployee.CreateNew(
                new EmployeeId("foo"),
                new Name("f", null, "l", null, null),
                new FakeAddress(),
                new CommissionRate(new CommissionRateValue(0.10m)),
                new Money(new FakeCurrency(), new MoneyValue(100000m)));

            // Act
            var areEqual = employee1 == employee2;

            // Assert
            areEqual.Should().BeFalse();
        }
示例#32
0
    static void Main()
    {
        var date1 = new Date(7, 15, 1979);
        var date2 = new Date(12, 29, 1980);
        var date3 = new Date(3, 28, 2009);
        var date4 = new Date(1, 14, 2014);
        var now   = DateTime.Now;

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

        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}");
            }

            if (currentEmployee.Birthdate.Month == now.Month)
            {
                Console.WriteLine("Birthday bonus: $100.00");
                Console.WriteLine($"earned: {currentEmployee.Earnings() + 100:C}\n");
            }
            else
            {
                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()}");
        }
    }
    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);
        var pieceWorker = new PieceWorker("MainuL", "Haque", "123-11-1234", 10.05M, 525);

        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}\n");

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

        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()}");
        }
    }
示例#34
0
        public static void Main(string[] args)
        {
            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);
             /*
             Console.WriteLine("Not sorted in any way yet \n");

             for (int j = 0; j < payableObjects.Length; j++) {
            Console.WriteLine("Employee new {0} is a {1}", j,
               payableObjects[j]);
             }
             */
             foreach (IPayable p in payableObjects) {
            Console.WriteLine(p + "\n");
             }
             string menuOption;
             bool menuLogic = true;

             while (menuLogic) {
            Console.WriteLine("1: Sort last name in ascending order using IComparable");
            Console.WriteLine("2: Sort pay amount in descending order using IComparer");
            Console.WriteLine("3: Sort by social security number in ascending order using a selection sort and delegate");
            Console.WriteLine("4: Exit");
            menuOption = Console.ReadLine();
            switch (menuOption) {
               case "1":
                  Array.Sort(payableObjects);
                  foreach (IPayable p in payableObjects) {
                     Console.WriteLine(p + "\n");
                  }
                  Console.WriteLine();
                  break;

               case "2":
                  Array.Sort(payableObjects, Employee.payAmountSorter());

                  foreach (IPayable p in payableObjects) {
                     Console.WriteLine(p + "\n");
                  }
                  Console.WriteLine();
                  break;

               case "3":
                  PayrollSystemTest payRoll = new PayrollSystemTest();

                  ComparerSSN ssnSort = new ComparerSSN(Employee.SortAsSSN);
                  payRoll.SelectionSort(payableObjects, ssnSort);

                  break;

               case "4":
                  Console.WriteLine("Option 4 ");
                  menuLogic = false;
                  break;
            }
             }

             Console.ReadKey();
        }
示例#35
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();
    }
示例#36
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();
    }
示例#37
0
 public static void Main()
 {
     CommissionEmployee salesperson = new CommissionEmployee();
 }
    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
    }
 public static void Main()
 {
     CommissionEmployee salesperson = new CommissionEmployee();
       salesperson.EmpNum = 345;
       Console.WriteLine(salesperson.GetGreeting());
 }
示例#41
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", "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.GetPaymentAmount());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          hourlyEmployee, hourlyEmployee.GetPaymentAmount());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          commissionEmployee, commissionEmployee.GetPaymentAmount());
        Console.WriteLine("{0}\nearned: {1:C}\n",
                          basePlusCommissionEmployee,
                          basePlusCommissionEmployee.GetPaymentAmount());

        // 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
        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.GetPaymentAmount());
        } // 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());
        }

        Console.WriteLine("-------------------------------------------------");

        // 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);

        SortSSNDelegate sortDelegate = new SortSSNDelegate(Employee.CompareSSN);  //delegate points to method.
        bool            key          = true;

        while (key)
        {
            Console.WriteLine(Environment.NewLine + "1.Sort last name in ascending order using IComparable");
            Console.WriteLine("2.Sort pay amount in descending order using IComparer");
            Console.WriteLine("3.Sort by social security number in asc order using selection sort & DELEGATE");
            Console.WriteLine("Press 4 anytime to Exit." + Environment.NewLine);
            int value = Int32.Parse(Console.ReadLine());
            switch (value)
            {
            case 1: Console.WriteLine("<Sorting Last Name using IComparABLE>");
                Array.Sort(payableObjects);
                PrintArrayElements(payableObjects);
                break;

            case 2: Console.WriteLine("\n\n<Sort payment amount in desc using ICompaRER>");
                Array.Sort(payableObjects, new PaymentAmountDesc());
                PrintArrayElements(payableObjects);
                break;

            case 3: Console.WriteLine("\n\n<Sort based on SSN in Ascending order>");
                SelectionSortMethod(payableObjects as object, sortDelegate, true);       // Call method. 'true' for ascending.
                PrintArrayElements(payableObjects);
                break;

            default: key = false;
                break;
            }
        } // end Main
    }
示例#42
0
        //load xml file into an ObservableCollection
        private void InitEmployees(ObservableCollection <IPayable> EmployeeList, string path)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;

            XmlReader xmlIn = XmlReader.Create(path, settings);

            if (xmlIn.ReadToDescendant("Employee"))
            {
                // xmlIn.ReadToDescendant("Employee");
                do
                {
                    string id = xmlIn.GetAttribute("id");
                    if (id.Equals("salaried"))
                    {
                        xmlIn.ReadStartElement("Employee");
                        string   ssn       = xmlIn.ReadElementContentAsString();
                        string   first     = xmlIn.ReadElementContentAsString();
                        string   last      = xmlIn.ReadElementContentAsString();
                        decimal  salary    = xmlIn.ReadElementContentAsDecimal();
                        Employee salaryEmp = new SalariedEmployee(first, last, ssn, salary);
                        EmployeeList.Add(salaryEmp);
                    }
                    else if (id.Equals("commission"))
                    {
                        xmlIn.ReadStartElement("Employee");
                        string   ssn       = xmlIn.ReadElementContentAsString();
                        string   first     = xmlIn.ReadElementContentAsString();
                        string   last      = xmlIn.ReadElementContentAsString();
                        decimal  sales     = xmlIn.ReadElementContentAsDecimal();
                        decimal  rate      = xmlIn.ReadElementContentAsDecimal();
                        Employee salaryEmp = new CommissionEmployee(first, last, ssn, sales, rate);
                        EmployeeList.Add(salaryEmp);
                    }
                    else if (id.Equals("hourly"))
                    {
                        xmlIn.ReadStartElement("Employee");
                        string   ssn         = xmlIn.ReadElementContentAsString();
                        string   first       = xmlIn.ReadElementContentAsString();
                        string   last        = xmlIn.ReadElementContentAsString();
                        decimal  hourlyWage  = xmlIn.ReadElementContentAsDecimal();
                        decimal  hoursWorked = xmlIn.ReadElementContentAsDecimal();
                        Employee salaryEmp   = new HourlyEmployee(first, last, ssn, hourlyWage, hoursWorked);
                        EmployeeList.Add(salaryEmp);
                    }
                    else if (id.Equals("base"))
                    {
                        xmlIn.ReadStartElement("Employee");
                        string   ssn       = xmlIn.ReadElementContentAsString();
                        string   first     = xmlIn.ReadElementContentAsString();
                        string   last      = xmlIn.ReadElementContentAsString();
                        decimal  sales     = xmlIn.ReadElementContentAsDecimal();
                        decimal  rate      = xmlIn.ReadElementContentAsDecimal();
                        decimal  salary    = xmlIn.ReadElementContentAsDecimal();
                        Employee salaryEmp = new BasePlusCommissionEmployee(first, last, ssn, sales, rate, salary);
                        EmployeeList.Add(salaryEmp);
                    }
                }while (xmlIn.ReadToNextSibling("Employee"));
            }
            xmlIn.Close();
        }
 public static void Main()
 {
     CommissionEmployee salesperson = new CommissionEmployee();
 }
示例#44
0
    static void Main()
    {
        //create a list of Employee type (which is the base)
        List <Employee> empList = new List <Employee>();  // can also store child classes of Employee type objects

        //add an Employee (base) object to the list
        empList.Add(new Employee());

        //CANNOT cast Employee object (base) to CommissionEmployee object (child)
        //CommissionEmployee c = (CommissionEmployee)empList[0];

        //add a CommissionEmployee (child) object to the list
        empList.Add(new CommissionEmployee());

        //CAN cast CommissionEmployee object (child) to Employee object (base)
        //Employee e = (Employee)empList[1];

        //set some properties of Employee object
        empList[0].IdNum  = 123;
        empList[0].Salary = 20_000.00;
        //empList[0].CommissionRate = .06;      //CommissionRate is not a property of Employee class

        //set some properties of CommissionEmployee object
        empList[1].IdNum  = 456;
        empList[1].Salary = 20_000.00;
        //empList[1].CommissionRate = .06;     //empList[1] is still of Employee type, so CommissionRate not available

        //check to see if underlying object type is a CommissionEmployee, if so, set the commission rate
        if (empList[1] is CommissionEmployee)
        {
            CommissionEmployee ce = (CommissionEmployee)empList[1]; //address of list object is assigned to ce
            ce.CommissionRate = .06;                                //this indirectly changes the list object
        }

        //print out list
        foreach (var item in empList)
        {
            WriteLine(item.ToString());
        }

        ReadLine();

        //time to switch object references in the list
        //Employee[0] is now a CommissionEmployee, Employee[1] is now an Employee
        //Employee to CommissionEmployee (base to child)
        CommissionEmployee cEmp = new CommissionEmployee(); //first create a temp CommissionEmployee object (new address)

        cEmp.IdNum          = empList[0].IdNum;             //capture the current IdNum and Salary
        cEmp.Salary         = empList[0].Salary;
        cEmp.CommissionRate = .08;                          //set the CommissionRate
        empList[0]          = cEmp;                         //then assign back to the list (assigns address of ce)

        //CommissionEmployee to Employee (child to base)
        Employee emp = new Employee();             //first create a temp Employee object

        emp.IdNum  = empList[1].IdNum;             //capture the current IdNum and Salary
        emp.Salary = empList[1].Salary;
        //emp.CommissionRate = .06;                 //Employee objects don't have commission rate
        empList[1] = emp;                           //then assign back to the list

        //print out list
        foreach (var item in empList)
        {
            WriteLine(item.ToString());
        }

        ReadLine();
    }