010-003-006
Method Overloading: Price Formatting
Easy
Problem Description
method overloading: Price Formatting
In this problem, you will create a program that defines three overloaded formatPrice methods accepting different parameter types (int, double, and String), reads values from standard input, and displays formatted price output for each type.
Learning Objective: Understand overloading that distinguishes methods by parameter type
Define the formatPrice method with the same name but different parameter types (int, double, String) to format price data. Learn that the method to call is automatically selected based on argument type.
Input
3 lines as follows:
- Line 1: an integer value (int)
- Line 2: a decimal value (double)
- Line 3: a string value (String)
Output
Price(int): [integer value]
Price(double): [decimal value]
Price(String): [string value]
Examples
Example 1:
Input:
1500
99.99
500
Output:
Price(int): 1500
Price(double): 99.99
Price(String): 500
Example 2:
Input:
5000
2999.5
12000
Output:
Price(int): 5000
Price(double): 2999.5
Price(String): 12000
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