We have been asked to work on a website that sells goods across the US. They need our team to build an app to calculate the sales tax for the items sold.
For this challenge we’ll be taking in information, running calculations, adding business logic, and then returning an output. At the basic levels it will be some mathematical calculations. At the higher levels we’ll be looking up information in tables and determining what path the app follows based on input.
No matter the level you choose to work with write a test case before you start your code. Then write just enough code to pass the test. Once you have passing code refactor to pass other test cases.
To start off, build an app that takes in both the cost of the item or total costs of items and the sales tax percent to calculate. It should return the total after adding taxes to the purchase.
Hint: Total = price + (price * tax percent / 100)
Going a step further, display the cost of the item or items, the amount of tax, and the total after tax that the customer is spending.
Output for a $10 item with an 8% tax rate:
Instead of passing in the sales tax for an area the app we are working on will be taking in the name and address, including city and state, of the purchaser. From this information look up the tax percentage from a table based on the location of the buyer. Make sure to return the item cost, tax amount, and total cost.
Use the combined rate from this website for each state. https://taxfoundation.org/state-local-sales-tax-rates-midyear-2018/
Hint: The simplest way to use this information is to copy and hard code it into your application. Worry about making it adjustable after you get the functionality working.
Going a step further, many larger cities have a city sales tax on top of the state sales tax. Instead of using the state’s average local tax calculate the specific taxes for the location of the buyer based on the address they input.
For simplicity of this challenge use the major cities in this link, if the one in the input isn’t listed then use the average from the previous link. https://taxfoundation.org/sales-tax-rates-major-cities-midyear-2017/
Hint: Total Tax = (State Tax + Local Tax) / 100; Total Cost = Price + Price * (State Tax + Local Tax) / 100;
The company that hired us to create these apps has decided to give a 10% discount to their employees. They want this to be a pre-tax discount. Create a list of employee names and when the user inputs a name check it against the list. If the input is for an employee apply the discount before adding the taxes. Make sure to return the cost of the item (after discount), amount of taxes, and total cost.
Hint: Discounted = Price - (Price * Discount / 100)
Going a step further add the ability to enter a discount code to receive a 5% post tax discount.