Link to home
Start Free TrialLog in
Avatar of Eindoofus
Eindoofus

asked on

Is this code correct? I am receiving a compiler error. What can I do to fix it?

I'm at work and only have access to ideone.com for compiling code. I just attempted compile the following code one the site and I ran into a bunch of errors:

/**
 * Postfix expression evaluation 
 *
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'Class1'
 * created in the main() method.
 */
class PostFix
{
	/**
	 * The main entry point for the application. 
	 *
	 * @param args Array of parameters passed to the application
	 * via the command line.
	 */
	public static void main (String[] args)
	{
		Stack s = new LinkedStack();
		
		try {
			for (int i = 0; i < args.length; i++) {
				if (args[i].equals("+")) {
					int a = ((Integer) s.pop()).intValue();
					int b = ((Integer) s.pop()).intValue();
					s.push(new Integer(a + b));
				}
				else if (args[i].equals("-")) {
					int a = ((Integer) s.pop()).intValue();
					int b = ((Integer) s.pop()).intValue();
					s.push(new Integer(b - a));
				}
				else if (args[i].equals("*")) {
					int a = ((Integer) s.pop()).intValue();
					int b = ((Integer) s.pop()).intValue();
					s.push(new Integer(b * a));
				}
				else if (args[i].equals("/")) {
					int a = ((Integer) s.pop()).intValue();
					int b = ((Integer) s.pop()).intValue();
					s.push(new Integer(b / a));
				}
				else {
					s.push(new Integer(args[i]));
				}
			}
		
			System.out.println(((Integer) s.pop()).toString());
		}
		catch (StackException se) {
			se.printStackTrace();
		}
	}
}

Open in new window


And these are the errors I receive:

Main.java:13: cannot find symbol
symbol  : class LinkedStack
location: class PostFix
		Stack s = new LinkedStack();
		              ^
Main.java:44: cannot find symbol
symbol  : class StackException
location: class PostFix
		catch (StackException se) {
		       ^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

Open in new window


This code was given to me by an instructor. Is it incorrect? Is it missing an import statement? Are there other errors? How can I fix it so that it can compile?
Avatar of for_yan
for_yan
Flag of United States of America image

I guess there is no such standard class as LinkedStack

There is LiinkedList and Stack but no LinkedStack
ASKER CERTIFIED SOLUTION
Avatar of Venabili
Venabili
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial