Question: Write a complete Java program (consisting of one class comprised of main method and other specified value-returning methods) which will input from a provided file

Write a complete Java program (consisting of one class comprised of main method and other specified value-returning methods) which will input from a provided file a series of infix expression strings involving addition and multiplication on single-digit integer operands and then evaluate and output the result of each expression to a file. An example of an output line appears below:

THE VALUE OF THE EXPRESSION 6+9*(5*(3+4)) IS 321

Assume that each input expression is a valid expression. The following expression strings should be used as test data input for your program. You are encouraged to include additional expression strings in your input file to further exercise the algorithm:

5 (5) 3+4 3*5 5*(3+4) 3+4*5+6 2*(((4+2))) 6+9*(5*(3+4)) 7*3+5*6 1*2*3*4*5*6*7 (((((5))))) 1+2+3+4+5+6 (3*6+4)*(4+5*7) 3*((4+5*(1+6)+2))

The following BNF grammar notation describes the recursive structure of expressions involving addition and multiplication on the set of integers:

FILE ::= { LINE } LINE ::= EXPRESSION EXPRESSION ::= TERM { + TERM } TERM ::= FACTOR { * FACTOR } FACTOR ::= digit | ( EXPRESSION )

Your program will employ several Java value-returning methods. The basic logical design for each method is given on the following page. Be sure to follow the techniques of good programming style and use extensive comments to provide internal documentation of your source program.

Write a complete Java program (consisting of one class comprised of main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!