Design, implement, and test a JAVA program that read infix expressions from a file, [login to view URL], converts the infix expression to postfix notation, and evaluates the postfix expressions. We make the following Simplifying assumptions:
1) All operators and operands are one character long in the original infix expression
2) Allowable operators are +, -, *, / (integer division), ^ (exponentiation).
3) All operators are left associative
3) There are no unary operators
4) Each expression is contained on its own line withing the file
5) Parentheses can of course be used in normal fashion, and blanks should be allowed between symbols
The infix expressions below should be read into the program from a file, [login to view URL]
1: 8 + 4 * 2 - 6
2: 7 * 2 - 4 * 3 + 2 * 5
3: 2 * 3 * 4 - 8 + 9 / 3 /3
4: 5 + 7 * 4 - 6
5: 4 * ( 3 + 2 * 4) - 7
6: ( 5 + 7 ) / ( 9 - 5)
7: 3 * ( 5 * ( 5 - 2 ) ) - 9
8: ( ( 5 * ( 4 + 2 ) - ( 8 + 8 ) / 2 ) - 9 ) ^ 3
9: ( ( 5 + 5 * ( 6 - 2 ) + 4 ^ 2 ) * 8 )
10: ( ( ( 3 ^ 4 ) ) )
Be sure that the program outputs the original infix expression, its postfix equivalent, as well as the evaluation of the postfix expression. All outpout should be sent to a file called csis.txt.
The only stack class that should be used in this lab is the ObjectStack class that will be provided in a .txt file.
You should use at least the following classes and interface for the project.
Driver
ObjectStack
ObjectStackInterface
InfixToPostfix
EvalPostfix
The only user-defined static function should be main(). No floats, doubles, or scientific notation should be used.
The program should be able to handle the following ill-formed expressions, indicating that such an expression is erroneous, identifying the type of error, and going on to process the nest infix expression.
1 + * 2
1 2 * 3 ^ 4
( 1 + 2
( 1 + 2 ) * 3 )
You can use Java's Scanner class to open a file for input
Required declarations:
import java.io.*;
import [login to view URL];
public static void mains(String[] args) throws IOException {
To open a file for input and create a Scanner Object:
Scanner filescan = new Scanner(new File("[login to view URL]"));
To read a line from the file using the Scanner object:
while ([login to view URL]()) {
String buf = fileScan,nextLine();
To close the Scanner object:
[login to view URL]();
The conversion from infix to postfix will require the comparison of operator priorities. Here's a method that will take an operator as input and retunr its priority:
private int priority(char op) {
switch (op) {
case '^': return 3;
case '*':
case '/': return 2;
case '+':
case '-': return 1;
default : return 0;
}
}
Every class must have a Javadoc class comment
Every method must have a Javadoc method comment
Every method parameter must have an @param tag
Every method with a return statement must ahve an @return tag
Generate the HTML Javadoc documentation
Each data structure must implement an interface for that data structure. The interface files must be included.
Class Diagram:
Driver----> InfixToPostfix --->
| |
| ---> ObjectStack -----> <interface> ObjectStackInterface
| |
--> EvalPostfix ------>
Hello, I already did this assignment. The requirements were not exact but the gist is same. I can provide you the solution with your requirements within 12 hours.
I can show you my past work before you award project to me. Message me so that we can discuss on it.
I just read your project. but will you tell me about more. what you want. the source code or Exe file of this program. kindly send me more information . thank you