Question

Create a C# application You are to create a class object called “Employee” which included eight...

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

Homework Answers

Answer #1

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


  
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Python Coding Federal law requires that hourly employees be paid “time and a half” for all...
Python Coding Federal law requires that hourly employees be paid “time and a half” for all work above 40 hours per week. Write a program that prompts the user to enter their hours worked and hourly wage (e.g. $20.00/hr) and then computes and prints their pay. The program should test the number of hours worked to determine if any overtime pay is due. As an example for regular pay (no overtime) suppose that a worker makes $10/hr and works 40...
Design a PayRoll class that has data members for an employee’s hourly pay rate, number of...
Design a PayRoll class that has data members for an employee’s hourly pay rate, number of hours worked of type double. The default constructor will set the hours worked and pay rate to zero. The class must have a mutator function to set the pay rate for each employee and hours worked. The class should include accessors for both the hours worked and the rate of pay. The class should lastly have a getGross function that will return a double...
Problem: A company wants a program that will calculate the weekly paycheck for an employee based...
Problem: A company wants a program that will calculate the weekly paycheck for an employee based on how many hours they worked. For this company, an employee earns $20 an hour for the first 40 hours that they work. The employee earns overtime, $30 an hour, for each hour they work above 40 hours. Example: If an employee works 60 hours in a week, they would earn $20/hr for the first 40 hours. Then they would earn $30/hr for the...
Write a program which: Write a program which uses the following arrays: empID: An array of...
Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary....
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate class. In Worker...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For Loop that asks for a number between 1 and 10; Will double the number each time through the loop and display the answer. Will run five times, so the number will have been doubled five times, and the answer displayed five times. After the loop, display a message saying 'It's done!'. 2. Uses a While Loop; Ask the user to input a friend's name....
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private data fields to store the account holder's name and the account balance A constructor with 0 arguments A constructor with 1 argument (account holder's name) A constructor with 2 arguments(account holder's name and account balance) Public properties for the account holder's name and the account balance. Do not use auto-implemented properties. A method to increase the balance (deposit) A method to decrease the balance...
Note: In this chapter and in all succeeding work throughout the course, unless instructed otherwise, calculate...
Note: In this chapter and in all succeeding work throughout the course, unless instructed otherwise, calculate hourly rates and overtime rates as follows: 1. Carry the hourly rate and the overtime rate to 3 decimal places and then round off to 2 decimal places (round the hourly rate to 2 decimal places before multiplying by one and one-half to determine the overtime rate). 2. If the third decimal place is 5 or more, round to the next higher cent. 3....