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
--------------------------------------------------------------------OutPut----------------------------------------------------------------------------
Menu: Please Choose:
1. "John Doe"
2. "Jane Doe"
3. exit
1
John Doe Pay:
Regular Pay:50
Overtime Pay:50
Total Pay: 100
Menu: Please Choose:
1. "John Doe"
2. "Jane Doe"
3. exit
exit
this is for C#
CODE:
using System;
namespace EmployeeDemo
{
//Create a class Employee
class Employee
{
//Attributes
private string firstN;
private string lastN;
private string idNum;
private double wage;
private int weekHrsWkd;
private double regHrsAmt;
private double regPay;
private double otPay;
//Default constructor
public Employee()
{
regHrsAmt = 40;
}
//Getters and setters
public string FirstN
{
get
{
return firstN;
}
set
{
firstN = value;
}
}
public string IdNum
{
get
{
return idNum;
}
set
{
idNum= value;
}
}
public string LastN
{
get
{
return lastN;
}
set
{
lastN = value;
}
}
public double Wage
{
get
{
return wage;
}
set
{
wage = value;
}
}
public int WeekHrsWkd
{
get
{
return weekHrsWkd;
}
set
{
weekHrsWkd = value;
}
}
public double RegPay
{
get
{
return regPay;
}
}
public double OtPay
{
get
{
return otPay;
}
}
//Method to calculate pay in regular and over time
public void CalcPay()
{
if (weekHrsWkd <= regHrsAmt)
{
regPay = weekHrsWkd * wage;
otPay = 0;
}
else
{
regPay = regHrsAmt * wage;
otPay = (weekHrsWkd - regHrsAmt) * (1.5 * wage);
}
}
}
//Crete a class for check
class Demo
{
//Method to get menu choice
public static int menu()
{
Console.WriteLine("\n1.How much the person totally made\n"+
"2.How much of paycheck is regular pay\n"+
"3. How much of paycheck is overtime pay\n"+
"4. Exit\n");
Console.Write("Enter your choice: ");
int ch = Convert.ToInt32(Console.ReadLine());
while (ch<1 || ch > 4)
{
Console.WriteLine("ERROR!!!!Choice should 1-4!!\n");
Console.Write("Enter your choice: ");
ch = Convert.ToInt32(Console.ReadLine());
}
return ch;
}
static void Main(string[] args)
{
//Prompt for number of employees in the company
Console.Write("Enter the number of employees in the company:
");
int empCnt= Convert.ToInt32(Console.ReadLine());
//Error check in count
while (empCnt <= 0)
{
Console.WriteLine("ERROR!!!Count must be positive!!\n");
Console.Write("Enter the number of employees in the company:
");
empCnt = Convert.ToInt32(Console.ReadLine());
}
//Create a 2d array
Employee[,] employees = new Employee[empCnt,4];
//Loop through to get each employee details
for(int i = 0; i < empCnt; i++)
{
//Create an employee object
Employee employee = new Employee();
//Get name and id of employee
Console.Write("Enter employee " + (i+1) + " first name: ");
string fName = Console.ReadLine();
employee.FirstN = fName;
Console.Write("Enter employee " + (i + 1) + " last name: ");
string lName = Console.ReadLine();
employee.LastN = lName;
Console.Write("Enter employee " + (i + 1) + " id: ");
string id= Console.ReadLine();
employee.IdNum = id;
//Loop through to get 4 weeks pay and work hours details
for(int j = 0; j < 4; j++)
{
Console.Write("Enter employee " + fName + " week "+ (j + 1) + "
work hours: ");
int wkHrs= Convert.ToInt32(Console.ReadLine());
Console.Write("Enter employee " + fName + " week " + (j + 1) + "
wage per hour: ");
double wage = Convert.ToDouble(Console.ReadLine());
employee.Wage = wage;
employee.WeekHrsWkd = wkHrs;
//Calculate pay in each week
employee.CalcPay();
//Add into corresponding columns
employees[i, j] = employee;
}
}
//For user choice
int ch = menu();
//Loop until exit
while (ch != 4)
{
//Find total earning in a month
if (ch == 1)
{
Console.Write("Enter employee id: ");
string id = Console.ReadLine();
double wageTot = 0;
bool flag = false;
for(int i = 0; i < empCnt; i++)
{
if (employees[i, 0].IdNum == id)
{
for(int j = 0; j < 4; j++)
{
wageTot += employees[i, j].RegPay + employees[i, j].OtPay;
}
Console.WriteLine(employees[i, 0].FirstN + " " + employees[i,
0].LastN + " total wage in month = " + wageTot);
flag = true;
break;
}
}
if (flag == false)
{
Console.WriteLine("Employee id " + id + " not found in
company!!!\n");
}
}
//Find total earning in regular pay in a month
else if (ch == 2)
{
Console.Write("Enter employee id: ");
string id = Console.ReadLine();
double wageRegTot = 0;
bool flag = false;
for (int i = 0; i < empCnt; i++)
{
if (employees[i, 0].IdNum == id)
{
for (int j = 0; j < 4; j++)
{
wageRegTot += employees[i, j].RegPay;
}
Console.WriteLine(employees[i, 0].FirstN + " " + employees[i,
0].LastN + " total of regular pay in month = " + wageRegTot);
flag = true;
break;
}
}
if (flag == false)
{
Console.WriteLine("Employee id " + id + " not found in
company!!!\n");
}
}
//Find total earning in OT pay in a month
else if (ch == 3)
{
Console.Write("Enter employee id: ");
string id = Console.ReadLine();
double wageOtTot = 0;
bool flag = false;
for (int i = 0; i < empCnt; i++)
{
if (employees[i, 0].IdNum == id)
{
for (int j = 0; j < 4; j++)
{
wageOtTot += employees[i, j].OtPay;
}
Console.WriteLine(employees[i, 0].FirstN + " " + employees[i,
0].LastN + " total of Over time pay in month = " +
wageOtTot);
flag = true;
break;
}
}
if (flag == false)
{
Console.WriteLine("Employee id " + id + " not found in
company!!!\n");
}
}
ch = menu();
}
//Exit
Console.WriteLine("\nExititing from application.....");
}
}
}
You are to create a class object called “Employee” which included eight private variables: firstN...