Write a function in Java that calculates a total cost with tax and tip. Given three doubles: basePrice, taxRate (as a decimal, e.g., 0.08...
X1527: Calculate Total Cost
Write a function in Java that calculates a total cost with tax and tip. Given three doubles: basePrice, taxRate (as a decimal, e.g., 0.08 for 8%), and tipRate (as a decimal, e.g., 0.15 for 15%), calculate and return the total amount. The tax is applied to the base price, and the tip is calculated on the base price plus tax.
For example: basePrice = 20.0, taxRate = 0.08, tipRate = 0.15
Tax = 20.0 * 0.08 = 1.6
Subtotal = 20.0 + 1.6 = 21.6
Tip = 21.6 * 0.15 = 3.24
Total = 21.6 + 3.24 = 24.84
Your Answer:
Feedback
Your feedback will appear here when you check your answer.