Description of Program You are to write a program name cale.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a...


Description of Program<br>You are to write a program name cale.java that evaluates an infix expression entered by the user. The expression may contain the following tokens:<br>(1) Integer constants (a series of decimal digits).<br>(2) x (representing a value to be supplied later).<br>(3) Binary operators (+, -, *,/ and %).<br>(4) Parentheses<br>Spaces between tokens are allowed but not required. The program will convert the expression to postfix (RPN) form and display the converted expression. The program will repeatedly prompt the user for the value of x,<br>displaying the value of the expression each time. When the user enters the letter q instead of a number, the program terminates.<br>The following example illustrates the behavior of the program (user input is in bold and red):<br>Porgram output is in bold and green.<br>Enter infix expression: (x +1) * (x - 2) /4<br>Converted expression: x1+x 2-* 4/<br>Enter value of x: 5<br>Answer to expression: 4<br>Enter value of x: 7<br>Answer to expression: 10<br>Enter value of x: q<br>If the infix expression contains<br>a error of any kind, the program must display the message Error in expression (with an optional explanation) and then terminate. The following examples illustrate various types of errors:<br>Enter infix expression: 12+<br>Error in expression!! No operator between operands. Also last token must be an operand.<br>Enter infix expression: 10.4<br>Error in expression!! Cannot accept floating point numbers.<br>Enter infix expression: 1 ( +2)<br>Error in expression!! No operator between operand and left parentheses.<br>Enter infix expression: 5- (x - 2))<br>Error in expression!! No matching left parentheses for a right parentheses.<br>

Extracted text: Description of Program You are to write a program name cale.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits). (2) x (representing a value to be supplied later). (3) Binary operators (+, -, *,/ and %). (4) Parentheses Spaces between tokens are allowed but not required. The program will convert the expression to postfix (RPN) form and display the converted expression. The program will repeatedly prompt the user for the value of x, displaying the value of the expression each time. When the user enters the letter q instead of a number, the program terminates. The following example illustrates the behavior of the program (user input is in bold and red): Porgram output is in bold and green. Enter infix expression: (x +1) * (x - 2) /4 Converted expression: x1+x 2-* 4/ Enter value of x: 5 Answer to expression: 4 Enter value of x: 7 Answer to expression: 10 Enter value of x: q If the infix expression contains a error of any kind, the program must display the message Error in expression (with an optional explanation) and then terminate. The following examples illustrate various types of errors: Enter infix expression: 12+ Error in expression!! No operator between operands. Also last token must be an operand. Enter infix expression: 10.4 Error in expression!! Cannot accept floating point numbers. Enter infix expression: 1 ( +2) Error in expression!! No operator between operand and left parentheses. Enter infix expression: 5- (x - 2)) Error in expression!! No matching left parentheses for a right parentheses.
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here