Answer to Question #134235 in C# for Tasawur Imam

Question #134235
1. Write the code of a class by the name of Person that contains attributes like name, age income etc and a method called calculatedTax(). All attributes should be private and use properties for read and write values for above mentioned attribues and a public method that calculates tax on the basis of a person’s income. If the income of the person is below 100, 000 it should say no tax applies on you. For income between 100,000 and 300, 000 15% tax should be displayed of the entered income amount. For income above 300, 000 25% should be displayed for the entered income amount. Write the complete code for the Person class and how the Person object is created and its method is called? The person object should be created by entering the required information in that should take input for the person’s name, age and income using properties ?
1
Expert's answer
2020-09-21T08:40:18-0400
using System;


namespace ConsoleApp11
{
    class Program
    {
        static void Main(string[] args)
        {
            Person noIncomePerson = new Person()
            {
                Name = "Billy",
                Age = 20,
                Income = 20000
            };


            Person _15IncomePerson = new Person()
            {
                Name = "Max",
                Age = 25,
                Income = 100001
            };


            Person _25IncomePerson = new Person()
            {
                Name = "Jane",
                Age = 25,
                Income = 500000
            };


            noIncomePerson.CalculateTax();
            _15IncomePerson.CalculateTax();
            _25IncomePerson.CalculateTax();




            Console.Write("Press any key...");
            Console.ReadKey();
        }
    }


    class Person
    {
        string name;
        int age;
        decimal income;


        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        public decimal Income
        {
            get { return income; }
            set { income = value; }
        }


        public void CalculateTax()
        {
            if (Income < 100000)
            {
                Console.WriteLine($"{Name}, No tax applies on you");
            }
            else if (Income >= 100000 && Income <= 300000)
            {
                Console.WriteLine($"{Name}, You tax is 15%: {Income * 0.15M}");
            }
            else
            {
                Console.WriteLine($"{Name}, You tax is 25%: {Income * 0.25M}");
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS