0

I'm doing some hw and am currently stumped. It gives an interface and a class for ArrayStack and asks to write a code that converts infix to postfix. In my main method is this line

PostFixConverter(infixExpression);  

which calls to a method that calculates the postfix expression. My problem is that the class ArrayStack is not static but my main method is, so how can I resolve this?

Also,

Am I converting infix to postfix wrong by not making a new class that calculates postfix because all other code I've seen that does this has a separate class for it? Is there an advantage to doing it that way?

Thank You!

user207421
  • 305,947
  • 44
  • 307
  • 483
EmsandEms
  • 49
  • 3
  • 10

2 Answers2

0

Create Object of your class in main method like following and call non static(instance method)

ArrayStack arrayStack = new ArrayStack();                                        
arrayStack.postFixConverter(infixExpression);
AGdev
  • 616
  • 8
  • 12
0

For first query refer below:

public static void main (String[] args)
{
    String infixExpression = "Your infix string";
    PostFixConverter(infixExpression);  
}

private static void PostFixConverter(String infixExpression) 
{
    //your code goes here
}

For second query, it's your choice to do it that way.

sAm
  • 319
  • 2
  • 20
  • changed method to private static void PostFixConverter(String infixExpression){ and it now compiles!Thank You! However new problems have arisen. – EmsandEms Mar 03 '16 at 05:55
  • please share the issue. – sAm Mar 03 '16 at 05:59
  • My program is suppose to read from a file that has infix expressions, print them out, convert to postfix and print that out. Output Example: Infix expression = ((9/3)-2) Postfix expression = 93/2- The file reading is good. However when I run my program it prints out the infix expression and just keeps running. Nothing else happens. Would it help is I made question about it? – EmsandEms Mar 03 '16 at 06:04
  • you can add new question with code snippet. – sAm Mar 03 '16 at 06:06
  • Fixed the running thing by adding else's to some if's. If I am stuck again I shall ask. Thanks! – EmsandEms Mar 03 '16 at 06:18