Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By Norm

Thread: Problem getting karel to turn north? he turns back east?

  1. #1
    jmorgangrice is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default Problem getting karel to turn north? he turns back east?

    So basically, in my run command, my first instruction is to turnNorth, then putBeeper.
    Yet when he turns north, he then turns back east, before doing putBeeper, so can only guess its my code where im telling karel to face north. Heres the code

    [Java] karel turn north - Pastebin.com

    Thanks!
    Jay

  2. #2
    jmorgangrice is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    Also worth noting, when he turns back east, he does so by turning right

    Thanks

    Sorry for double post

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    If your questions are about a java program, please post the code for it here.
    Be sure to wrap the code in code tags. Use the # icon above the input box.

  4. #4
    jmorgangrice is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    Java Code:
       1.
          private void faceNorth() {
       2.
                          if (facingEast()) {
       3.
                                  turnLeft();
       4.
                          }
       5.
                          if (facingWest()); {
       6.
                                  turnRight();
       7.
                          }
       8.
                          if (facingSouth()) {
       9.
                                  for (int i=0; i<2; i++) {
      10.
                                          turnLeft();
      11.
                                  }
      12.
                          }
      13.
                         
      14.
                  }


    Thanks

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    Ok, now what?
    Do you have any questions or comments on the code you posted?
    Can you add some comments to the code describing what you want it to do?
    How can I tell by looking at your code if it is doing what you want?

  6. #6
    jmorgangrice is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default

    ermmmm.... You read my origional post?

    Forgive me for bluntness, i aprechiate any help given. But your in the beginners section, so expect beginner mistakes. No need for short tone,

    the code is something that i ask karel to do (to make sure hes turning north, and that he places his first beeper). yet when the code which i posted is called upon, he turns north, then goes back east, then places his second command to place first beeper, i didn't post all the code so it was easier to read, as these are the first 2 things i ask karel to do. and the thing that goes wrong, does so before he places the beeper. So it follows the code iv given. but after turning north, it turns east, before doing my second line of code (putBeeper)

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default

    You read my origional post?
    Yes and it was completely meaningless without the code. And now you have done it the other way, posting the code without the comments that explain it. If the two were together it would be better.

    There is no way to suggest what is wrong with your program from the few lines of code you have posted.
    Try debugging your code by adding printlns to show execution flow and the values of variables as they change and are used. The output might show you where the problem in your logic is.
    Be sure to put a println inside of all the if() tests you show so you know when they are being executed.
    Fubarable likes this.

Similar Threads

  1. Scriptlet Not Running on JSP after coming back from back button of browser
    By jason.3dmagic in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-23-2011, 07:44 AM
  2. Karel the robot
    By vulerious in forum New To Java
    Replies: 0
    Last Post: 07-31-2009, 09:48 PM
  3. Replies: 5
    Last Post: 04-17-2009, 12:56 AM
  4. Java Developer; East Lansing, MI
    By roelhtc in forum Jobs Offered
    Replies: 0
    Last Post: 06-02-2008, 11:52 PM
  5. Java/J2EE Architect: East Lansing, MI
    By roelhtc in forum Jobs Offered
    Replies: 0
    Last Post: 05-12-2008, 10:53 PM

Posting Permissions

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