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 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                                                      ...
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...
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...
Write an interactive Java class Project8Q3, that will display a menu with the available commands 'G',...
Write an interactive Java class Project8Q3, that will display a menu with the available commands 'G', 'D', and 'X'. If 'G' is selected, prompt the user for the ID of a president to display to the screen and then display the president's information. If 'D' is selected, display all the values in the LinkedHashMap to the user with their associated LinkedHashMap key. If 'X' is selected, exit the program. The class should have the method addPresident(id, lastName, firstName, middleInitial) which...
Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a...
Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a title Ask the user to enter the following values: The type of plane(Boeing 747 or Airbus A300) The number of passengers on board the Plane The number of crew aboard the plane The maximum number of people that can be carried by one liferaft assuming all the liferafts on the plane are the same size The actual number of liferafts that are available on...
Write a program that prompts the user for their first and lastname. Display the first...
Write a program that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user.Ask the user to input a phone number.The program checks which part of Colorado a phone number is from using the values below.If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none of the digits...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT