Hoping someone here can help, writing a program in c# that does simple calculation too someone salary, Having a problem with a method where it will multiply two numbers but wont subtract the third, it just outputs 700, it won't take the 700 off the salary, if ya get me.
The problem is in the method PayAfterTax, any help appreciated.
Code:
class Employee
{
public string employeeName;
public int employeeAge;
public string employeeDepartment;
public int employeeNumber;
public int weeklyHours;
public double taxRate;
public int yearsOfService;
public double monthlySalary;
public double TotalYearlyIncome = 0;
public int Months = 12;
public double Taxpaid = 0;
public Employee() {}
public Employee(string inEmployeeName,int inEmployeeAge,string inEmployeeDepartment,int inEmployeeNumber,int inWeeklyHours,double inTaxRate,int inYearsOfService,double inMonthlySalary,int inMonths,double inTaxPaid)
{
employeeName = inEmployeeName;
employeeAge = inEmployeeAge;
employeeDepartment = inEmployeeDepartment;
employeeNumber = inEmployeeNumber;
weeklyHours = inWeeklyHours;
taxRate = inTaxRate;
yearsOfService = inYearsOfService;
monthlySalary = inMonthlySalary;
Months = inMonths;
Taxpaid = inTaxPaid;
}
public void EmployeeDetails()
{
Console.WriteLine("Employee's Name :"+employeeName);
Console.WriteLine("Employee's Age :"+employeeAge);
Console.WriteLine("Employee's Department :"+employeeDepartment);
Console.WriteLine("Employee's Number :"+employeeNumber);
Console.WriteLine("Employee's Weekly Hours: :"+weeklyHours);
Console.WriteLine("Employee's Tax Rate :"+taxRate);
Console.WriteLine("Employee's Years of service :"+yearsOfService);
Console.WriteLine("Employee's Monthly Salary :" + monthlySalary + "\n");
}
public double CalYearlySalary(int Months, double monthlySalary)
{
return ( Months * monthlySalary);
}
public double TaxCalculation(double monthlySalary,double taxRate)
{
return (monthlySalary*taxRate);
}
public double PayAfterTax(double monthlySalary, double taxRate, double Taxpaid)
{
return(monthlySalary * taxRate) - Taxpaid;
}
}
}
Code:
class Program
{
static void Main(string[] args)
{
Employee a1 = new Employee("Kevin O Sullivan",31,"Software Writer",5667,39,0.20,5,3500,12,0);
a1.EmployeeDetails();
Console.WriteLine("Your yearly Salarly is :" + a1.CalYearlySalary(a1.Months, a1.monthlySalary) + "\n");
Console.WriteLine("The amount of tax you pay every Month is :"+a1.TaxCalculation(a1.monthlySalary, a1.taxRate)+"\n");
Console.WriteLine("Your take home pay is: " + a1.PayAfterTax(a1.monthlySalary,a1.taxRate,a1.Taxpaid));
Employee b2 = new Employee("Mary Murphy",28,"Software Writer",5442,39,0.20,6,3600,12,0);
b2.EmployeeDetails();
Employee c3 = new Employee("John Cusack", 35, "Software Tester", 5876, 39, 0.20, 10, 4000,12,0);
c3.EmployeeDetails();
Employee d4 = new Employee("Teresa O Reilly",30,"Software Tester",5798,39,0.20,7,3800,12,0);
d4.EmployeeDetails();
Employee e5 = new Employee("Timmy Jones",35,"Payroll",6723,39,0.42,8,4200,12,0);
e5.EmployeeDetails();
Employee f6 = new Employee("Ciara O Mahony",40,"Head Accountant",4432,50,0.42,15,6000,12,0);
f6.EmployeeDetails();
Employee g7 = new Employee("Chris Murphy",43,"Technical Writer",3445,40,0.42,12,4500,12,0);
g7.EmployeeDetails();
Employee h8 = new Employee("Maire Higgins",49,"CEO/Manager",4214,55,0.42,25,7000,12,0);
h8.EmployeeDetails();
}
}
}
The problem is in the method PayAfterTax, any help appreciated.