示例#1
0
        public static void MonthlyPay()
        {
            //monthly employee
            HourlyEmployee hourly = new HourlyEmployee("Frank", "Finance", 2020, 160, 30);

            Console.WriteLine("Employee Name: " + hourly.name);
            Console.WriteLine("Employee Section: " + hourly.section);
            Console.WriteLine("Employee Employment Date: " + hourly.dateEmployed);

            Console.WriteLine("Wage per month:");
            Console.WriteLine(hourly.hoursPerMonth * hourly.ratePerHour);

            Console.WriteLine();

            //salary employee
            SalaryEmployee yearly = new SalaryEmployee("Joe", "Sanitation", 2020, 50000);

            Console.WriteLine("Employee Name: " + yearly.name);
            Console.WriteLine("Employee Section: " + yearly.section);
            Console.WriteLine("Employee Employment Date: " + yearly.dateEmployed);
            Console.WriteLine("Wage per year:");
            Console.WriteLine(yearly.annualPay);

            Console.WriteLine();
        }
示例#2
0
        void PopulateEmployee()
        {
            int index = -99;

            for (int i = 0; i < myEmployees.Length; i++)
            {
                if (myEmployees[i] == null)
                {
                    index = i;
                    break;
                }
            }
            if (index != -99)
            {
                Console.WriteLine("\nPopulating Employee:");
                Console.WriteLine("\nPlease Enter the Employee's First Name:");
                String firstName = Console.ReadLine();

                Console.WriteLine("\nPlease Enter the Employee's Last Name");
                String lastName = Console.ReadLine();

                Console.WriteLine("\nPlease Enter the Employee's Social Security Number (9 digits,numbers only, no dashes)");
                String SocialSecurityNumber = Console.ReadLine();

                Console.WriteLine("\nWhat type of employee is this, hourly(h), salary(s), commission(c) or base plus commission (b)? Please answer h/s/c/b");
                String type = Console.ReadLine();

                if (type.Equals("h", StringComparison.InvariantCultureIgnoreCase))
                {
                    Console.WriteLine("\nPlease Enter number of hours");
                    int hoursWorked = int.Parse(Console.ReadLine());

                    Console.WriteLine("\nPlease Enter rate, (ex for $20 an hour enter 20):");
                    decimal hourlyWage = Convert.ToDecimal(Console.ReadLine());

                    myEmployees[index] = new HourlyEmployee(firstName, lastName, SocialSecurityNumber, hourlyWage, hoursWorked);
                }
                else if (type.Equals("s", StringComparison.InvariantCultureIgnoreCase))
                {
                    //This is a salary employee
                    decimal grossPay = 0m;
                    do
                    {
                        Console.WriteLine("\nIs this employee Staff(s) or Executive(e)? Please answer s or e.");
                        String Salarytype = Console.ReadLine();

                        if (Salarytype.Equals("s", StringComparison.InvariantCultureIgnoreCase))
                        {
                            grossPay    = 50000M;
                            validChoice = true;
                        }
                        else if (Salarytype.Equals("e", StringComparison.InvariantCultureIgnoreCase))
                        {
                            grossPay    = 100000M;
                            validChoice = true;
                        }
                        else
                        {
                            Console.WriteLine("Invalid Employee Salary Type\n");
                            validChoice = false;
                        }
                    } while (validChoice == false);

                    myEmployees[index] = new SalariedEmployee(firstName, lastName, SocialSecurityNumber, grossPay);
                }
                else if (type.Equals("c", StringComparison.InvariantCultureIgnoreCase))
                {
                    //this is a commission employee

                    Console.WriteLine("\nPlease Enter the number of Units Sold:");
                    decimal grossSales = Convert.ToDecimal(Console.ReadLine());

                    Console.WriteLine("\nPlease enter the price per Unit:");
                    decimal commissionRate = Convert.ToDecimal(Console.ReadLine());

                    myEmployees[index] = new CommissionEmployee(firstName, lastName, SocialSecurityNumber, grossSales, commissionRate);
                }
                else if (type.Equals("b", StringComparison.InvariantCultureIgnoreCase))
                {
                    //this is a base plus commission employee

                    Console.WriteLine("\nPlease Enter the number of Units Sold:");
                    decimal grossSales = Convert.ToDecimal(Console.ReadLine());

                    Console.WriteLine("\nPlease enter the price per Unit:");
                    decimal commissionRate = Convert.ToDecimal(Console.ReadLine());

                    Console.WriteLine("\nPlease enter this employee's base salary:");
                    decimal baseSalary = Convert.ToDecimal(Console.ReadLine());

                    myEmployees[index] = new BasePlusCommissionEmployee(firstName, lastName, SocialSecurityNumber, grossSales, commissionRate, baseSalary);
                }
                else
                {
                    Console.WriteLine("\nInvalid employee type");
                    PopulateEmployee();
                }
            }
            else
            {
                Console.WriteLine("\nSorry, all available employee slots are full.\n");
                Menu();
            }
        }