010-003-001

Method Overloading: Price Formatting

Easy

Problem Description

method overloading: Price Formatting

In this problem, you will create a program that defines overloaded formatPrice methods with three different parameter types (int, double, String), reads values from standard input, and displays a formatted price string for each type.

Learning Objective: Understand overloading that distinguishes methods by parameter type

Define formatPrice method with 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

integer value
decimal value
string value

Output

Price(int): [integer value]
Price(double): [decimal value]
Price(String): [string value]

Examples

Example 1: Basic values

Input:

1500
99.99
500

Output:

Price(int): 1500
Price(double): 99.99
Price(String): 500

Example 2: Different values

Input:

5000
2999.5
12000

Output:

Price(int): 5000
Price(double): 2999.5
Price(String): 12000

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
3000
1499.9
discount
Expected Output:
Price(int): 3000
Price(double): 1499.9
Price(String): discount
Normal case
Input:
750
3200.25
sale
Expected Output:
Price(int): 750
Price(double): 3200.25
Price(String): sale

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 10 free executions remaining