Has to be written in C#! Write a program that includes an Employee class that can be used to calculate and print the take-home pay for a commissioned sales employee. Items to include as data members are employee number, first name, last name, and total sales. All employees receive 9% of the total sales of the month. Federal tax rate is 18%. Retirement contribution is 10%. Social Security tax rate is 6%. Use appropriate constants, design an object-oriented solution, and write constructors. Include at least one mutator and one accessor method; provide properties for the other data members. Create a second class, or a driver program, to test your design. Allow the user to enter values for the name of the employee and the sales amount for the month in the driver program as “Mike”, “Johnson”, and $50,000.
C# Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace commissionedSalesEmployee
{
//Class definition
class Employee
{
//Member Variables
private int
empNumber;
private String
fName;
private String
lName;
private double
totalSales;
public const int
FederalTaxRate = 18;
public const int
RetirementContribution = 10;
public const int
SocialSecurityTaxRate = 6;
//Default
Constructor
public Employee()
{
empNumber = 0;
fName = "";
lName = "";
totalSales = 0.0;
}
//Parameterized
constructor
public Employee(int eNo,
String efName, String elName, double sales)
{
empNumber = eNo;
fName = efName;
lName = elName;
totalSales = sales;
}
//Setter
methods
public void
setFirstName(String efName)
{
fName = efName;
}
//Getter
methods
public void
setLastName(String elName)
{
lName = elName;
}
//Setter
methods
public void setEmpNo(int
eNo)
{
empNumber = eNo;
}
//Setter
methods
public void
setSales(double sales)
{
totalSales = sales;
}
//Getter method
public int
getEmpNo()
{
return empNumber;
}
//Getter method
public String
getfName()
{
return fName;
}
//Getter method
public String
getlName()
{
return lName;
}
//Getter method
public double
getSales()
{
return totalSales;
}
public double
computeTakeHomePay()
{
double pay;
//9% of total sales
pay = (9 / 100.0) * totalSales;
//Federal tax rate is 18%
pay = pay - (pay * (FederalTaxRate / 100.0));
//Retirement Contribution is 10%
pay = pay - (pay * (RetirementContribution / 100.0));
//Social security tax rate is 18%
pay = pay - (pay * (SocialSecurityTaxRate / 100.0));
return pay;
}
}
//Driver class
class Program
{
//Main method
static void
Main(string[] args)
{
//Creating employee object
Employee emp = new Employee(123, "Mike", "Johnson", 50000);
//Printing Employee details
Console.WriteLine("\n Employee Number: " +
emp.getEmpNo().ToString());
Console.WriteLine("\n First Name: " + emp.getfName());
Console.WriteLine("\n Last Name: " + emp.getlName());
Console.WriteLine("\n Total Sales: $" +
emp.getSales().ToString());
Console.WriteLine("\n\n Take Home Pay: $" +
emp.computeTakeHomePay().ToString() + " \n\n");
Console.ReadKey();
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sample Output:
Get Answers For Free
Most questions answered within 1 hours.