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
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.
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
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.
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.
Ant is not coded correctly now. That should be fixed.
If you don't understand my answer, don't ignore it, ask a question.
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.
Please explain. Copy the full text of the error messages and paste it here.I can't find out what's wrong.
If you don't understand my answer, don't ignore it, ask a question.
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
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.
Direction isn't a string, thats your error its meant to be enum Direction
The member enum EAST can only be defined inside a top-level class or interface Ant.java line 40 Java Problempackage 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) { } }
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?
try Direction.EAST
If you don't understand my answer, don't ignore it, ask a question.
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
in the Ant file you need to declare direction as an enum, i think thats you're problem
how to do this?
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.
do you ever provide coded answers? sometimes hints don't work
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.