难以根据人们的收入和申报状态在文本文件中分配所欠税款
本文关键字:文件 文本 状态 分配 | 更新日期: 2023-09-27 18:31:44
我无法弄清楚如何在我使用的文本文件中进行欠税计算。 当我运行该程序时,它会显示每个人的收入和申报状态,但所欠税款没有显示。
class Program
{
static void Main(string[] args)
{
Customers.CustomerTax(DataIO.TextFileToString(@"C:'Users'Matt'Desktop'tax.txt"));
foreach (Customers item in Customers._taxList)
{
Console.WriteLine(item.ToString());
FilingStatus fs = (FilingStatus)Enum.Parse(typeof(FilingStatus), "Single");
}
}
}
这是我进行计算的地方
class Customers
{
String _marriage;
double _income;
double _taxOwed;
private FilingStatus _filingstatus;
public static List<Customers> _taxList = new List<Customers>();
public Customers(String marriage, int income)
{
Income = income;
Marriage = marriage;
}
public String Marriage
{
get { return _marriage; }
set
{
_marriage = value;
}
}
public double Income
{
get { return _income; }
set
{
if (value <= 0)
{
throw new ArgumentException(String.Format("{0} must be > 0", value));
}
_income = value;
}
}
public double CalculateTax()
{
double taxOwed = 0.0;
if (_filingstatus == FilingStatus.Single)
{
if (Income <= TaxCalculations.Single10)
{
taxOwed = .1 * Income;
}
else if (Income <= TaxCalculations.Single15)
{
taxOwed = .15 * Income;
}
else if (Income <= TaxCalculations.Single25)
{
taxOwed = .25 * Income;
}
else if (Income <= TaxCalculations.Single28)
{
taxOwed = .28 * Income;
}
else if (Income <= TaxCalculations.Single33)
{
taxOwed = .33 * Income;
}
else if (Income <= TaxCalculations.Single35)
{
taxOwed = .35 * Income;
}
else Console.WriteLine("Derp");
}
else if (_filingstatus == FilingStatus.MarriedJoint)
{
if (Income <= TaxCalculations.MarriedJoint10)
{
taxOwed = .1 * Income;
}
else if (Income <= TaxCalculations.MarriedJoint15)
{
taxOwed = .15 * Income;
}
else if (Income <= TaxCalculations.MarriedJoint25)
{
taxOwed = .25 * Income;
}
else if (Income <= TaxCalculations.MarriedJoint28)
{
taxOwed = .28 * Income;
}
else if (Income <= TaxCalculations.MarriedJoint33)
{
taxOwed = .33 * Income;
}
else if (Income <= TaxCalculations.MarriedJoint35)
{
taxOwed = .35 * Income;
}
else Console.WriteLine("Derp");
}
else if (_filingstatus == FilingStatus.MarriedSeparate)
{
if (Income <= TaxCalculations.MarriedSeparate10)
{
taxOwed = .1 * Income;
}
else if (Income <= TaxCalculations.MarriedSeparate15)
{
taxOwed = .15 * Income;
}
else if (Income <= TaxCalculations.MarriedSeparate25)
{
taxOwed = .25 * Income;
}
else if (Income <= TaxCalculations.MarriedSeparate28)
{
taxOwed = .28 * Income;
}
else if (Income <= TaxCalculations.MarriedSeparate33)
{
taxOwed = .33 * Income;
}
else if (Income <= TaxCalculations.MarriedSeparate35)
{
taxOwed = .35 * Income;
}
else Console.WriteLine("Derp");
}
else if (_filingstatus == FilingStatus.HeadOfHouse)
{
if (Income <= TaxCalculations.HeadOfHouse10)
{
taxOwed = .1 * Income;
}
else if (Income <= TaxCalculations.HeadOfHouse15)
{
taxOwed = .15 * Income;
}
else if (Income <= TaxCalculations.HeadOfHouse25)
{
taxOwed = .25 * Income;
}
else if (Income <= TaxCalculations.HeadOfHouse28)
{
taxOwed = .28 * Income;
}
else if (Income <= TaxCalculations.HeadOfHouse33)
{
taxOwed = .33 * Income;
}
else if (Income <= TaxCalculations.HeadOfHouse35)
{
taxOwed = .35 * Income;
}
else Console.WriteLine("Derp");
}
else Console.WriteLine("Not a Valid Filing Status");
return taxOwed;
}
public static void CustomerTax(String s)
{
String[] customersArr = s.Split(''n');
foreach (string item in customersArr)
{
if (item.Equals("")) continue;
String[] customer = item.Split(',');
Customers p = new Customers(customer[1], int.Parse(customer[0]));
_taxList.Add(p);
}
}
public override string ToString()
{
return String.Format("Income: {0} Marriage Status: {1} Tax Owed: {2}", _income, _marriage, _taxOwed);
}
}
}
流读取器,数据 IO
class DataIO
{
public static String TextFileToString(String path)
{
String output = "";
String record = "";
using (StreamReader sr = new StreamReader(path))
{
while ((record = sr.ReadLine()) != null)
{
output += record + "'n";
}
}
return output;
}
}
也许是你的ToString函数有问题?
public override string ToString()
{
return String.Format("Income: {0} Marriage Status: {1} Tax Owed:", _income, _marriage, _taxOwed);
}
应如下所示:为格式字符串中的第三个参数添加大括号?
public override string ToString()
{
return String.Format("Income: {0} Marriage Status: {1} Tax Owed: {2}", _income, _marriage, _taxOwed);
}