In: Computer Science
Create a C# Console Application, name the solution Homework 6 and the project TaxRate.
Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make sure that they input a correct value (e.g. you need to make sure that salary is a double). If it is invalid, keep prompting them to enter their salary until they comply.
For your Application, you will need to create AT LEAST 3 Methods/Functions (not including the Main method).
You need to create a Method namedCalculateFederalTax that will have areturn type of double and will accept 1 parameter of type doublethat will be used to determine the amount of Federal Taxes to be withheld. The method should determine which Federal tax bracket the individual belongs to and return the amount of Federal taxes to be withheld.
You need to create a Method namedCalculateFICATax that will have a return type ofdouble and will accept 1parameter of type double that will be used to determine the amount of FICA Taxes to be withheld. The method should return the amount of FICA taxes to be withheld.
You need to create a Method namedDisplayResults that will have a return type ofvoid and will accept 4parameters. The method will write a message on the console with the users name, their salary, the amount of Federal Tax that will be withheld, the amount of FICA Tax that will be withheld and their net salary (their salary - all taxes that were withheld). Your parameters should be as follows:
Parameter 1 : Type string
Parameter 2 : Type double
Parameter 3 : Type double
Parameter 4 : Type double
Use the information below to figure out what percent to deduct from the users salary for each income tax:
Federal
Tax rate | Taxable income bracket |
---|---|
10% | $0 to $9,525 |
12% | $9,526 to $38,700 |
22% | $38,701 to $82,500 |
24% | $82,501 to $157,500 |
32% | $157,501 to $200,000 |
35% | $200,001 to $500,000 |
37% | $500,001 or more |
FICA - 6.2%
Program:
using System;
namespace taxRate
{
class Program
{
//method to
determine the amount of Federal Taxes to be withheld
public static
double CalculateFederalTax(double n)
{
if(n<=9525)
return
n*0.01;
if(n<=38700)
return
n*0.12;
if(n<=82500)
return
n*0.22;
if(n<=157500)
return
n*0.24;
if(n<=200000)
return
n*0.32;
if(n<=500000)
return
n*0.35;
return
n*0.37;
}
//method to
determine the amount of FICA Taxes to be withheld
public static
double CalculateFICATax(double n)
{
return
n*0.062;
}
//method to write a
message on the console
public static void
DisplayResults(string name, double salary, double fedtax, double
ficattax)
{
Console.WriteLine("Name:
" + name);
Console.WriteLine("Gross
Salary: " + salary);
Console.WriteLine("Federal
Tax: " + fedtax);
Console.WriteLine("FICA
Tax: " + ficattax);
double
netsalary = salary - fedtax - ficattax;
Console.WriteLine("Net
Salary: " + netsalary);
}
//main method
public static void
Main(string[] args)
{
//read name
Console.Write("Enter
Name: ");
string
name = Console.ReadLine();
//read salary
Console.Write("Enter
Salary: ");
double
salary;
while
(!double.TryParse(Console.ReadLine(), out salary))
{
Console.Write("Error!
Try again : ");
}
//calculate Federal Tax
double
fedtax = CalculateFederalTax(salary);
//calculate FICA Tax
double
ficattax = CalculateFICATax(salary);
//display the details
DisplayResults(name,
salary, fedtax, ficattax);
Console.ReadKey(true);
}
}
}
Output: