Question

In: Computer Science

Write a program, called NationalTax, that will simulate calculating a citizen's income tax for the year....

Write a program, called NationalTax, that will simulate calculating a citizen's income tax for the year.

A country uses lettered ID's to identify its citizens. Valid ID's will be either 8 or 9 characters long. All characters entered will be alphabetic characters only (a-z or A-Z).

  • Display a welcome message.
  • Prompt the user for their ID and read it in.
  • Next, determine if the ID is valid based on its length.
    • If it is not valid, simply state that the ID is invalid and let the program end naturally (you may NOT use System.exit).
    • However, if it is valid, then do the following:
      • Prompt the user for the tax year (entered as a four-digit integer). No validity check needs to happen here.
      • Prompt the user for their annual income (this includes dollars and cents) and read it in. Since no annual income can be less than zero, if the user enters a negative amount, simply convert it to its positive amount. You may not use if/else statements here. Use the appropriate Math library method.
      • Convert the ID to all CAPS.
      • Display the ID.
      • Display the annual income as dollars and cents.
      • Set the tax amount to be log10 of their annual income multiplied by 100. Display this as their initial tax amount.
      • Then if the first character of the ID is in the range:
        • A - G, then the person works for the government. Reduce their tax by 10%. Display that they are a government employee, that they receive a 10% tax reduction, and display the new tax amount.
        • H - P, then the person works in the public sector. There is no tax reduction. Display they they are a public sector employee and that they receive no tax reduction.
        • Q - U, then the person is unemployed. Display that they are unemployed and that they receive no tax reduction.
        • Otherwise the person is retired. Reduce their tax by 25%. Display that they are retired, that they receive a 25% tax reduction, and display the new tax amount.
      • Then if the last character of the ID is greater than the first character:
        • the person is 21 years old or older. They pay an additional $100 in taxes. Add this to their current tax amount. Display that they are 21 years of age or older, that there is an additional $100 tax, and display the new tax amount.
        • Otherwise the person is less than 21 years old. There is no additional tax. Display that the are under 21 years of age and do not pay the additional tax.
      • Then if the ASCII value of the fifth letter (remember indexing starts at 0) of the ID (as a capital letter) is divisible by 7
        • that person is a millionaire. Their tax is the larger of the current tax amount and $15,000. Display that they are a millionaire, that their tax is the larger of their current tax amount (display the value) and $15,000, and display their new tax amount.
        • Otherwise they are not. Display nothing.
      • Then if the ID contains the string "MED" (remember case does not matter in the ID):
        • then they are a medical professional. Their tax is reduced by $100. Display that they are a medical profession, they their tax is reduced by 100, and display the new tax amount.  
        • Otherwise they are not. Display nothing.
      • Then if the final tax amount is negative, change it to 0.
      • Finally, in one printf statement, display a message that tells the user the ID, the tax year, their annual income, and their final tax amount owed.

Solutions

Expert Solution

The following is the python code for the requested scenario. I have checked all the test cases and it is working correctly. I have mentioned the comments in the code for better understanding.



ids = input("Please enter the id")
if(len(ids) > 9):
    print("ID invalid")
    exit()

tax_year = int(input("Enter the tax year"))
annual_income = float(input("Enter the annual income"))

#creating a positive annual income
annual_income = abs(annual_income)

#convert the income back to string to split it into a list
annual_income = str(annual_income)

#split the annual income into a list of dollars and cents
annual_income_list = annual_income.split(".")

#convert all the id letters to uppercase
ids = ids.upper()

print("The ID is " + ids)
print("The annual income is " + str(annual_income_list[0]) + " dollars and " + str(annual_income_list[1]) + " Cents")

#convert the annual income to float again
annual_income = float(annual_income)

#calculate initial tax
import math
initial_tax =  math.log10(int(annual_income)) * 100

print("The initial tax for your annual income is set to " + str(initial_tax))

# #split the id to get each letter as a list and save it in id_list
# id_list = ids.split()
# print(id_list)

#check for government employee i.e. A-G, retired employee etc.
if(ord(ids[0]) >= 65 and ord(ids[0]) <= 71):
    initial_tax = initial_tax - (1/10 * initial_tax)
    print("being a government employee, the tax has been reduced by 10%. The new tax is " + str(initial_tax))
    
elif(ord(ids[0]) >= 72 and ord(ids[0]) <= 80):
    print("You are a public sector employee, hence no tax deduction")
    
elif(ord(ids[0]) >= 81 and ord(ids[0]) <= 85):
    print("You are unemployed, hence no tax deduction")
    
else:
    initial_tax = initial_tax - (1/4 * initial_tax)
    print("being a retired employee, the tax has been reduced by 25%. The new tax is " + str(initial_tax))
    
#check for 21 years age and increase 100 dollars if ans is yes
if(ord(ids[0]) < ord(ids[len(ids) - 1])):
    initial_tax += 100
    print("being more than 20 years, the tax has been increased by $100. The new tax is " + str(initial_tax))

else:
    print("being less than 21 years, the tax will not be increased. The new tax is " + str(initial_tax))
    
#check for millionaire

if(ord(ids[5])%7 == 0):
    print("Your current tax is " + str(initial_tax))
    initial_tax = initial_tax + 15000
    print("being a millionaire, the tax will be increased by $15000. The new tax is " + str(initial_tax))
    
#check for medical professional

if "MED" in ids:
    initial_tax = initial_tax - 100
    print("being a medical professional, the tax will be reduced by $100. The new tax is " + str(initial_tax))

initial_tax = abs(initial_tax)

#display the final counts
print("For the user ID "+ ids+ " for the tax year "+ str(tax_year) + " and for the annual income of " + str(annual_income) + " the tax you have to pay is " + str(initial_tax))

You may notice that system.exit is used even though the question asked not to but the above program is not inside a function and hence cannot be exited without the use of exit. I did so because I do not know what python version you wanted.

Python 3 will take another syntax and python 2 another. Hence, I left it. All other things are same and works fine.


Related Solutions

What is the tax formula for calculating your tax liability every income year? Write the formula...
What is the tax formula for calculating your tax liability every income year? Write the formula out in full. Explain each element of the tax formula with reference to the relevant provisions of the ITAA97.
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a Java program to compute the income after tax of an employee based on the...
Write a Java program to compute the income after tax of an employee based on the following rule of tax rate. Assuming the salary is $22000, display the tax and the income after tax. 12% if salary ≥ 25,000 5% if salary < 10,000 Otherwise 8% will be applied Write a Java program to compute and display the sum of the numbers that can be both divisible by 6 and 8 from 1 to 500. Suppose there is a list...
please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X...
Overview For this assignment, write a program that uses functions to simulate a game of Craps....
Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT