Question: JAVA Based We want to build a simple English language calculator that does the following: takes three inputs from the keyboard, two of them single
JAVA Based
We want to build a simple English language calculator that does the following: takes three inputs from the keyboard, two of them single digits (0 to 9) takes a char from the keyboard, representing one of five operations from the keyboard: + (addition), (subtraction), * (multiplication), / (division), and ^ (exponentiation) outputs the description of the operation in plain English, as well as the numeric result For instance, if the two numbers are 5 and 3, and the operation is *, then the output should be five multiplied by three is 15 Note that the result is given as a number, not a word. If the two numbers are 2 and 9, and the operation is , then the output should be two minus nine is -7 If the two numbers are 5 and 2, and the operation is ^, then the output should be five to the power two is 25 (Hint: to perform the exponentiation, use the pow method of the Math class.) If the two numbers are 5 and 0, and the operation is /, then the output should be Division by zero is not allowed Here the operation will not be performed. If the two numbers are 25 and 3, and the operation is +, then the output should be Invalid number because 25 has two digits. As for the operators, they should be translated into English as follows: + plus ? minus * multiplied by / divided by ^ to the power You should use the switch case selection statement to translate the input values into words. You need to consider these special situations: For division, there is a special constraint: you cannot divide by 0, and you should therefore test whether the second number is 0. If it is 0, then you should output a message saying that you are not allowed to divide by 0. You may use Exception handling using a try-catch block. The operator is not one of the preceding five operators; in that case, output a message saying that the operator is not a valid one. One or two of the numbers is not a valid digit; again, you should output a message to that effect. Hint: You can deal with these special situations in the default statement of the switch block and possibly use some boolean variables to keep track of this information, as you may need it later in your program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
