In: Computer Science
Write a java program that will first display the following menu: Choose one of the following 1- To add 2 double integers 2- To add 2 integer numbers 3- To add 3 double numbers 4- To add 3 integer numbers After reading user’s choice, use a switch case statement to call the corresponding method Void add 1 (double n1, double n2) Void add2() Double add3 (double n1, double n2, double n3) Double add4 ()
// Screenshot of the code & output
// Code to copy
Add.java
import java.util.Scanner;
public class Add {
public static void main(String[] args) {
Scanner userInput = new
Scanner(System.in);
System.out.println("Please enter
your choice.\n "
+ " 1- To add 2 double integers.\n "
+ " 2- To add 2 integer numbers.\n "
+ " 3- To add 3 double numbers.\n "
+ " 4- To add 3 integer numbers");
int n = userInput.nextInt();
switch(n){
case 1:
System.out.print("Enter first double : ");
double
num1=userInput.nextDouble();
System.out.print("Enter second double : ");
double
num2=userInput.nextDouble();
System.out.println("Sum of the two doubles: "+
add1(num1,num2));
break;
case 2:
System.out.print("Enter first integer : ");
int
num3=userInput.nextInt();
System.out.print("Enter second integer : ");
int
num4=userInput.nextInt();
System.out.println("Sum of the two intgers: "+
add2(num3,num4));
break;
case 3:
System.out.print("Enter first double : ");
double
num5=userInput.nextDouble();
System.out.print("Enter second double : ");
double
num6=userInput.nextDouble();
System.out.print("Enter third double : ");
double
num7=userInput.nextDouble();
System.out.println("Sum of the three doubles: "+
add3(num5,num6,num7));
break;
case 4:
System.out.print("Enter first integer : ");
int
num8=userInput.nextInt();
System.out.print("Enter second integer : ");
int
num9=userInput.nextInt();
System.out.print("Enter third integer : ");
int
num10=userInput.nextInt();
System.out.println("Sum of the three intgers: "+
add4(num8,num9,num10));
break;
default:
System.out.println("invalid
choice");
}
userInput.close();
}
private static double add1(double num1, double
num2) {
return num1+num2;
}
private static int add2(int num3, int num4)
{
return num3+num4;
}
private static double add3(double num5, double num6,
double num7) {
return num5+num6+num7;
}
private static int add4(int num8, int num9,int num10)
{
return num8+num9+num10;
}
}