In Figure 6.5 on page 330, we presented a program to evaluate arithmetic expressions. In this exercise,
Question:
In Figure 6.5 on page 330, we presented a program to evaluate arithmetic expressions. In this exercise, you will write a similar program to evaluate boolean expressions. Rather than arithmetic operations, the input expressions for this program will use the operations && (the “and” operation), || (the “or” operation), and ! (the “not” operation). Rather than combining numbers, the input expression will combine simple boolean comparisons of numbers such as(1 < 2)and (6 < 3). Assume all the numbers in these simple comparisons are integers. Allow the following comparison operations: <, >, <=, >=, ==, and !=. At first assume that all boolean expressions are fully parenthesized and well formed. Be sure to note that “not” is a unary operation. You can assume that the argument to “not” (which follows the !) is enclosed in parentheses.
Your program should allow the user to evaluate additional expressions until the user wishes to end the program. For a more difficult assignment, enhance your program by adding any or all of the following features:
(a) The numbers need not be integers.
(b) The expression need not be fully parenthesized, and if parentheses are missing, then the Java precedence rules apply. (Note that innermost expressions such as (1 < 2) are still assumed to be in parentheses.)
(c) The expression need not be well formed, and if it is not well formed, then the user is asked to re-enter the expression.
Step by Step Answer: