Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

infix, postfix expression

843789Oct 29 2009 — edited Nov 1 2009
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,

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 29 2009
Added on Oct 29 2009
10 comments
318 views