Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // create objects
            Location loc = new Location { Description = "Head Office", City = "Glasgow" };
            HourlyPaidEmployee emp1 = new HourlyPaidEmployee(1, "Michael",
                "michael", loc, "1234");
            SalariedEmployee emp2 = new SalariedEmployee(2, "Susan", "susan",
                loc, "5678", 6);
            Employee emp3 = new HourlyPaidEmployee(3, "Ahmad", "ahmad",
                loc, "4321");
            Department dep = new Department();
            dep.AddEmployee(emp1);
            dep.AddEmployee(emp2);
            dep.AddEmployee(emp3);
            DatabaseTimeSheet dts = new DatabaseTimeSheet(@"mydb");

            // send messages (call methods)
            Console.WriteLine("Email address for {0}: {1}", emp1.Name, emp1.Email());
            emp1.RecordTime(dts, 5, PayRate.Weekend);
            Console.WriteLine("Email address for {0}: {1}", emp2.Name, emp2.Email());
            int newGrade = emp2.PayIncrement();
            Console.WriteLine("New grade for {0}: {1}", emp2.Name, newGrade);
            Console.WriteLine("Email address for {0}: {1}", emp3.Name, emp3.Email());

            Object o = new HourlyPaidEmployee();
            SalariedEmployee semp = o as SalariedEmployee;

            // wait for key press before ending
            Console.ReadLine();
        }
Exemplo n.º 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 void LoadEmployees()
        {
            //simulating loading from database.
            employees = new Employee[2];

            employees[0] = new ContractEmployee("Adam Barr");
            Console.WriteLine();

            employees[1] = new SalariedEmployee("Max Benson");
            Console.WriteLine();
        }
Exemplo n.º 4
0
 //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);
 }
Exemplo n.º 5
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
    }
    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 *****/
    }
Exemplo n.º 7
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 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
    }
Exemplo n.º 9
0
    public static void Main( string[] args )
    {
        // create four-element IPayable array
          IPayable[] payableObjects = new IPayable[ 4 ];

          // 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 SalariedEmployee( "Lisa", "Barnes",
         "888-88-8888", 1200.00M );

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

          // generically process each element in array payableObjects
          foreach ( var currentPayable in payableObjects )
          {
         // output currentPayable and its appropriate payment amount
         Console.WriteLine( "payment due {0}: {1:C}\n",
            currentPayable, currentPayable.GetPaymentAmount() );
          } // end foreach
    }
Exemplo n.º 10
0
 public void setProjManager(SalariedEmployee e)
 {
     manager = e;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Create a new SalariedEmployee object.
 /// </summary>
 /// <param name="id">Initial value of Id.</param>
 /// <param name="lastName">Initial value of LastName.</param>
 /// <param name="firstName">Initial value of FirstName.</param>
 /// <param name="salary">Initial value of Salary.</param>
 public static SalariedEmployee CreateSalariedEmployee(int id, string lastName, string firstName, int salary)
 {
     SalariedEmployee salariedEmployee = new SalariedEmployee();
     salariedEmployee.Id = id;
     salariedEmployee.LastName = lastName;
     salariedEmployee.FirstName = firstName;
     salariedEmployee.Salary = salary;
     return salariedEmployee;
 }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
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
    }
Exemplo n.º 14
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);

        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
    }
Exemplo n.º 15
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
Exemplo n.º 16
0
    internal void ReadDataFromInputFile()
    {
        // create and intialize the file objects
        FileStream   fstream = new FileStream("INPUT.txt", FileMode.Open, FileAccess.Read);
        StreamReader infile  = new StreamReader(fstream);  // FileStream

        int numberOfRecords = int.Parse(infile.ReadLine());

        employees = new Employee[numberOfRecords];

        for (int i = 0; i < employees.Length; i++)
        {
            string employeeType = infile.ReadLine();

            // read in data for an employee
            string fName = infile.ReadLine();
            string lName = infile.ReadLine();
            string ssn   = infile.ReadLine();

            // how many more things are there to read?
            if (employeeType == SAL)
            {
                decimal weeklySalary = decimal.Parse(infile.ReadLine());

                // make a employee using the data you just read
                // put the employee into the array
                employees[i] = new SalariedEmployee(fName, lName, ssn, weeklySalary);
            }
            else if (employeeType == BPC)
            {
                decimal grossSales     = decimal.Parse(infile.ReadLine());
                decimal commissionRate = decimal.Parse(infile.ReadLine());
                decimal baseSalary     = decimal.Parse(infile.ReadLine());
                // make an employee using the data you just read
                // put the employee into the array
                employees[i] = new BasePlusCommissionEmployee(fName, lName, ssn, grossSales, commissionRate, baseSalary);
            }
            else if (employeeType == COM)
            {
                decimal grossSales     = decimal.Parse(infile.ReadLine());
                decimal commissionRate = decimal.Parse(infile.ReadLine());

                // make a employee using the data you just read
                // put the employee into the array
                employees[i] = new CommissionEmployee(fName, lName, ssn, grossSales, commissionRate);
            }
            else if (employeeType == HOURLY)
            {
                decimal hourlyWage  = decimal.Parse(infile.ReadLine());
                decimal hoursWorked = decimal.Parse(infile.ReadLine());

                // make a employee using the data you just read
                // put the employee into the array
                employees[i] = new HourlyEmployee(fName, lName, ssn, hourlyWage, hoursWorked);
            }
            else
            {
                Console.WriteLine("ERROR: That is not a valid employee type.");
            }
        }

        // close the file or release the resource
        infile.Close();
    }
Exemplo n.º 17
0
 public void ApplyDeduction(SalariedEmployee employee, PayCheck payCheck)
 {
     throw new NotImplementedException();
 }
		private IEmployee FillInEditedEmployee(SalariedEmployee employee){
			employee.PayInfo.Salary = Double.Parse(Salary);
			return this.FillInStandardEmployee(employee);
		}
Exemplo n.º 19
0
    private void CreateEmployeeRecord()
    {
        //display prompt that asks for employee last name
        Console.Write("Enter the Last Name for the record to add: (ex: Smith) ");

        //user types in the employee last name
        string lname = Console.ReadLine();

        // check to see if record already exists in the database
        // if it does, return back to main menu, issue a message
        Employee emp = FindEmployeeRecord(lname);

        if (emp != null)
        {
            Console.WriteLine("Error: " + lname + " is already in the database.");
            return;
        }

        //display prompt that asks for type of employee
        Console.WriteLine("Enter the type of employee H= Hourly, C= Commision, S = Salaried, P= BasePlusCommision: ");
        ConsoleKeyInfo employeeType = Console.ReadKey();

        //display prompt that asks for employee First Name
        Console.WriteLine("Enter the employees first name: ");
        string fname = Console.ReadLine();

        //display prompt that asks for employee Last Name
        Console.WriteLine("Enter the employees last name: ");
        lname = Console.ReadLine();

        //display prompt that asks for the SSN
        Console.WriteLine("Enter the employees SSN: ");
        string ssn = Console.ReadLine();

        // if type of employee is H
        if (employeeType.KeyChar == EMP_H || employeeType.KeyChar == EMP_h)
        {
            //display prompts for hourly wage and hours worked
            Console.WriteLine("Enter hourly wage: ");
            decimal hourlyWage = decimal.Parse(Console.ReadLine());
            Console.WriteLine("Enter hours worked: ");
            decimal hoursWorked = decimal.Parse(Console.ReadLine());

            // make hourly employee
            emp = new HourlyEmployee(fname, lname, ssn, hourlyWage, hoursWorked);
        }
        //if type employee is salaried
        else if (employeeType.KeyChar == EMP_S || employeeType.KeyChar == EMP_s)
        {
            // prompt for weekly salary
            Console.WriteLine("Enter the weekly salary: ");
            decimal weeklySalary = decimal.Parse(Console.ReadLine());

            // make a salaried employee
            emp = new SalariedEmployee(fname, lname, ssn, weeklySalary);
        }
        //if employee type is commision
        else if (employeeType.KeyChar == EMP_C || employeeType.KeyChar == EMP_c)
        {
            // prompt for gross sales and commision rate
            Console.WriteLine("Enter the gross sales: ");
            decimal grossSales = decimal.Parse(Console.ReadLine());
            Console.WriteLine("Enter the commision rate: ");
            decimal commisionRate = decimal.Parse(Console.ReadLine());
            // make a commision employee
            emp = new CommissionEmployee(fname, lname, ssn, grossSales, commisionRate);
        }
        //if employee type is BasePlusCommision
        else if (employeeType.KeyChar == EMP_P || employeeType.KeyChar == EMP_p)
        {
            // prompt for gross sales, commision rate, and base salary
            Console.WriteLine("Enter the gross sales: ");
            decimal grossSales = decimal.Parse(Console.ReadLine());
            Console.WriteLine("Enter the commision rate: ");
            decimal commisionRate = decimal.Parse(Console.ReadLine());
            Console.WriteLine("Enter Base salary: ");
            decimal baseSalary = decimal.Parse(Console.ReadLine());
            // make a BasePluseCommision employee
            emp = new BasePlusCommissionEmployee(fname, lname, ssn, grossSales, commisionRate, baseSalary);
        }
        //if employee types does not exist
        else
        {
            Console.WriteLine(employeeType.KeyChar + " is not a type of employee.");
            return;
        }
        ////display the current employee data and ask for confirm
        //// ask user to confirm
        Console.WriteLine(emp);
        Console.WriteLine("Is the above information all correct? [Y] or [N] ");
        string answer = Console.ReadLine();

        if (answer != "Y")
        {
            return;
        }


        // the db saves the record, and returns to main menu - steps:
        // and insert the newly created student object into the array

        // 1 - make an array that is 1 "bigger" than employees
        Employee[] biggerEmployeeArray = new Employee[employees.Length + 1];

        // 2 - copy all objects from employees to the bigger array
        // (at the same index val)
        for (int i = 0; i < employees.Length; i++)
        {
            biggerEmployeeArray[i] = employees[i];
        }

        // put emp in the last slot in the bigger array
        biggerEmployeeArray[biggerEmployeeArray.Length - 1] = emp;

        // make the employees ref point to the bigger array
        employees = biggerEmployeeArray;
    }
    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("-------------------------------------");
        Console.WriteLine("Total number of Employee\n" + Employee.employeeCount);
        Console.WriteLine("------------------------------------");
        Console.Read();
    }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            // declaring a List of type TempEmployee to store the objects
            List <Object> tmp     = new List <object>();
            var           tmpList = new List <Employee>();
            //we can do the same for the other class (SalariedEmployee)
            List <Employee> salList                 = new List <Employee>();
            List <Project>  ourProjects             = new List <Project>();
            List <WorksOn>  employeeProjAssignments = new List <WorksOn>();

            // add new employee object directly to the list using some values
            tmpList.Add(new TempEmployee("John", " 1200 s westren st, Canyon", 22, 40f, 15.5f));

            //create employee object using some values, then add the created object to the list
            var e = new TempEmployee("Nick", " 333 Bill st, Amarillo", 26, 50f, 15.5f);

            tmpList.Add(e);
            Project          p1 = new Project("WT Stadium", 11);
            SalariedEmployee a  = new SalariedEmployee("Bob", " 233 Bill st, Amarillo", 33, 5000f, 1200f);

            // read some employees info from the cosole "keyboard input", then add them to the list

            p1.setProjManager(a);
            SalariedEmployee t = p1.getProjManager();

            t.displEmpInfo();



            // To read employees data from file, where each line has one employee info separated by comma ","
            // the employee information is in the file tempEmployee.txt which is in the main directory of this project

            LoadData('T', tmp, "tempEmployees.txt", false);

            tmpList.AddRange(tmp.ConvertAll(x => (TempEmployee)x));
            tmp = new List <Object>();
            LoadData('S', tmp, "salEmployees.txt", false);
            salList.AddRange(tmp.ConvertAll(x => (SalariedEmployee)x));

            tmp = new List <Object>();
            LoadData('P', tmp, "projectsData.txt", true);
            ourProjects.AddRange(tmp.ConvertAll(x => (Project)x));



            tmp = new List <Object>();
            tmp.AddRange(salList.ConvertAll(x => (Object)x));
            tmp.AddRange(tmpList.ConvertAll(x => (Object)x));
            listAllEmpPayInfo('S', tmp);

            //LoadProjMangers(List<Employee> el,List<Project> pl, string fileName, bool headerIncluded)
            LoadProjMangers(salList, ourProjects, "projManagers.txt", true);
            LoadEmpProjAssignment(salList, ourProjects, employeeProjAssignments, "worksOn.txt", true);
            foreach (Project p in ourProjects)
            {
                Console.WriteLine("Project info for:");
                p.getProjManager().displEmpInfo();
                Console.WriteLine(" Has the following Employees:");
                foreach (WorksOn epa in employeeProjAssignments)
                {
                    Project tp = epa.getProject();
                    if (tp == p)
                    {
                        epa.getEmployee().displEmpInfo();
                    }
                }
            }
        }