Method Overloading: Tax Calculation
Problem Description
method overloading: Tax Calculation
In this problem, you will create a program that reads int, double, and String price values from Scanner, implements three overloaded methods accepting each type, calculates a 10% consumption tax, and displays the tax-included price to standard output.
Learning Objective: Use overloading to provide same functionality for different input types
Implement tax calculation methods for different data types (int, double, String) using method overloading. Implement calculation processing appropriate to each type: integer arithmetic for int, floating-point arithmetic for double, and string-to-number conversion before calculation for String. Tax rate is 10%.
Input
Read 3 lines:
- Line 1: int price
- Line 2: double price
- Line 3: String price (numeric string)
Output
Tax included(int): [result] yen
Tax included(double): [result] yen
Tax included(String): [result] yen
Examples
Example 1: Basic values
Input:
1000
1000.5
2999
Output:
Tax included(int): 1100 yen
Tax included(double): 1100.5500000000002 yen
Tax included(String): 3298 yen
Example 2: Different values
Input:
5000
2000.0
800
Output:
Tax included(int): 5500 yen
Tax included(double): 2200.0 yen
Tax included(String): 880 yen
Example 3: Boundary values
Input:
0
0.0
10000
Output:
Tax included(int): 0 yen
Tax included(double): 0.0 yen
Tax included(String): 11000 yen
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up