• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

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?
0
Eindoofus
Asked:
Eindoofus
1 Solution
 
for_yanCommented:
I guess there is no such standard class as LinkedStack

There is LiinkedList and Stack but no LinkedStack
0
 
VenabiliCommented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now