我很困惑在哪里做这个的数学部分,但我需要做的税*金额

本文关键字:金额 在哪里 学部 | 更新日期: 2023-09-27 18:09:03

我的问题:我需要能够做数学部分来计算税额*金额,我对在哪里放它感到困惑,感谢阅读这篇文章,并希望帮助我,我希望它来计算税后的金额,我有大部分的代码工作只是不是它的数学部分。

 static void Main(string[] args)
    {
        Taxpayer[] incometax = new Taxpayer[2];
        string socialsecurity;
        int income;
        int tax;
        int x;
        for (x = 0; x < incometax.Length; ++x)
        {
            GetData(out socialsecurity, out income, out tax);
            incometax[x] = new Taxpayer(socialsecurity, income, tax); 
        }
        Console.WriteLine("Sorted List:");
        for (x = 0; x < incometax.Length; ++x)
            Display(incometax[x]);
    }
    internal static void GetData(out string socialsecurity, out int income, out int tax)
    {
        string inputString;
        Console.Write("Enter Social Security Number: ");
        socialsecurity = Console.ReadLine();
        Console.Write("Enter Income: ");
        inputString = Console.ReadLine();
        income = Convert.ToInt32(inputString);
        Console.Write("Enter Tax: ");
        inputString = Console.ReadLine();
        tax = Convert.ToInt32(inputString);
    }
    internal static void Display(Taxpayer Tax)
    {
        Console.WriteLine("SSN: {0} Income: {1} Tax: {2}", Tax.SocialSecurityNumber, Tax.Income, Tax.Tax.ToString());
    }
}
    class Taxpayer
    {
        private string socialSecurityNumber;
        private int grossIncome;
        private int Incometax;
        public Taxpayer(string socialsecurity, int income, int tax)
        {
            socialSecurityNumber = socialsecurity;
            grossIncome = income;
            Incometax = tax;
        }
        public string SocialSecurityNumber
        {
            get { return socialSecurityNumber; }
            set { socialSecurityNumber = value; }
        }
        public int Income
        {
            get { return grossIncome; }
            set { grossIncome = value; }
        }
        public int Tax
        {
            get { return Incometax; }
            set { Incometax = value; }
        }
    }
}

我很困惑在哪里做这个的数学部分,但我需要做的税*金额

在Display方法中进行计算:

internal static void Display(Taxpayer Tax)
{
    Console.WriteLine("SSN: {0} Income: {1} Tax: {2} Total: {3}",
        Tax.SocialSecurityNumber,
        Tax.Income,
        Tax.Tax.ToString(),
        (Tax.Income * Tax.Tax).ToString("C"));
}

我把你的例子清理干净并添加了注释,我还添加了数学部分的例子。

    private static void Main(string[] args)
    {
        // Declare a list of income taxes
        List<Taxpayer> incometax = new List<Taxpayer>();
        // Set the loop input
        bool moreInput = true;
        // Do the loop
        while (moreInput)
        {
            // Ask for the social security number
            Console.Write("Enter Social Security Number: ");
            string socialsecurity = Console.ReadLine();
            // Ask for income
            Console.Write("Enter Income: ");
            int income = Convert.ToInt32(Console.ReadLine());
            // Ask for the txt
            Console.Write("Enter Tax: ");
            int tax = Convert.ToInt32(Console.ReadLine());
            // Create a new taxpayer
            incometax.Add(new Taxpayer(socialsecurity, income, tax));
            // Ask if we should keep going?
            Console.Write("Add another? true/false: ");
            moreInput = Convert.ToBoolean(Console.ReadLine());
        }
        // Order the list by social security number
        Console.WriteLine("Sorted List:");
        incometax = incometax.OrderBy(x => x.SocialSecurityNumber).ToList();
        // Display each taxpayer
        foreach (Taxpayer taxPayer in incometax)
        {
            taxPayer.Display();
        }
        // Read any key to hold the console open
        Console.ReadKey();
    }
}
internal class Taxpayer
{
    public Taxpayer(string socialsecurity, int income, int tax)
    {
        this.SocialSecurityNumber = socialsecurity;
        this.Income = income;
        this.Tax = tax;
    }
    public string SocialSecurityNumber { get; set; }
    public int Income { get; set; }
    public int Tax { get; set; }
    public int Amount
    {
        get
        {
            return this.Tax * this.Income;
        }
    }
    public void Display()
    {
        Console.WriteLine("SSN: {0} Income: {1} Tax: {2} Amout: {3}", this.SocialSecurityNumber, this.Income, this.Tax, this.Amount);
    }
}