Question: 1. Redo Example 1. 2 in the book (the one covered in class about calculating the final price of an item).For this question, ignore the
1. Redo Example 1. 2 in the book (the one covered in class about calculating the final price of an item).For this question, ignore the luxury tax part of the question. To represent percentage, 5% means 5/100 (you can either) multiply by 0.05 or multiply by 5 and divide by 100. User provides the needed values. Have the output display the final price as a dollar amount. For example $16430.53
example 1.2
In this example, we design an algorithm that calculates the sales tax and the price of an item sold in a particular state.
The sales tax is calculated as follows: The states portion of the sales tax is 4%, and the citys portion of the sales tax is 1.5%. If the item is a luxury item, such as a car more than $50,000, then there is a 10% luxury tax.
To calculate the price of the item, we need to calculate the states portion of the sales
tax, the citys portion of the sales tax, and, if it is a luxury item, the luxury tax. Suppose
salePrice denotes the selling price of the item, stateSalesTax denotes the states sales tax, citySalesTax denotes the citys sales tax, luxuryTax denotes the luxury tax, salesTax denotes the total sales tax, and amountDue denotes the final price of the item.
To calculate the sales tax, we must know the selling price of the item and whether the item is a luxury item.
The stateSalesTax and citySalesTax can be calculated using the following formulas:
stateSalesTax = salePrice 0.04 citySalesTax = salePrice 0.015
Next, you can determine luxuryTax as follows:
if (item is a luxury item) luxuryTax = salePrice 0.1
otherwise luxuryTax = 0
Next, you can determine salesTax as follows: salesTax = stateSalesTax + citySalesTax + luxuryTax
Finally, you can calculate amountDue as follows: amountDue = salePrice + salesTax
The algorithm to determine salesTax and amountDue is, therefore:
-
Get the selling price of the item.
-
Determine whether the item is a luxury item.
-
Find the states portion of the sales tax using the formula:
stateSalesTax = salePrice 0.04
-
Find the citys portion of the sales tax using the formula:
citySalesTax = salePrice 0.015
-
Find the luxury tax using the following formula:
if (item is a luxury item) luxuryTax = salePrice 0.1
otherwise luxuryTax = 0
-
Find salesTax using the formula: salesTax = stateSalesTax + citySalesTax + luxuryTax
-
Find amountDue using the formula: amountDue = salePrice + salesTax
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
