Question: Write a method called getSum ( ) that takes one to three double parameters and returns the sum of these parameter ( s ) as
Write a method called getSum that takes one to three double parameters and returns the sum of these parameters as double. If any of the parameters is not an integer or a double, the program will catch an exception and print One or more arguments is not an int or a double.
When your code is ready, click the button below to submit your work for grading. FREEZE CODE BEGINS
import java.util.;
public class MethodOverloading
FREEZE CODE ENDS
FREEZE CODE BEGINS
public static void mainString args
try
ifargslength
double x Double.parseDoubleargs;
System.out.printlngetSumx;
ifargslength
double x Double.parseDoubleargs;
double y Double.parseDoubleargs;
System.out.printlngetSumx y;
ifargslength
double x Double.parseDoubleargs;
double y Double.parseDoubleargs;
double z Double.parseDoubleargs;
System.out.printlngetSumx y z;
FREEZE CODE ENDS
FREEZE CODE BEGINS
FREEZE CODE ENDS Click to compile your code
COMPILE CODE
codefinalMethodOverloadingjava:: error: 'try' without 'catch', 'finally' or resource declarations
try
codefinalMethodOverloadingjava:: error: illegal start of type
finally NumberFormatException e
errors
Test your code with a few different values
TEST WITH
Expected Output:
TEST WITH
Expected Output:
TEST WITH
Expected Output:
TEST WITH HELLO
Expected Output:One or more arguments is not an int or a double
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
