我的目标是使用asp.net,c#和html根据应税收入计算联邦所得税。以下是我到目前为止编码的内容。摘要:用户通过文本框输入年收入和受抚养人数量。每个受抚养人都有1000美元的扣除额。应税所得=年收入 - (家属人数* 1000)。我需要将应税收入乘以税率。
我在计算应税收入的这个价值时遇到了困难,仍然需要对计算按钮进行编码以完成它的工作。
Taxable Income Range and Tax Rate:
>450000 -- 39.6%.
>378000 and <=450000 -- 33%.
>192000 and <=378000 -- 28%.
>71000 and <=192000 -- 25%.
>15000 and <=71000 -- 15%.
<=15000 -- 10%.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Form1.aspx.cs" Inherits="WebApplication1.Form1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<div style="TEXT-ALIGN: center">
Enter your name here: <asp:TextBox ID="name" runat="server"></asp:TextBox>
<br /><br />
Annual Income: <asp:TextBox ID="income" runat="server"></asp:TextBox>
<br /><br />
Number of dependents: <asp:TextBox ID="dependents" runat="server"></asp:TextBox>
<br /><br />
<asp:Button ID="calculate" runat="server" Text="Calculate Tax" OnClick="calculate_Click" />
<br /><br />
Total Tax: <asp:TextBox ID="total" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
这是.cs,我还需要编辑_rates秒来代表应税收入和税率的上表。
namespace WebApplication1 {
}
public class IncomeTaxCalculator
{
protected List<KeyValuePair<double, int>> _rates = null;
protected IncomeTaxCalculator()
{
// Load from database.
_rates = new List<KeyValuePair<double, int>>();
_rates.Add(new KeyValuePair<double, int>(.10, 15000));
_rates.Add(new KeyValuePair<double, int>(.15, 15000));
_rates.Add(new KeyValuePair<double, int>(.25, 71000));
_rates.Add(new KeyValuePair<double, int>(.28, 192000));
_rates.Add(new KeyValuePair<double, int>(.33, 378000));
_rates.Add(new KeyValuePair<double, int>(.396, 450000));
}
public double Single(int income)
{
double tax = 0;
for (int i = _rates.Count - 1; i >= 0; i--)
{
if (income > _rates[i].Value)
{
tax += (income - _rates[i].Value) * _rates[i].Key;
income = _rates[i].Value;
}
}
return tax;
}
// Singletone
protected static IncomeTaxCalculator _instance = null;
public static IncomeTaxCalculator Instance
{
get
{
if (_instance == null)
{
_instance = new IncomeTaxCalculator();
}
return _instance;
}
}
}
public partial class Form1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(IncomeTaxCalculator.Instance.Single(40000).ToString("C"));
}
protected void calculate_Click(object sender, EventArgs e)
{
}
}
答案 0 :(得分:1)
Form1没有Instance
。你可能想:
Response.Write(IncomeTaxCalculator.Instance.Single(40000).ToString("C"));