Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Java program called Calculator.java that reads a line of an expression

ID: 3639143 • Letter: C

Question

Create a Java program called Calculator.java that reads a line of an expression with a binary operator (+, –,*,/) and two operands of double type. Your program should determine the execution result of the expression. The following shows a sample run of the program.

Enter an expression: 5.45 + 7.0
Result is 12.45
Try again? y
Enter an expression: 2.3 – 9.77
Result is -7.47
Try again? y
Enter an expression: 2.3
Input error
Try again? y
Enter an expression: 2.3 * 4.5.5
Input error
Try again? y
Enter an expression: 1.0 + * 2.0
Input error
Try again? n
Bye.

Explanation / Answer

import java.io.*; class Calculator { public static void main(String arg[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i,fl=0;double d1=0,d2=0,rslt=0;char cont='y'; while (cont=='y') { fl=0; System.out.print("Enter expression : "); String s=br.readLine(); if(iscorrect(s)==1) { for(i=0;i