Final Price with a Tax Constant
Easyjava
Learn the Concept: ConstantsDeclare final double TAX_RATE = 0.18; and use it to add 18% tax to a price.
Input: one number — the price before tax.
Output: one line — the final price (price + price x TAX_RATE) rounded to two decimal places.
Example 1
Input
1000
Output
1180.00
- 0 <= price <= 10000000
- TAX_RATE is exactly 0.18
Hint 1
double finalPrice = price + price * TAX_RATE;
Hint 2
Format with "%.2f" and Locale.US.
The 18% rate lives in one named constant, so the intent is obvious and it can only be set once. Rounding to two decimals with String.format hides any tiny floating-point noise in the multiplication.
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Circle Area with a PI ConstantEasy · javaSolve Problem
- Seconds in N DaysEasy · javaSolve Problem
- Weeks to DaysEasy · javaSolve Problem