data structure and algorithms
This homework in java program please read the instruction carefully and I attach the whole files......
A complete class Tokenizer and a partially complete class Calculator are provided. You are asked to complete the implementation of Calculator class by implementing the static method eval.
The argument for method eval is a string which is an expression that is in the same form as that when you type in a calculator. For example: 2+(3*(5-2)-4)*6 ------ infix notation
The output is just the result as a double. For example, if the input argument is 2+(3*(5-2)-4)*6 , then the output should be 32
Note:
1. You need to put Tokenizer and Calculator together to make it work.
2. You need to use infix2postifx method to convert the expression from infix format to postfix format before doing the calculation.
3. In order to do the calculation, you need to parse the postfix expression, since the method infix2postfix returns the postfix expression as a string.
There are two ways to tackle this problem:
a. There is a class StringTokenizer in java.util. You can use this class with space “ “ as the delimit to parse the expression.
b. Or you can modify the method infix2postfix to make it return a list of operands and operators (as strings) thus avoid using StringTokenizer.
public static double eval(String exp) {
//Implement this function
}
9 years ago
15
Purchase the answer to view it

- IPFix.zip
Purchase the answer to view it

- Explanation.txt
- array.rar
