We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

Eindoofus
Eindoofus asked
on
Medium Priority
394 Views
Last Modified: 2013-12-29
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?
Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:
I guess there is no such standard class as LinkedStack

There is LiinkedList and Stack but no LinkedStack
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.