Calculate tax
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace Lecture61
{
public class Program
{
public static void Main()
{
//Creating objects
Taxpayer[] myArray = new Taxpayer[10];
int income;
int social = 1000;
//Assigning value
for (int i = 0; i < myArray.Length; i++)
{
Console.WriteLine("Enter money");
income = int.Parse(Console.ReadLine());
myArray[i] = new Taxpayer(income, social);
social++;
}
//printing output
for (int i = 0; i < myArray.Length; i++)
{
Console.WriteLine("\nSocial Num :{0}\nIncome : {1}\nTax : {2}", myArray[i].GetSecurity, myArray[i].GetIncome, myArray[i].GetTax);
}
}
public class Taxpayer
{
//Data Fields
private int SocialSecurityNumber;
private int YearlyGrossIncome;
private int TaxOwned;
//Constructor
public Taxpayer(int YearlyGrossIncome, int social)
{
this.SocialSecurityNumber = social;
Calculate(YearlyGrossIncome);
this.YearlyGrossIncome = YearlyGrossIncome;
}
//Method for calculating area
private void Calculate(int income)
{
if (income < 30000)
{
TaxOwned = (income * 15) / 100;
}
else
{
TaxOwned = (income * 28) / 100;
}
}
//GetSet Methods
public int GetSecurity
{
get { return SocialSecurityNumber; }
set
{
this.SocialSecurityNumber = value;
}
}
public int GetTax
{
get { return TaxOwned; }
}
public int GetIncome
{
get { return YearlyGrossIncome; }
set
{
this.YearlyGrossIncome = value;
Calculate(value);
}
}
}
}
}
Comments
Post a Comment