Results 1 to 4 of 4
Thread: Turning a Bug around.
- 02-17-2010, 07:14 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
Turning a Bug around.
This is what I currently have. I need to get the bug to turn around without subtracting from its current position. The book provides this sample:
Bug bugsy = new Bug(10)
bugsy.move(); //It is now at 11
bugsy.turn();
bugsy.move(); //It is now at 10.
Everything I've done to turn it simply makes it move backwards so the turn is at 10. And then the next move puts it at 11 again instead of 10. Or it turns it twenty units so it's at -11, which isn't what I'm supposed to do.
Just as a warning I come from an English major background. I still have enough trouble remembering which is my x axis and which is my y axis.
Thank you ever so much,
Shadow
public class ShellBugMover
{
//Constructs the Bug
public ShellBugMover(int initialPosition)
{
currentPosition = initialPosition;
}
//Moves the Bug 1 unit to the right.
public void move()
{
currentPosition = currentPosition + 1;
}
//Changes the direction of the Bug.
public void turn()
{
currentPosition = ????
}
//Denotes the current position of the Bug.
public int getPosition()
{
return currentPosition;
}
//Declares the instance field.
int currentPosition;
}Last edited by Nightshadow_t2; 02-17-2010 at 07:28 AM. Reason: clarification
- 02-17-2010, 07:47 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
I answered exactly this question in another thread.
kind regards,
Jos
- 02-17-2010, 07:51 AM #3
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
Does that mean I need to create another variable for the direction? I tried creating one earlier, but then the tester wouldn't compile anymore. And thank you for pointing me at the thread, though I still find myself a bit lost.
May the day be yours,
ShadowLast edited by Nightshadow_t2; 02-17-2010 at 08:02 AM.
- 02-17-2010, 08:03 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Turning an image to binary
By morghul in forum New To JavaReplies: 3Last Post: 01-17-2010, 07:47 PM -
im very new to java need help with taking years and turning it into days, hours, etc.
By mrnoahf in forum New To JavaReplies: 3Last Post: 08-11-2009, 12:18 AM -
Turning numbers into asterisks.
By BugginVT in forum New To JavaReplies: 7Last Post: 02-25-2009, 07:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks