Create a C application You are to create a class object call

Create a C# application

You are to create a class object called “Employee” which included eight private variables:

firstN

lastN

dNum

wage: holds how much the person makes per hour

weekHrsWkd: holds how many total hours the person worked each week.

regHrsAmt: initialize to a fixed amount of 40 using constructor.

regPay

otPay

After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked.

Methods:

constructor

properties

CalcPay(): Calculate the regular pay and overtime pay.

Create an “EmployeeDemo” class. In the main function, the program should ask the user the number of employee in the company and create a 2-dimensional dynamic array (number of employee by 4 weeks). Then, the program should ask user to enter each employee’s information and the amount of hours they worked weekly.

The program shows a menu with employee name for user to choose which employee to display the following information:

How much the person totally made

How much of paycheck is regular pay

How much of paycheck is overtime pay

Solution

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Employee
{
  
   public enum EmployeeType {GROUPA, GROUPB, GROUPC, GROUPD};
  
   public struct EmployeeSalaryInfo
   {
       public float hourlyWage;
       public int monthlyHours;
       public float baseSalary;
       public int numSales;
         

       public EmployeeSalaryInfo( EmployeeType eme)     
       {
           this.hourlyWage = 0;
           this.monthlyHours = 0;
           this.baseSalary = 0;
           this.numSales = 0;
             
       }
   }

   class Program
   {
       static void Main(string[] args)
       {
           Console.WriteLine(\"Welcome to the Employee System\");
           EmployeeArray empArray = new EmployeeArray();  
             
           int continueRunning = 1;
           do                                                     
               Console.WriteLine();
               Console.WriteLine(\"Please Enter Your Choice:\");
               Console.WriteLine(\"1=Enter new employee\");         
               Console.WriteLine(\"2=Update existing employee\");  
               Console.WriteLine(\"3=Delete employee\");             
               Console.WriteLine(\"4=Print employee list\");         
               Console.WriteLine(\"Any other number to Exit\");
               int userChoice = int.Parse(Console.ReadLine());
               Console.WriteLine();
               switch (userChoice)
               {
                   case 1:                                         
                       Employee emp = CreateNewWorker();       //Asking for employee information by creating a new employee.
                       if (!(empArray.Contains(emp)))           //Checking to see that employee does not exist
                           empArray.Add(emp);                   //If the employee does not exist in the list then we can add it.
                       else
                           Console.WriteLine(\"Can not add new worker. This worker already exists\");
                       break;
                   case 2:                                       //If user wishes to edit an employee
                       EditEmployee(empArray);
                       break;
                   case 3:
                       DeleteEmployee(empArray);               //if user wishes to delete an employee from the list
                       break;
                   case 4:
                       empArray.Print();
                       break;
                   default:
                       continueRunning = 0;                       //If user has chosen to exit the system.
                       break;
               }
           } while (continueRunning == 1);                       //Checking to see if to continue running the system
       }
      
       static Employee CreateNewWorker()                                                   //Method for creating a new employee.
       {         
           Employee emp;                                                                   //A new employee consists of the basic information which is
           Console.WriteLine(\"Enter first name:\");                                           //The first name
           string first = Console.ReadLine();
           Console.WriteLine(\"Enter last name:\");                                           //The family name
           string last = Console.ReadLine();
           Console.WriteLine(\"Enter birth date in DD/MM/YYYY format\");                       //and birthday.
           DateTime bDay = DateTime.Parse(Console.ReadLine());
           Console.WriteLine(\"Is worker 1=Secretary, 2=Sales, 3=Manager, 4=Top Manager?\");   //Also asking for the type
           EmployeeSalaryInfo salInfo = GetSalaryInfo(workerType);                       //and the salary information
           emp = new Employee(first, last, bDay, workerType, salInfo);                   //with all the info can create a new employee
           return emp;
       }

       static void EditEmployee(EmployeeArray employees)                                   //Method for editing an employee and his info   
       {

           Employee emp = GetEmployeeInfo();                                               //First getting basic info about employee to edit.
           EmployeeSalaryInfo salInfo = new TGCEmployeeSalaryInfo();                      
           if (employees.Contains(emp))                                                       //Then checking that list has this employee (if not can not edit)
           {
               Console.WriteLine(\"Has worker position changed? 1=Yes, 2=No\");      
               int changeType = int.Parse(Console.ReadLine());             
               if (changeType == 1)                                                           //If employee type has changed
               {                                                                           //then ask for new type
                   Console.WriteLine(\"Is worker 1=Secretary, 2=Sales, 3=Manager, 4=Top Manager?\");
                   TGCEmployeeType workerType = (TGCEmployeeType)int.Parse(Console.ReadLine()) - 1;
                   salInfo = GetSalaryInfo(workerType);                                       //and then ask for his salary info
                   employees.Replace(emp, workerType, salInfo);                               //and finally replace the info in the salary list.
               }
               else                                                                           //if type ha not changed   
               {
                   salInfo = GetSalaryInfo(employees.Find(emp));                               //then get only the salary info (without the need for the type)
                   employees.Replace(emp, employees.Find(emp), salInfo);                       //and finally replace the info in the salary list.
               }
           }
           else
               Console.WriteLine(\"There is no such employee\");     

       }

         

       static Employee GetEmployeeInfo()                   //A method for getting the basic information about an employee which includes
       {
           Console.WriteLine(\"Enter first name of the employee\");
           string first = Console.ReadLine();               //His First name
           Console.WriteLine(\"Enter last name of the employee\");
           string last = Console.ReadLine();               //His last name
           Console.WriteLine(\"Enter birth date in DD/MM/YYYY format\");
           DateTime bDay = DateTime.Parse(Console.ReadLine()); //And his birthday
           Employee emp = new Employee(first, last, bDay);   
           return emp;                                       //and then we can create an emplyee object (without adding him to the list)
       }

       static TGCEmployeeSalaryInfo GetSalaryInfo(TGCEmployeeType empType)       //A method for getting the salary info about a certain employee type from the user
       {
           TGCEmployeeSalaryInfo salInfo = new TGCEmployeeSalaryInfo(empType);
           switch(empType)                                                       //A switch to see what the type is so that the correct questions could be asked
           {
               case (EmployeeType)0:                                           //if it is a secretary than ask for hourly wage and number of hours
                   Console.WriteLine(\"Please Enter Hourly Wage\");
                   salInfo.hourlyWage = float.Parse(Console.ReadLine());
                   Console.WriteLine(\"Please Enter Number of Hours Worked\");
                   salInfo.monthlyHours = int.Parse(Console.ReadLine());
                   break;
               case (TGCEmployeeType)1:                                           //if it is a sales person than ask for base salary, number of sales and bomus per sale
                   Console.WriteLine(\"Please Enter Base Salary\");
                   salInfo.baseSalary = float.Parse(Console.ReadLine());
                   Console.WriteLine(\"Please Enter Number of Sales\");
                   salInfo.numSales = int.Parse(Console.ReadLine());
                   Console.WriteLine(\"Please Enter Bonus per Sale\");
                   salInfo.salaryBonus = float.Parse(Console.ReadLine());
                   break;
               case (TGCEmployeeType)2:                                           //if it is a manager than ask for the base salary. The bonus is currently constant as part of the salary info struct
                   Console.WriteLine(\"Please Enter Base Salary\");
                   salInfo.baseSalary = float.Parse(Console.ReadLine());
                   break;
               case (EmployeeType)3:                                           //if it is a top manager than ask for the base salary. The bonus is currently constant as part of the salary info struct
                   Console.WriteLine(\"Please Enter Base Salary\");
                   salInfo.baseSalary = float.Parse(Console.ReadLine());
                   break;
           }

           return salInfo;
       }

   }

   class Employee                                               //An employee class which includes all the information about an employee, ways to retrieve and set the info, and calculate its salary
   {
       string firstName;
       string familyName;
       DateTime birthDate;
EmployeeType employeeType;
EmployeeSalaryInfo employeeSalaryInfo;

       public Employee(string first, string family, DateTime bDay) //first constructor which creates an employee without his salary info and type.
       {
           firstName = first;
           familyName = family;
           birthDate = bDay;
       }

       public Employee(string first, string family, DateTime bDay, EmployeeType empType, EmployeeSalaryInfo salInfo) //second constructor which creates an employee with all info
       {
           firstName = first;
           familyName = family;
           birthDate = bDay;
           employeeType = empType;
           employeeSalaryInfo = salInfo;
       }
      
       public string FirstName       //property method for getting the first name
       {
           get
           {
               return this.firstName;
           }
       }

       public string FamilyName       //property method for getting the last name
       {
           get
           {
               return this.familyName;
           }
       }

       public DateTime BirthDate   //property method for getting the birth date
       {
           get
           {
               return this.birthDate;
           }
       }

       public EmployeeType EmployeeType //property method for getting the type of employee or setting it (in case it changed)
       {
           get
           {
               return this.employeeType;
           }

           set
           {
               this.employeeType = value;
           }
       }

       public EmployeeSalaryInfo SalaryInfo //property method for setting new salary information for the employee
       {
           set
           {
               this.employeeSalaryInfo = value;
           }
       }

       public float CalcSalary()           //method for calculating the employee\'s salary
       {
           float salary=0;
           switch(employeeType)
           {
               case (EmployeeType)0:       //if employee is a secretary than multiply wage per hour by hours worked

                   salary = (employeeSalaryInfo.hourlyWage) * (employeeSalaryInfo.monthlyHours);
                   break;
               case ( EmployeeType)1:       //if employee is a sales person than multiply number of sales by bonus per sale and add that to the base salary
                   salary = ((employeeSalaryInfo.baseSalary) + (employeeSalaryInfo.numSales * (employeeSalaryInfo.salaryBonus)));
                   break;
               case (EmployeeType)2:       //if employee is a manager than add the bonus to the base salary
                   salary = (employeeSalaryInfo.baseSalary) + (employeeSalaryInfo.salaryBonus);
                   break;
               case ( EmployeeType)3:       //if employee is a top manager than add the bonus to the base salary
                   salary = (employeeSalaryInfo.baseSalary) + (employeeSalaryInfo.salaryBonus);
                   break;
           }

           return salary;
       }


   }
  
     

         

      
       public void Print()                       //a method for printing all employees in the list icluding name, birthdate, type and salary.
       {
           Console.WriteLine(\"Family Name\\tFirst Name\\tBirth Date\\tWorker Type\\tSalary\");
           Console.WriteLine(\"-----------\\t----------\\t----------\\t-----------\\t------\");
           foreach ( Employee e in employees)
               Console.WriteLine(\"{0}\\t{1}\\t{2}\\t{3}\\t{4}\", e.FamilyName.PadRight(11), e.FirstName.PadRight(10), e.BirthDate.ToShortDateString(), e.EmployeeType.ToString().PadRight(11), e.CalcSalary());
           Console.WriteLine();
          
       }
   }


  
}

Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the pe
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the pe
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the pe
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the pe
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the pe
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the pe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site