我得到这个错误在我的代码中,我试图让用户输入雇员的名字,他们赚了多少比收入通过所有的税收数学,然后给用户一个输出输入的姓名和拿回家的税款。我必须使用两个类。我哪里错了?请帮忙。Stackoverflowexception未处理。试图获取takehomepay价值
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace consoleapplication9
{
public class takehomepay
{
static void Main(String[] args)
{
const decimal commission = 0.7M; // Commision rate
const decimal federaltax = 0.18M; // federal tax rate
const decimal retirement = 0.10M; // retirement rate
const decimal socialsecurity = 0.06M; // social security rate
string employeeName;
decimal commcost = 0; // commision cost
decimal fedtaxcost = 0; // federal tax cost
decimal retirecost = 0; // retirement cost
decimal socseccost = 0; // social security cost
decimal totalwithholdingcost = 0; // total withholding
decimal takehomepay = 0; // amount taken home
decimal totalSales = 0;
Console.Write("\nEnter employees name: ");
employeeName = Console.ReadLine();
Console.Write("Enter the total sales amount for the week:");
totalSales = Convert.ToDecimal(Console.ReadLine());
var employee = new Employee(employeeName, totalSales);
Console.Write(employee);
Console.Read();
//Calculations
commcost = commission * totalSales;
fedtaxcost = federaltax * commcost;
retirecost = retirement * commcost;
socseccost = socialsecurity * commcost;
totalwithholdingcost = federaltax + retirement + socialsecurity;
takehomepay = commcost - totalwithholdingcost;
}
}
public class Employee
{
private string employeeName;
private decimal totalSales;
public Employee()
{
}
public Employee(string Name)
{
employeeName = Name;
}
public Employee(string Name, decimal Sales)
{
employeeName = Name;
totalSales = Sales;
}
public string EmployeeName
{
get
{
return employeeName;
}
set
{
employeeName = value;
}
}
public decimal takehomepay
{
get
{
return takehomepay;
}
set
{
takehomepay = value;
}
}
public override string ToString()
{
return "Employee: " + employeeName +
"\nTake home pay: " + takehomepay;
}
}
}
我改变了你的建议,但现在我得到的错误“一个得到或设置acceutor期望” public decimal takehomepay {get;设置;) { 得到 { return takehomepay; } set { takehomepay = value; } } } – 2014-09-26 05:24:16
@ nicko'connor删除最后一位,从字面上只是有'decimal takehomepay {get;设置;)'并且移除'{get {return takehomepay; } set {takehomepay = value; }}}' – 2014-09-26 05:26:37
请注意,它应该''而不是'''在'set'之后'' – 2014-09-26 05:29:39