In: Computer Science
Using BASH.
It’s that wonderful joyful time of the year again. That’s right! It’s Tax Time! You have been hired by CIT Taxing & Associates to develop a script that will take in a person's gross income and total taxes paid to Uncle Sam (the federal government) and spit out that person’s tax bracket and total taxes that he/she owes. To complete the script you will need to use an IFstatement as well as follow these guidelines:
● Name The Script: tax_man
● Prompt the user for their GROSS Income
● Prompt the user for total FEDERAL taxes already paid by wage garnishes.
● Using a IF STATEMENT use the following tax information to determine how much the person owes or is
owed
Gross Pay | Tax Rate |
$0 - $15,000 | 0% |
$15,001 - $60,000 | 5% |
$60,001 - $85,000 | 10% |
$85,001 - $200,000 | 20% |
$200,001 + (DEFAULT) | 25% |
● To determine how much is owed to the government (or how much is owed to the user), use the following equation: $ (( ( gross_pay * tax_rate ) - already_paid ))
● Finally, For The Final Tax Bracket ($200,001+), make this theELSE Code Block For The IF Statement
● In order to handle decimals, we need to use the bc command. When making your equation, format your equation as follows: amount=$(echo “scale=2; ($gross_pay *$ tax_rate) - $already_paid” | bc)
#bash script
#!/bin/bash
# Reading gross pay from user
read -p 'Enter Your Gross Pay: ' gross_pay
# Reading federal taxes already paid from user
read -p 'Enter the amount of federal taxes already paid: '
already_paid
# Gross pay: $0 - $15,000 -> 0%
if [ $gross_pay -ge 0 -a $gross_pay -le 15000 ]; then
# tax rate is 0
tax_rate=0
rate=0
# Gross pay: $15,001 - $60,000 -> 5%
elif [ $gross_pay -ge 15001 -a $gross_pay -le 60000 ]; then
# tax rate is 5
tax_rate=0.05
rate=5
# Gross pay: $60,001 - $85,000 -> 10%
elif [ $gross_pay -ge 60001 -a $gross_pay -le 85000 ]; then
# tax rate is 10
tax_rate=0.10
rate=10
# Gross pay: $85,001 - $200,000 -> 20%
elif [ $gross_pay -ge 85001 -a $gross_pay -le 200000 ]; then
# tax rate is 20
tax_rate=0.20
rate=20
# Gross Pay greater than $200,001 -> 25%
else
# tax rate is 25
tax_rate=0.25
rate=25
fi
#printing new line
echo ""
echo ""
# Calculating amount owed
amount=$(echo "scale=2; ($gross_pay * $tax_rate) - $already_paid" |
bc)
# Printing results
echo -n "You Owe: \$$amount"
#printing new line
echo ""
# Printing results
echo -n "Your Tax Rate is $rate% of your gross pay"
#printing new line
echo ""
echo ""