In: Computer Science
Language: C#
Create a new Console Application. 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 named CalculateFederalTax that will have a return type of double and will accept 1 parameter of type double that 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 named CalculateFICATax that will have a return type of double and will accept 1 parameter 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 named DisplayResults that will have a return type of void and will accept 4 parameters. 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 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 Tax Rate = 6.2%
Added 6 Methods
Main
CalculateFederalTax
CalculateFICATax
DisplayResults
input (for take input)
print (for print results)
Code: (Text File also included in End)
Output:
Files:
Code:
using System;
// namespace declaration
namespace TaxAPP {
// Class declaration
class Calculator {
// Main Method
static void Main(string[] args) {
// Variable
declaration
string name;
double salary;
// Taking input
Name
print("Enter Your
Name:");
name = input();
// Taking Salary
Input and validating
print("Enter Your
Salary:");
while(true){ // Run
until user give valid salary
if (double.TryParse(Console.ReadLine(), out salary)) { // User gave
valid salary
double fedralTax = CalculateFederalTax(salary); // calculating
Federal Tax
double ficaTax = CalculateFICATax(salary); // Calculating Fica
Tax
DisplayResults(name, salary, fedralTax, ficaTax); //Printing
Results
break; // Breaking Loo[]
} else { //user gave an illegal input
print("Type Valid Salary!");
}
}
}
// Method for calculate federal Tax
private static double CalculateFederalTax(double
salary){
double
taxPercentage;
// determining which
Federal tax bracket the individual belongs
if (salary <=
9525){
taxPercentage = 10;
}else if (salary <=
38700){
taxPercentage = 12;
}else if (salary <=
82500){
taxPercentage = 22;
}else if (salary <=
157500){
taxPercentage = 24;
}else if (salary <=
200000){
taxPercentage = 32;
}else if (salary <=
500000){
taxPercentage = 35;
}else {
taxPercentage = 37;
}
return (taxPercentage
* salary)/100; // Calculating Federal Tax
}
// Method for calculate fica tax
private static double CalculateFICATax(double
salary){
return (6.2 *
salary)/100; // Calculating Fica Tax
}
// Method for print results
private static void DisplayResults(string name,
double salary, double fedralTax, double ficaTax){
print("Name: " +
name);
print("Salary: " +
salary);
print("FedralTax: " +
fedralTax);
print("FicaTax: " +
ficaTax);
print("Net Salary: " +
(salary - fedralTax - ficaTax));
}
// Method for take input
private static string input(){
return
Console.ReadLine();
}
// Method for print output
private static void print(string msg){
Console.WriteLine(msg);
}
}
}