Question

In: Computer Science

Define a problem with user input, user output, Switch and some mathematical computation. Write the pseudocode,...

Define a problem with user input, user output, Switch and some mathematical computation. Write the pseudocode, code and display output.

Include source code and output. If no output explain the reason why and what you are going to do make sure it does not happen again aka learning from your mistakes.

Problem:
Pseudocode:
Code:
Output:

Solutions

Expert Solution

Problem : Find the Addition , Subtraction , Multiplication and Division using the Switch statement

Pseudocode :

Step 1: int select (for select the operation)
Step 2: Operation type:
       1. Enter 1 for  Addition
       2. Enter 2 for  subtraction
       3. Enter 3 for multiplication
       4. Enter 4 for Division
Step 3: Double x1,x2 ,result
Step 4: Enter the first value
Step 5: Enter the second value
Step 6: Use Switch statement.
Step 7: Switch(select)
        {
          case 1:
              result= x1+x2;
              print(result);
          case 2:
              result = x1-x2;
              print(result);
          case 3:
              result=x1*x2;
              print(result);
          case 4:
              result=x1/x2;
              print(result);
         default:
            print("Select valid option");
         }

Code:

import java.util.Scanner;

class Test {
    public static void main(String[] args) {

        int select;
        Double x1, x2, result;
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter value for performing the operation");
        System.out.println("Enter 1 for Addition (+)");
        System.out.println("Enter 2 for Subtraction(-)");
        System.out.println("Enter 3 for Multiplication (*)");
        System.out.println("Enter 4 for Division (/)");
        select = scanner.nextInt();
        System.out.println("Enter first value");
         x1 = scanner.nextDouble();
        System.out.println("Enter Second Value");
        x2 = scanner.nextDouble();

        switch (select) {

            case 1:
                result = x1 + x2;
                System.out.print(x1 + "+" + x2 + " = " + result);
                break;

            case 2:
                result = x1 - x2;
                System.out.print(x1 + "-" + x2 + " = " + result);
                break;

            case 3:
                result = x1 * x2;
                System.out.print(x1 + "*" + x2 + " = " + result);
                break;

            case '/':
                result = x1 / x2;
                System.out.print(x1 + "/" + x2 + " = " + result);
                break;

            default:
                System.out.println("Please select valid option");
                break;
        }
    }
}

Output:

Thank you.................


Related Solutions

Define a problem with user input, user output, While Statement and some mathematical computation. Write the...
Define a problem with user input, user output, While Statement and some mathematical computation. Write the pseudocode, code and display output.
Define a java problem with user input, user output, Do While Statement and some mathematical computation....
Define a java problem with user input, user output, Do While Statement and some mathematical computation. Write the pseudocode, code and display output.
Define a problem with user input, user output, -> operator and destructors. C ++ please
Define a problem with user input, user output, -> operator and destructors. C ++ please
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For example if the user enters B a b e c o o d i u g o a l $ Then we have the output below: #A=2 #E=1 #I=1 #O=3 #U=2
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimeters (cm) and mass in kilograms (kg)of a person from his height in inches (in.) and weight in pounds (lb). (a) Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. (b) Determine your own height and weight in SI units.
5. Take user input and give corresponding output. User will enter a sentence. The program will...
5. Take user input and give corresponding output. User will enter a sentence. The program will output the word that appears most frequently in this sentence. If there are multiple words with same frequency, output the first of these words. Please enter a sentence: I like batman because batman saved the city many times. The most frequent word is: batman The frequency is: 2 PYTHON
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT