Overloading: Distinguishing by Argument Type
Problem Description
Overloading: Distinguishing by Argument Type
In this problem, you will create a program that implements two overloaded add methods in a Calculator class—one accepting int arguments and one accepting double arguments—and calls the appropriate method based on the input operation type to display the sum to standard output.
Learning Objective: Understand overloaded methods with different argument types
Implement two versions of the add method in the Calculator class. The integer version takes two int arguments and returns their sum. The double version takes two double arguments and returns their sum. Read the operation type (int or double) from input, call the corresponding overloaded method, and print the result in the specified format.
Input
Line 1: Operation type (int or double)
Line 2: First number
Line 3: Second number
Output
Int: Sum (int): [integer sum]
Double: Sum (double): [decimal sum]
Example
Input:
int
5
3
```java
Output:
```java
Sum (int): 8
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