Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 42 of 42

Thread: Lagnton Ant

  1. #26
    Member
    Join Date
    Apr 2013
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    I am not sure. It is not showing any errors, but I did not run. It won't compile because it depends on Ant.java which is the one with this error on EAST

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Lagnton Ant

    Change the code to return the correct value vs EAST.

    Suggestion: add a main() method for testing the constructor and methods. Create an instance of the Ant class, call its methods and print out the results as appropriate.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #28
    Member
    Join Date
    Apr 2013
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    It worked because I imported direction I suppose. That's why I don't understand. I have imported it as well in 24 and is showing error on EAST.

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Lagnton Ant

    Ant is not coded correctly now. That should be fixed.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #30
    Member
    Join Date
    Apr 2013
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

     
    package simulation;
     
    import core.Direction;
     
    /**
     * 
     * Ant class
     * 
     *
     */
    public class Ant {
    	public Direction dir;
     
    	public Ant(int iPos, int jPos, Direction direction){
    		dir = direction;
    	}
     
    	public int getIPos() {
    		return 0;
    	}
    	protected void setIPos(int iPos) {
     
    	}
    	public int getJPos() {
    		return 10;
    	}
    	protected void setJPos(int jPos) {
    		// TODO fill in this method
    	}
    	public Direction getDirection() {
    		return dir;
    	}
    	protected void setDirection(Direction direction) {
     
    	}
     
    }

    I can't find out what's wrong.

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Lagnton Ant

    I can't find out what's wrong.
    Please explain. Copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #32
    Member
    Join Date
    Apr 2013
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    Sorry, still in EAST:

    The member enum EAST can only be defined inside a top-level class or interface
    Syntax error, insert "EnumBody" to complete BlockStatements

  8. #33
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Lagnton Ant

    Sorry, I can't connect that post with any code. Where is the code causing the error?

    Copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #34
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    Direction isn't a string, thats your error its meant to be enum Direction

  10. #35
    Member
    Join Date
    Apr 2013
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    package simulation;
     
    import core.Direction;
     
    /**
     * 
     * Ant class
     * 
     *
     */
    public class Ant {
    	public Direction dir;
     
    	public Ant(int iPos, int jPos, Direction direction){
    		dir = direction;
    	}
     
    	public int getIPos() {
    		return 0;
    	}
    	protected void setIPos(int iPos) {
     
    	}
    	public int getJPos() {
    		return 10;
    	}
    	protected void setJPos(int jPos) {
    		// TODO fill in this method
    	}
    	public Direction getDirection() {
    		return EAST;
    	}
    	protected void setDirection(Direction direction) {
     
    	}
     
    }
    The member enum EAST can only be defined inside a top-level class or interface Ant.java line 40 Java Problem
    Syntax error, insert "EnumBody" to complete BlockStatements Ant.java line 40

    --- Update ---

    Sorry, where does it say it is a string? I know it is not a string, where did I go wrong on syntax?

  11. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Lagnton Ant

    try Direction.EAST
    If you don't understand my answer, don't ignore it, ask a question.

  12. #37
    Member
    Join Date
    Apr 2013
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    package simulation;
     
    import core.Direction;
     
    /**
     * 
     * Ant class
     * 
     *
     */
    public class Ant {
    	public Direction dir;
     
    	public Ant(int iPos, int jPos, Direction direction){
    		dir = direction;
    	}
     
    	public int getIPos() {
    		return 0;
    	}
    	protected void setIPos(int iPos) {
     
    	}
    	public int getJPos() {
    		return 10;
    	}
    	protected void setJPos(int jPos) {
    		// TODO fill in this method
    	}
    	public Direction getDirection() {
    		return Direction.EAST;	
    	}
    	protected void setDirection(Direction direction) {
     
    	}
     
    }

    Errors:
    The member enum EAST can only be defined inside a top-level class or interface Ant.java /Assign1/src/simulation line 40 Java Problem
    Syntax error, insert "EnumBody" to complete BlockStatements Ant.java /Assign1/src/simulation line 40 Java Problem

  13. #38
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    in the Ant file you need to declare direction as an enum, i think thats you're problem

  14. #39
    Member
    Join Date
    Apr 2013
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    how to do this?

  15. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Lagnton Ant

    You posted the enum definition in post#3. Did you ever use it in any of the code after that without any problems? If it did work for some classes since post #3, what has changed since then?
    If you don't understand my answer, don't ignore it, ask a question.

  16. #41
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Lagnton Ant

    do you ever provide coded answers? sometimes hints don't work

  17. #42
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Lagnton Ant

    There is something messed up in the way this project is configured in the IDE. I've never seen the error message that is being posted. The error message doesn't correspond to the posted source code.
    The error messages I'm familiar with look like this:
    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Error in ant files
    By workforsiva in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 17th, 2013, 08:38 AM
  2. Java Ant
    By dsavatar in forum Java Theory & Questions
    Replies: 2
    Last Post: December 6th, 2012, 09:29 AM
  3. Ant Colony Simulator
    By KevinWorkman in forum The Cafe
    Replies: 4
    Last Post: December 14th, 2011, 01:39 PM
  4. Ant Executes and Stops After a Certain Task
    By DanielPros in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 9th, 2011, 10:46 AM
  5. Reading ant output when exec the command
    By cipm66 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: October 23rd, 2010, 01:48 PM