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
  • Within c++ Create a simple Employee class with name, department, and title. Create an hourlyEmployee class...

    Within c++ Create a simple Employee class with name, department, and title. Create an hourlyEmployee class (which inherits from the Employee class) for a basic payroll program to compute the net pay salary of hourly based employees. Your program should also find the average net pay for a small company. To define the class, include the appropriate data members, member functions, constructors, and access modifiers. For simplicity, use a constant tax rate of 30% to compute the tax amount. Employees...

  • 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...

  • The following needs to be in C programming ! Outcomes: Demonstrate the ability to design a...

    The following needs to be in C programming ! Outcomes: Demonstrate the ability to design a menu driven program. Demonstrate the ability to reuse previous code to create a new assignment. Demonstrate the ability to use appropriate program logic. Program Specifications: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program...

  • Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses...

    Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program The program will reuse the DATE struct from the previous assignment.  You should also copy in the functions relating to a DATE. The program will create a PAYRECORD struct with the following fields: typedef struct...

  • 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....

  • 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 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...

  • 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...

  • 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...

  • employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name;...

    employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name; std::string address; std::string phoneNum; double hrWage, hrWorked; public: Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo); std::string getName(); void setName(std::string n); int getENum(); std::string getAdd(); void setAdd(std::string a); std::string getPhone(); void setPhone(std::string p); double getWage(); void setWage(double w); double getHours(); void setHours(double h); double calcPay(double a, double b); static Employee read(std::ifstream& in); void write(std::ofstream& out); }; employee.cpp ---------- //employee.cpp #include...

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