Question

In: Computer Science

Write a java program that will first display the following menu: Choose one of the following...

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 ()

Solutions

Expert Solution

// 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;
   }
}



Related Solutions

Write a simple airline ticket reservation program. The program should display a menu with the following...
Write a simple airline ticket reservation program. The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit on the number of flights. Create a linked list...
Write a C++ program to run a menu driven program with the following choices: 1) Display...
Write a C++ program to run a menu driven program with the following choices: 1) Display the grades 2) Adjust grade 3) Display Average for each student 4) Display number of student with at least a B 5) Quit requirements: 1. Write a function called getValidGrade that allows a user to enter in an integer and loops until a valid number that is >= 0 and <= 100 is entered. It returns the valid value. 2. Write a function called...
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
CIT 149 JAVA 1 programming question. The Assignment This program will display a menu to the...
CIT 149 JAVA 1 programming question. The Assignment This program will display a menu to the user from which they can choose an option to find the area of a rectangle, the area of a triangle, or to quit. The user will make the selection and will be prompted to enter the height and width, or the base and height, depending upon which selection they made. The program will then calculate the appropriate area and display the results. This program...
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names     &
Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close Do you...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
Write a python program to display a menu with the following options: (1) add, (2) subtract,...
Write a python program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. I f the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.
Java code for a binary tree that does the following:  Display a menu to the...
Java code for a binary tree that does the following:  Display a menu to the user and request for the desired option.  Based on the user’s input, request for additional information as follows: o If the user wants to add a node, request for the name (or ID) of the new node to be added as well as the name of the desired parent of that node.  If the parent node already has two children, the new...
Java code for a binary tree that does the following:  Display a menu to the...
Java code for a binary tree that does the following:  Display a menu to the user and request for the desired option.  Based on the user’s input, request for additional information as follows: o If the user wants to add a node, request for the name (or ID) of the new node to be added as well as the name of the desired parent of that node.  If the parent node already has two children, the new...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT