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?
EindoofusAsked:
Who is Participating?
 
VenabiliConnect With a Mentor Commented:
LinkedStack and StackException are not standard Java classes.

So if the instructor gave you the code, he either expected you to write these two classes or had given them as well.

Creating a LinkedStack class is a standard excerise for Java but you might have done that earlier -- the code above is how to do post fix expressions evaluations using a LinkedStack.

So your choices are:
- check your notes and find the class
- ask the instructor
- create the classes yourself.

What is the correct action for you depends on what type of class you are taking and what is your assignment
0
 
for_yanCommented:
I guess there is no such standard class as LinkedStack

There is LiinkedList and Stack but no LinkedStack
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.