Results 1 to 6 of 6
- 07-01-2012, 02:01 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 6
- Rep Power
- 0
Karel- debugging a problem and can't solve it o.o
Hi I've been using the karel "spin-off" language of java as a precursor to learning real java and I faced a problem that I cannot solve.
The question can be seen here as problem 3 on page 4 out of 5. What occurs is Karel is able to complete the pattern up to the third row but once she moves up to the next row she continues to move straight as if it skipped specific lines of code.
The code is below.Java Code:import stanford.karel.*; public class CheckerboardKarel extends SuperKarel { public void run() { turnRight(); if (facingSouth()) { turnLeft(); while (frontIsClear()) { putBeeper(); move(); if (frontIsClear()) { move(); while (frontIsBlocked()) { while (noBeepersPresent()) { putBeeper(); gobackHome(); } } } gobackHome(); if (frontIsBlocked()) { if (facingWest()) { nextRowA(); } } invertedChecker(); gobackHome(); if (frontIsBlocked()) { if (facingWest()) { nextRowB(); } noninvertedChecker(); } invertedChecker(); } } } private void gobackHome() { if (frontIsBlocked()) { turnAround(); while (frontIsClear()) { move(); } } } private void invertedChecker() { if (facingNorth()) { turnRight(); while (frontIsClear()) { move(); putBeeper(); if (frontIsClear()) { move(); while (frontIsBlocked()) { while (noBeepersPresent()) { putBeeper(); } gobackHome(); if (frontIsBlocked()) { if (facingWest()) { nextRowB(); } } } } } } } private void nextRowA() { turnRight(); move(); } private void nextRowB() { turnRight(); move(); turnAround(); } private void noninvertedChecker() { if (facingSouth()) { turnLeft(); while (frontIsClear()) { putBeeper(); move(); if (frontIsClear()) { move(); while (frontIsBlocked()) { while (noBeepersPresent()) { putBeeper(); gobackHome(); } } } gobackHome(); if (frontIsBlocked()) { if (facingWest()) { nextRowA(); } } } } } }
Last edited by stormed; 07-01-2012 at 02:04 AM.
-
Re: Karel- debugging a problem and can't solve it o.o
This isn't really Java, so we might not be able to help. We certainly can't help without seeing what your error messages are.
- 07-01-2012, 02:11 AM #3
Member
- Join Date
- Jul 2012
- Posts
- 6
- Rep Power
- 0
Re: Karel- debugging a problem and can't solve it o.o
Hm yes I thought so, however this is from the coding methodology class of Stanford (course notes offered online and I'm using those). course code being CS106A, I've seen threads in the past on this board relating to it.
No there are no error messages whatsoever, it is just as I explained in the original post. Karel continues a pattern as seen in the problem example (within the link) that I coded myself up until the third row however the fourth row it just goes north and continues to lay beepers in the wrong direction. I'm very new to coding so sorry if it seems disorganized, I don't usually provide descriptions for different methods until I'm finished the actual coding.
- 07-01-2012, 02:19 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Karel- debugging a problem and can't solve it o.o
A couple of things may help: If there is public documentation for the Karel and SuperKarel classes, post a link. (And if there isn't, tell your teacher there should be.)
Secondly, please edit your post and correct the indentation. Generally I'm pretty tolerant of formatting (even when people, inexplicably, don't do things the same way I do) but your placement of the closing braces is crazy. Put them each on their own line, lining up directly below the opening brace they match. This isn't a trivial matter: from what you describe you are dealing with some sort of logic error and the nesting of the code matters a lot.
- 07-04-2012, 03:50 AM #5
Member
- Join Date
- Jul 2012
- Posts
- 1
- Rep Power
- 0
Re: Karel- debugging a problem and can't solve it o.o
pbrockway2: There is documentation on Karel (i.e., Karel the Robot Learns Java by Eric Roberts), it can be found here (PDF)
stormed: While it may not be as helpful to you, you may want to thing in bits at first (i.e., just get Karel to put a beeper down and then move)
Java Code:// Programmer notes/definitions // putBeeper - Karel puts a beeper down // beepersInBag - Karel checks to see if he has any beepers in his bag // facingEast - Karel determines his direction // frontIsClear - Karel checks to see if anything is blocking his way // forwardHo - Karel checks to see if anything is blocking his way, if nothing is he continues moving while (beepersInBag() { while (facingEast() { while (frontIsClear() { putBeeper(); forwardHo(); forwardHo(); } } } private void forwardHo () { if (frontIsClear()) { move(); } }
- 07-04-2012, 04:06 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Similar Threads
-
cant solve my problem .needs some help(C++):(y):
By seongchog in forum New To JavaReplies: 2Last Post: 12-03-2011, 09:49 PM -
Solve JVM Problem
By pedroffbarbosa in forum Advanced JavaReplies: 8Last Post: 11-29-2011, 12:35 AM -
Problem getting karel to turn north? he turns back east?
By jmorgangrice in forum New To JavaReplies: 6Last Post: 07-24-2011, 09:18 PM -
Help me to solve problem
By mansoorhacker in forum Forum GuidesReplies: 8Last Post: 01-24-2009, 07:29 PM -
Help me to solve problem
By mansoorhacker in forum New To JavaReplies: 3Last Post: 11-13-2008, 09:15 AM
Bookmarks