Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please critique!

 
richard rehl
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a really crude exercise in turtle graphics, from Deitel (Java How to Program). The assignment (chapter 7, ex. 21) is to write a turtle graphics program that will draw a square using the commands given by the author. I know that there are better ways to input/store the commands than an array but my constraints are that I haven't really worked through Arraylists or other collections yet, and, I'm trying to first stick to the assignment. Although Eclipse complains that there are errors, the program compiles and runs; I don't know what the errors are. Thanks for looking!

p.s. I'm also aware that turtle graphics can do much more than draw squares and rectangles... again, I'm just trying to do the exercise as given


 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try compiling it on the command line, there's a fairly obvious mistake on one line.
 
richard rehl
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Harold, tried compiling on the command line, no errors reported, compiled and ran just fine....
 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's odd, it doesn't compile for me.

Line 63 is the problem.
 
richard rehl
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The for loop declaration? I'm not getting an error message there... is it something to do with using cmds.length as the loop test?
 
richard rehl
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, that's weird - just looked at the code that I posted and see which is NOT in my compiler code! A gremlin?

I tried retyping line 63:
and still get
Errors exist in required project: Ex7_21. Continue launch?
from Eclipse.

If you fix that line, does it compile for you?
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harold Lime wrote:That's odd, it doesn't compile for me.

Line 63 is the problem.


That error is a known Javaranch problem -- there is some obscure issue that corrupt code, as it is being posted.

Henry
 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My compiler, and my brain, although you're making me doubt the latter tell me that:

for (int i = 0; i >< cmds.length; i++) {

}

does not make sense, specifically 'i >< cmds.length;'.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
richard rehl wrote:The for loop declaration? I'm not getting an error message there... is it something to do with using cmds.length as the loop test?


Can you confirm that the for loop in your first post looks EXACTLY character for character like one in your code? I think there was a text conversion problem when the code was posted.
 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Harold Lime wrote:That's odd, it doesn't compile for me.

Line 63 is the problem.


That error is a known Javaranch problem -- there is some obscure issue that corrupt code, as it is being posted.

Henry


Ah, in that case I can't see anything wrong. It compiles and runs, no errors and no warnings.
 
richard rehl
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:
richard rehl wrote:The for loop declaration? I'm not getting an error message there... is it something to do with using cmds.length as the loop test?


Can you confirm that the for loop in your first post looks EXACTLY character for character like one in your code? I think there was a text conversion problem when the code was posted.


I can safely say that line 63 as posted is NOT like the line in my compiler code. When I add that > token to the line, Eclipse gives me an error message
Syntax error on token "<", delete this token
.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, I kind of feel silly with how long it took me to post my previous reply. Must have been more than a minute...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic