1
Answer

c# programming help homework 911 need it by 12 pm

Jenni Witzel

Jenni Witzel

16y
2.5k
1
This line of code:

Employee newEmployee = new Employee(hours, rate);

Should not be:

Employee newEmployee = new Employee(employeeName, hours, rate);

Because the constructor for the Employee class was expanded to include input of the employee name. As I mentioned last time, you need 3 parameters to create a newEmployee object now.

Also, don't forget to call the PrintName method to output the employee name as shown on the lab specifications. Get this in today (Saturday) and I won't count it late.




using System;
using SC = System.Console;

public class FLastLab07
{
public static void Main()
{
double hours, rate;
string employeeName, hoursStr, rateStr;

SC.WriteLine("Lab 7 – Your Name\n");
SC.Write("\nPlease input Employee Name: ");
employeeName = SC.ReadLine();

while (employeeName != "Quit")
{
SC.Write("\nPlease input hours worked: ");
hoursStr = SC.ReadLine();
SC.Write("\nPlease input rate of pay: ");
rateStr = SC.ReadLine();
hours = Convert.ToDouble(hoursStr);
rate = Convert.ToDouble(rateStr);

Employee newEmployee = new Employee(hours, rate);

newEmployee.CalculateGrossPay();
newEmployee.CalculateStateTax();
newEmployee.CalculateFederalTax();
newEmployee.CalculateFICATax();
newEmployee.CalculateNetPay();

SC.Write("\nPlease input Employee Name: ");
employeeName = SC.ReadLine();
} // end of loop
SC.WriteLine("\nEnd of Lab 7\n");
SC.ReadLine();
} // end of Main method
} // end of Main class


class Employee
{
private double hoursWorked, rateOfPay, grossPay, stateTax,
federalTax, ficaTax, netPay, overtimePay;

public Employee(double hrsWorked, double rate)
{
hoursWorked = hrsWorked;
rateOfPay = rate;
}

public void CalculateGrossPay()
{
grossPay = hoursWorked * rateOfPay;
if (hoursWorked > 40)
{
overtimePay = (hoursWorked - 40) * rateOfPay;
}
else
{
overtimePay = 0;
}
SC.Write("\nGross pay is:\t{0,10}", grossPay.ToString("C"));
SC.WriteLine(" (including Overtime: {0})", overtimePay.ToString("C"));
}

public void CalculateStateTax()
{
const double stateTaxRate = 0.04;
stateTax = grossPay * stateTaxRate;

SC.WriteLine("\nState tax is:\t{0,10}", stateTax.ToString("C"));
}

public void CalculateFederalTax()
{
const double federalTaxRate = 0.23;
federalTax = grossPay * federalTaxRate;

SC.WriteLine("\nFederal tax is:\t{0,10}", federalTax.ToString("C"));
}

public void CalculateFICATax()
{
const double ficaTaxRate = 0.14;
ficaTax = grossPay * ficaTaxRate;

SC.WriteLine("\nFICA tax is:\t{0,10}", ficaTax.ToString("C"));
}

public void CalculateNetPay()
{
netPay = grossPay - (stateTax + federalTax + ficaTax);
SC.WriteLine("\nNet pay is:\t{0,10}", netPay.ToString("C"));
}
} // end of Employee class
Answers (1)