Question: JAVA Calculator Program - Create program Calculator that accepts a single string as a console input. Write a method with exact method header as given:
JAVA Calculator Program - Create program Calculator that accepts a single string as a console input. Write a method with exact method header as given: public static double calculate(String inp). The string inp represents a single binary arithmetic operation is received in the main method and pass it as argument to method calculate. In the string inp, the operands and operator are separated by zero or more spaces. This method should perform the operation and return the result in double. You may assume that the strings will always be valid, however you will need to check Divide by zero error. When divide by zero error happens, print an Error message from the method. The main method will ask the user to input the string, call the method to operate on the string get the result and print the value.
Output Examples:
Run 1
Enter String:
1 + 3
The answer is 4.0
Run 2
Enter String:
12 / 0
Error!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
