Question

Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variable...

Visual C# C#

Visual Studio 2017

You are to create a class object called “Employee” which included eight 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Explanation in Comments

using System;

namespace ABC
{
public class Employee{

private int []weekHrsWkd;
private int regHrsAmt;
private double wage,regPay,otPay;
private String idNum,firstN,lastN;

public Employee()
{
this.regHrsAmt=40;
this.regPay=0.0;
this.otPay=0.0;
}
public String GetName()
{
return this.firstN+" "+this.lastN;
}
public void SetFirstN(String fn)
{
this.firstN=fn;
}
public void SetLastN(String ln)
{
this.lastN=ln;
}
public void SetIdNum(String id)
{
this.idNum=id;
}
public void SetWage(double wg)
{
this.wage=wg;
}
public void SetWeekHrsWkd(int []whw)
{
this.weekHrsWkd=new int[whw.Length];
Array.Copy(whw,this.weekHrsWkd,whw.Length);
  
}
public double CalcPay()
{
int overtime=0;
for(int i=0;i< weekHrsWkd.Length;i++)
{
int c=weekHrsWkd[i]-regHrsAmt;
//update regular pay
if(c>0){
overtime+=c;
this.regPay+=40*this.wage;
}
else// no overtime means that weekHrswkd is the only deciding factr for payment
this.regPay+=weekHrsWkd[i]*wage;
}
//assign overtime pay
this.otPay=1.5*wage*overtime;
//return total pay
return this.otPay+this.regPay;
  
}
public void Properties(){
Console.WriteLine("Name: "+this.firstN+" "+this.lastN+"\nID: "+this.idNum+"\n");
double totPay=this.CalcPay();
Console.WriteLine("Total Pay is :"+ totPay);
Console.WriteLine("Regular Pay is :"+ this.regPay);
Console.WriteLine("OverTime Pay is :"+ this.otPay);

}
}
public class EmployeeDemo
{
public static void Main(string[] args)
{

Console.WriteLine("Input number employees:");
int n= int.Parse(Console.ReadLine());
int [,]chart=new int [n,4];
Employee []employees=new Employee[n];
  
//take input for n employees
for (int i=0;i<n;i++){
Console.WriteLine("Input FirstName of Employee #{0}",i+1);
String fn= Console.ReadLine();
Console.WriteLine("Input LastName of Employee #{0}",i+1);
String ln= Console.ReadLine();
Console.WriteLine("Input ID of Employee #{0}",i+1);
String id=Console.ReadLine();
Console.WriteLine("Input "+fn+" "+ln+"'s wage");
double wg=Double.Parse(Console.ReadLine());
int []arr=new int[4];
for (int j=0;j<4;j++)
{
Console.WriteLine("Input "+fn+" "+ln+"'s working hours for week {0} :",j+1);
arr[j]=int.Parse(Console.ReadLine());
chart[i,j]=arr[j];
}
               employees[i]=new Employee();
employees[i].SetFirstN(fn);
employees[i].SetLastN(ln);
employees[i].SetIdNum(id);
employees[i].SetWage(wg);
employees[i].SetWeekHrsWkd(arr);
  
}
bool stillContinue=true;
int choice=0;
while(stillContinue){
Console.WriteLine("Menu \n Choose from the list of employees");
for (int i=0;i<n;i++){
Console.WriteLine((i+1)+". "+employees[i].GetName());
}
               choice=Int32.Parse(Console.ReadLine())-1;
//if invalid option chosen, exit
if(choice==-1 || choice>=n)
stillContinue=false;
else
employees[choice].Properties();

}
}
}
}

OP:----------------------------------------------------------------------------------------------------

Input number employees:
1
Input FirstName of Employee #1
A
Input LastName of Employee #1
B
Input ID of Employee #1
1
Input A B's wage
45
Input A B's working hours for week 1 :
40
Input A B's working hours for week 2 :
56
Input A B's working hours for week 3 :
43
Input A B's working hours for week 4 :
21
Menu
Choose from the list of employees
1. A B
1
Name: A B
ID: 1

Total Pay is :7627.5
Regular Pay is :6345
OverTime Pay is :1282.5
Menu
Choose from the list of employees
A B

>

Add a comment
Know the answer?
Add Answer to:
Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variable...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly...

    If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly pay) If the employee is not a supervisor and she worked 40 hours or less calculate her paycheck as her hourly wage * hours worked (regular pay) If the employee is not a supervisor and worked more than 40 hours calculate her paycheck as her (hourly wage * 40 ) + (1 ½ times here hourly wage * her hours worked over 40) (overtime...

  • Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...

    Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The owners of the Annan Supermarket would like to have a program that computes the weekly gross pay of their employees. The user will enter an employee’s first name, last name, the hourly rate of pay, and the number of hours worked for the week. In addition, Annan Supermarkets would like the program to compute the employee’s net pay and overtime pay. Overtime hours, any...

  • Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main()...

    Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named Employee, and do not declare it public. Create a field for each of the following pieces of information: employee name, employee number, hourly pay rate, and overtime rate. Create accessor and mutator methods for each field. The mutator method for the hourly pay rate should require the value to be greater than zero. If it...

  • use visual studio, this is the step how to creat the project. creat new project in...

    use visual studio, this is the step how to creat the project. creat new project in the next page make sure to select visual C++ then empty project on the next dialog box. after you create new project click on add new item and then select C++ source file (cpp file) and click add. after you finish, make sure you send me the run file ( result) as well Write a program that calculates and prints the amount of wages...

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • C coding language is used. Write a program that declare parallel arrays for storing information about...

    C coding language is used. Write a program that declare parallel arrays for storing information about 10 employees. One array will store the hours each person worked for a week and a second array will store each person's weekly pay. Your program should ask the user for the number of hours each of the 10 employees worked. The pay should calculate both regular and overtime pay. Assume that all 10 employees earn $15.25 per hour. Your program should allow the...

  • I NEED ALL QUESTIONS OR ELSE THUMBS DOWN! C++ Implement a structure Employee. An employee has...

    I NEED ALL QUESTIONS OR ELSE THUMBS DOWN! C++ Implement a structure Employee. An employee has a name (a char *) and a salary (a double). Write a default constructor, a constructor with two parameters (name and salary), and methods char* getName() double getSalary() to return the name and salary. Write a small global function TestEmployee() to test your structure. Creating a new employee. Please type the name: Larry Bird Please specify the salary: 200000 New employee has been created....

  • J Inc. has a file with employee details. You are asked to write a C++ program...

    J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and...

  • Hello I am confused about this C++ program. I need to create a payroll C++ program...

    Hello I am confused about this C++ program. I need to create a payroll C++ program following these steps. Source file structure Your program will consist of three source files: main.cpp the main program Payroll.hppclass declaration for the Payroll class. Make sure you have an include guard. Payroll.cpp Payroll's member functions Class definition Create a Payroll class definition. The class has private members which originate from user input: number of hours worked hourly rate float float - and private members...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT