010-003-007
Method Overloading: Temperature Conversion
Easy
Problem Description
method overloading: Temperature Conversion
In this problem, you will create a program that defines three overloaded convertToFahrenheit methods (accepting int, double, and String parameters respectively) to convert Celsius to Fahrenheit and displays the results to standard output.
Learning Objective: Implement different processing by parameter type using overloading
Define convertToFahrenheit method with same name but different parameter types (int, double, String) to convert Celsius to Fahrenheit. Implement calculation processing for each type.
Input
3 lines of input:
- Line 1: integer Celsius temperature processed as int
- Line 2: decimal Celsius temperature processed as double
- Line 3: string Celsius temperature processed as String
Output
[celsius]C = [fahrenheit]F
Conversion formula: Fahrenheit = Celsius × 9/5 + 32
Examples
Example 1: Basic values
Input:
0
25.5
30
Output:
0C = 32F
25.5C = 77.9F
30C = 86.0F
Example 2: Different values
Input:
100
37.5
15
Output:
100C = 212F
37.5C = 99.5F
15C = 59.0F
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