Results 1 to 6 of 6
  1. #1
    ribbs2521 is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default Import not working

    I was wondering if someone could tell me why I'm getting a compilation error when I try to run this. This code is straight out of a book so I must be missing something.

    This is the error:
    package edu.colorado.collections does not exist
    import edu.colorado.collections.CharStack;

    Java Code:
    import edu.colorado.collections.CharStack;
    import edu.colorado.collections.DoubleStack;
    import edu.colorado.io.EasyReader;
    
    public class BooleanCalc
    {
    	public static void main(String[] args)
    	{
    		EasyReader stdin = new EasyReader(System.in);
    		double anser;
    
    		System.out.println("Type a fully parenthesized arithmetic expression:");
    		answer = readAndEvaluate(stdin);
    		System.out.println("That evaluates to " + answer);
    	}
    
    	public static double readAndEvaluate(EasyReader input)
    	{
    		final char DECIMAL = '.';
    		final char RIUGHT_PARENTHESIS = ')';
    		final String SYMBOLS = "+-*/";
    
    		DoubleStack number = new DoubleStack();
    		CharStack operations = new CharStack();
    
    		while (!input.isEOLN())
    		{
    			if (Character.isDigit(input.peek()) || (input.peek() == DECIMAL))
    			{
    				numbers.push(input.charInput());
    			}
    			else if (SYMBOLS.indexOf(input.peek()) >= 0)
    			{
    				operations.push(input.charInput());
    			}
    			else if (input.peek() == RIGHT_PARENTHESIS)
    			{
    				input.ignore();
    				evaluateStackTops(numbers, operations);
    			}
    			else
    			{
    				input.ignore();
    			}
    		}
    		input.skipLine();
    
    		if (numbers.size() != 1)
    			throw new IllegalArgumentException("Illegal input expression.");
    		return numberls.pop();
    	}
    
    	public static void evaluateStackTops(DoubleStack numbers, CharStack operations)
    	{
    		double operand1, operand2;
    
    		if ((numbers.size() < 2) || (operations.isEmpty()))
    			throw new IllegalArgumentException("Illegal expression.");
    		operand2 = numbers.pop();
    		operand1 = numbers.pop();
    
    		switch (operations.pop())
    		{
    			case '+': numbers.push(operand1 + operand2);
    					  break;
    			case '-': numbers.push(operand1 - operand2);
    					  break;
    			case '*': numbers.push(operand1 * operand2);
    					  break;
    			case '/': numbers.push(operand1 / operand2);
    					  break;
    			default:  throw new IllegalArgumentException("Illegal operation.");
    		}
    	}
    }

  2. #2
    angelicsign is offline Member
    Join Date
    Dec 2008
    Posts
    25
    Rep Power
    0

    Default

    yup,you are totally missing some packages.
    Java Code:
    edu.colorado.collections.CharStack;
    edu.colorado.collections.DoubleStack;
    edu.colorado.io.EasyReader;
    this 3 packages are not inside J2SE API.
    so you have to compile this 3 packages somewhere else
    where the code will start like this normally

    Java Code:
    package edu.colorado
    what packages are included in the java?
    Java 2 Platform SE v1.4.2
    you can refers to the link above.
    Last edited by angelicsign; 12-16-2008 at 06:18 AM.

  3. #3
    ribbs2521 is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default

    I'm not quite sure I understand what you mean by, compiling them somewhere else. How would I compile the packages? Can I do it in my code or do I do that manually.

    I tried adding the package edu.colorado; to my code after the three imports but I get this error:

    java:7: class, interface, or enum expected
    package edu.colorado;

    (there is a carat symbol under the P in the error message)

  4. #4
    angelicsign is offline Member
    Join Date
    Dec 2008
    Posts
    25
    Rep Power
    0

    Default

    okay, i try to give you a simple example.

    this code save inside the directory of vehicles
    e.g. c:\directory\vehicles\car.java
    Java Code:
    [COLOR="Red"]package vehicles;[/COLOR]
    public class car{
    code here.......
    }
    save and compile the car.java to get a .class file

    this is the main test program, may save at anywhere under same directory.
    e.g. c:\directory\testProj\testing.java
    Java Code:
    [COLOR="Red"]import vehicles.car;[/COLOR]
    public class testing{
    code here....
    }
    you have to packaging it before you import the package.
    similarly, you are trying to import a package that is not inside java library, so you have to find out where the edu.colorado package come from.
    copy paste it then compile it to have a .class file so that you'll able to import
    edu.colorado.*;

  5. #5
    ribbs2521 is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default

    OK, I think I've got it now, I'll let you know if I have any issues. Thanks for the clarification.

  6. #6
    angelicsign is offline Member
    Join Date
    Dec 2008
    Posts
    25
    Rep Power
    0

Similar Threads

  1. can any one help?? how to import library
    By libish in forum New To Java
    Replies: 5
    Last Post: 02-12-2009, 06:51 AM
  2. import java.util ????
    By kris09 in forum New To Java
    Replies: 3
    Last Post: 08-11-2008, 12:39 AM
  3. How to import a package in Eclipse?
    By naipulb in forum New To Java
    Replies: 2
    Last Post: 06-09-2008, 11:04 AM
  4. Replies: 8
    Last Post: 05-28-2008, 07:00 AM
  5. import statement.
    By diRisig in forum New To Java
    Replies: 2
    Last Post: 02-08-2008, 12:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •