Hi all!
I have some questions, I wanna ask you.
About changing infix expression to postfix expression
If I have 4 class
interface Expression {
public String toInfixString();
public String toSuffixString();
public double compute();
}
public enum typeOfExp {
Infix, Suffix
}
class Connect {
public static Expression createExp (String exp, typeOfExp type)
{
return null;
}
}
public class ExpRunner {
public static void main(String[] args)
{
//
Expression exp =
connect.createExp ("6.8+ 3/4-(9*2-1+5) +1.0)", typeOfExp.Infix);
System.out.println(exp.compute());
System.out.println(exp.toSuffixString());
}
}
- I don?t understand Connect class. CreateExp is the method of that class, and Expression in this case is the data type of this method? Is this right? So we can take place it of building the constructor of Expression class?
- Another question is how to get the String exp in class Connect to compute in the class implement Expression interface? :?> That is a String so have I to read every item in that string and put it into an interger array to compute by using stack? And if item of the array is a function as pow, sin, cos => how to traverse? I mean if the item is an Interger or operator, I can write is if(operator(item)) ( operator is the function I create)? but with pow, sin, cose how can I write?
I?m very bad at programming so if these questions are so stupid. Please don?t fret me.
Regard,