Question

In: Computer Science

Create a C# Application. Create a class object called “Employee” which includes the following private variables:...

Create a C# Application. Create a class object called “Employee” which includes the following private variables:

firstN
lastN
idNum
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

Solutions

Expert Solution

Code Screenshots:

Sample Output:

Code to Copy:

using System;

//Define the class Employee()

class Employee

{

    //Declare the

    //required private variables.

    private string firstN;

    private string lastN;

    private int idNum;

    private double wage;

    private double weekHrsWkd;

    private double regHrsAmt;

    private double regPay;

    private double otPay;

    //Define the constructor.

    public Employee(string fname = "", string lname = "",

     int id = -1, double sal = 0, double hrs = 0)

    {

        firstN = fname;

        lastN = lname;

        idNum = id;

        wage = sal;

        weekHrsWkd = hrs;

        regHrsAmt = 40;

        regPay = 0;

        otPay = 0;

        CalcPay();

    }

    //Define the required properties.

    public int ID

    {

        get

        {

            return idNum;

        }

    }

   

    public string Name

    {

        get

        {

            return lastN + ", " + firstN;

        }

    }

    public double RegPay

    {

        get

        {

            return regPay;

        }

    }

    public double OTPay

    {

        get

        {

            return otPay;

        }

    }

    //Define the method CalcPay().

    public void CalcPay()

    {

        //Declare the

        //required variables.

        double othrs, reghrs;

       

        //If the employee has

        //worked more than the Regular

        //Hours, calculate

        //the overtime hours.

        if(weekHrsWkd > regHrsAmt)

        {

            reghrs = regHrsAmt;

            othrs = weekHrsWkd - regHrsAmt;

        }

        //Otherwise, set the

        //overtime hours to zero.

        else

        {

            othrs = 0;

            reghrs = weekHrsWkd;

        }

        //Calculate the

        //regular and overtime pay.

        regPay = wage * reghrs;

        otPay = 1.5 * wage * othrs;

    }

}

//Define the class EmployeeDemo.

class EmployeeDemo {

    //Define the Main() method.

    public static void Main (string[] args)

    {

        //Define a 2-D array to

        //store the employees' data.

        Employee [,] employees;

       

        //Declare a variable to

        //store the required variables.

        int numEmp;

       

        //Prompt the user to enter

        //the number of employees.

        Console.Write("Enter the number of employees: ");

       

        //Read and store the input.

        numEmp = Convert.ToInt32(Console.ReadLine());

        //Allocate memory to the 2-D array.

        employees = new Employee[numEmp, 4];

        //Prompt the user to enter

        //the details of the employees.

        Console.WriteLine("Enter the details of the employees:");

        for(int i=0; i<numEmp; i++)

        {

            string fname;

            string lname;

            int id;

            double sal;

            double hrs;

            Console.WriteLine("Employee {0}:", (i+1));

            Console.Write("Enter the first name: ");

            fname = Console.ReadLine();

            Console.Write("Enter the last name: ");

            lname = Console.ReadLine();

            Console.Write("Enter the id of the employee: ");

            id = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter the hourly pay: ");

            sal = Convert.ToDouble(Console.ReadLine());

            for(int j=0; j<4; j++)

            {

                Console.Write("Enter the hours for week {0}: ", j+1);

                hrs = Convert.ToDouble(Console.ReadLine());

                employees[i, j] = new Employee(fname, lname, id, sal, hrs);

            }

        }

        Console.WriteLine("Choose one of the following employees: ");

        for(int i=0; i<numEmp; i++)

        {

            Console.WriteLine("{0}. "+employees[i,0].Name, i+1);

        }

        Console.Write("Enter the choice (1 - {0}): ", numEmp);

        int choice = Convert.ToInt32(Console.ReadLine()) - 1;

        if(choice >= 0 && choice < numEmp)

      {

            double ot = 0;

            double reg = 0;

            double total = 0;

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

            {

                reg += employees[choice, i].RegPay;

                ot += employees[choice, i].OTPay;

            }

            total = reg + ot;

            Console.WriteLine("The details of the selected employee are as follows:");

            Console.WriteLine("Total Pay: ${0}", total);

            Console.WriteLine("Regular Pay: ${0}", reg);

            Console.WriteLine("Overtime Pay: ${0}", ot);

        }

    }

}


Related Solutions

in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
1) Create a class called Employee that includes three instance variables — a first name (type...
1) Create a class called Employee that includes three instance variables — a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. 2)Create an app named EmployeeLinkedList that stores a collection of Employee objects in a LinkedList<Employee>. Test the app by creating five...
1) Create a class called Employee that includes three instance variables — a first name (type...
1) Create a class called Employee that includes three instance variables — a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. 2) Create an app named EmployeeLinkedList that stores a collection of Employee objects in a LinkedList<Employee>. Test the app by creating...
Create a class called employee which has the following instance variables: Employee ID number Salary Years...
Create a class called employee which has the following instance variables: Employee ID number Salary Years at the company Your class should have the following methods: New employee which reads in an employee’s ID number, salary and years of service Anniversary which will up the years of service by 1 You got a raise which will read in how much the raise was (a percent) and then calculate the new salary You get a bonus which gives a yearly bonus...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
C++ make a rational class that includes these members for rational -private member variables to hold...
C++ make a rational class that includes these members for rational -private member variables to hold the numerator and denominator values -a default constructor -an overloaded constructor that accepts 2 values for an initial fraction -member fractions add(), sub(), mul(), div(), less(), eq(), and neq() (less should not return true if the object is less than argument) -a member function that accepts an argument of type of ostream that writes the fraction to that open output stream do not let...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter,...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object: ● Implicit constructor (default constructor) ● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle: Area = pi * (r * r) Your...
C# Language Create a class called evaluateValue that declares 3 integer class variables: zeroValue, positiveValue and...
C# Language Create a class called evaluateValue that declares 3 integer class variables: zeroValue, positiveValue and negativeValue. These should be declared as public and you should not use automatic properties to declare them. Your class should have a constructor that takes one integer argument. In the constructor you will code if statements to set one of the three class variables (indicators) to 1 if the number sent to the constructor is either equal to zero, negative, or positive. In the...
Create the logic for an application that instantiates an object of the ATM class. Prompt the...
Create the logic for an application that instantiates an object of the ATM class. Prompt the user for the ATM object data to display the user’s bank balance PROGRAMMING LOGIC AND DESIGN QUESTION JAVA LANGUAGE
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT