Question

In: Computer Science

JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu...

JAVA PROGRAMMING

Hi! I need to create a calculator using do/while loop that calls a menu switch where the user choice the calculation type. In the switch each case calls a method to each type of calculation (addition/subtraction/division/multiply/ change set of numbers in the array) those methods sends back the result to be displayed in another method.

This application needs to hold the user input's numbers as an array.

Thanks for your time. It is a great help!

Solutions

Expert Solution

simple Java code to create a calculator using switch statements:

import java.util.Scanner;

public class JavaExample {

    public static void main(String[] args) {

        double num1, num2;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter first number:");

       
        num1 = scanner.nextDouble();
        System.out.print("Enter second number:");
        num2 = scanner.nextDouble();

        System.out.print("Enter an operator (+, -, *, /): ");
        char operator = scanner.next().charAt(0);

        scanner.close();
        double output;

        switch(operator)
        {
            case '+':
                output = num1 + num2;
                break;

            case '-':
                output = num1 - num2;
                break;

            case '*':
                output = num1 * num2;
                break;

            case '/':
                output = num1 / num2;
                break;

           
            default:
                System.out.printf("You have entered wrong operator");
                return;
        }

        System.out.println(num1+" "+operator+" "+num2+": "+output);
    }
}
Let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

Related Solutions

Java Programming - please read the description I need this description. Inside a do/ while loop...
Java Programming - please read the description I need this description. Inside a do/ while loop (while choice !='x') , create a method call that calls a switch menu with 3 cases for variable choice and X for exit application.(this is a user input) Each case calls other methods. One of those methods asks for user input float numbers to calculate addition. And the result return to another method that displays the result. Thanks for your help! Thanks for asking....
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to input two numbers using scanner class Print the instruction of the menu for the calculator program Ask user to press 0 to Quit Ask user to press 1 to Add Ask user to press 2 to Substract Ask user to press 3 to Multiply Ask user to press 4 to Divide Perform correct calcuation based on user inputs and print the result Print error...
(This is for java) I need to rewrite this code that uses a while loop. public...
(This is for java) I need to rewrite this code that uses a while loop. public class Practice6 {      public static void main (String [] args) {         int sum = 2, i=2;        do { sum *= 6;    i++;    } while (i < 20); System.out.println("Total is: " + sum); }
C programming. Explain by taking a programming example how do while loop is different from while...
C programming. Explain by taking a programming example how do while loop is different from while loop?
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4,...
Hello, I Have create this code and Tried to add do while loop but it gives...
Hello, I Have create this code and Tried to add do while loop but it gives me the error in string answar; and the areas where I blod So cloud you please help me to do ( do while ) in this code. // Program objective: requires user to input the data, program runs through the data,calcualtes the quantity, chacks prices for each iteam intered,calautes the prices seperatly for each item, and calculates the amount due without tax, and then...
I need the java code for a 4-function calculator app on android studio (do this on...
I need the java code for a 4-function calculator app on android studio (do this on android studio). Please make sure all the requirements shown below are followed (such as the error portion and etc). The topic of this app is to simply create a 4 function calculator which calculates math expressions (add, subtract, multiply, and divide numbers). The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button...
I need the java code for a 4 function calculator app on android studio (do this...
I need the java code for a 4 function calculator app on android studio (do this on android studio) - The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button - Implement the onclicklistener on the main activity - The calcuator should use order of operations (PEMDAS) - It should be able to continue from a previous answer (Ex: If you type 2+6 the calculator will display 8....
Create Python Code using a "for" loop and a "while" loop. You are starting a twelve...
Create Python Code using a "for" loop and a "while" loop. You are starting a twelve week program training to compete in a triathlon. The triathlon consists of three athletic events, 1.5 k swim, 40k bike, 10k run. In order to be prepared for the competition you want to print a training schedule. Starting with week 1 you will increase the distance of each activity so that you reach the race distance by week twelve. Due to rounding, you may...
Programming Language = JAVA I wanna make menu -driven using these items. 1. one 2. two...
Programming Language = JAVA I wanna make menu -driven using these items. 1. one 2. two 3. three 4. four 5. exit This program will read a txt data and will display them in console. text.txt 98765432,C,John,Smith,23 Church Ave,Central,2123,8,Valid 98765431,C,Joe,Smith,55 Church Street,Genzi,2323,0,Valid 98765430,C,Bob,Smith,23 Gong Road,Warambull,2443,0,Valid 98765429,C,Mike,Smith,42 Mike Street,Waterloo,2222,0,Valid 98765428,C,Juan,Smith,522 Banana steet,Bank,2423,2,Valid 98765427,C,Mike,Jones,232 Milemium lane,Sumrise,2753,13,Suspended 98765426,C,David,Smith,551 Russian Mountain ave,Kogara,2121,0,Valid 98765425,C,Sarah,Smith,123 Straight Street,Cronulla,2232,3,Valid 98765424,C,James,Smith,23 lane,Coroloa,2345,7,Valid 98765423,C,Mike,White,4 Loman Lane,Orange,2665,14,Suspended 98765422,C,Brendon,Fei,55 bal bay,sate,2757,0,Valid 98765421,C,Jian,Zhang,62 london Street,mango,2553,0,Valid 98765420,C,Choi,Saraha,11 hamberguer Street,kefece,2753,0,Valid 98765432,C,Godam,City,32 Kent Street,Maccus,2876,0,Valid when user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT