im trying to make an array list with some numbers, i want to use the numbers in the arraylist to tell a method how many times to run. with code it will make sense.
i know the thing i did with turn() * length is incorrect, obviously. what i am trying to figure out is how to do something similar to this. if anyone has any ideas they are greatly appreciated.
im writing a class that makes the bug "dance." i have to make a constructor that has an integer array as a parameter. the integer entries represent how many times the bug turns before it moves. when a dancing bug acts it should turn the number of times given by the current array entry. each move should carry out the next number in the array. after carrying out the last number in the array the bug should start over again, so that it continually repeats the same "dance" over and over.
overall the main thing is that, the dancingbugrunner should create an array and pass it as a parameter to the dancingbug constructor.
control statements arent really my problem. my problem now is that i am trying to get my bug to dance. i have gotten it to turn, but i cant get it to turn the amount of times that it is supposed to, move, and then turn the next number etc.
if anyone knows anything that would help it would be appreciated.
is this correct?
if so, I'd write a method that takes an integer, and turns the bug that many times.
Then for each element in the array, call the method above and pass in the current element.
nathan gibson wrote:i have tried placing the move method in lots of places, but i always get strange output. sometimes the bug just jumping across the screen.
At a high level, it sould seem to me that you should call the method to move your bug after the method that executes all the turns is complete.
nathan gibson wrote:i tried something of that order on my second post with code. i got very strange results with that. i have tried most of the obvious. the output with that code was something like the bug would make like a half circle and stop...
Ok, so you want the bug to turn a certain number of times, then move, then turn again? Looking at the logic here, you call turn();, then go into a for loop that moves the bug, then back to the outer for loop to turn again, then move again, etc. What is the code in turn(); and move();? I didn't see it in your earlier posts, or if it is there I have been known to miss things directly in front of my face.
i dont know if it helps, but with this full code:
my output is attached. its like not making since to me at this point. i know that the for loop inside has a weird counter, but i wasnt exactly sure what i would use. if anyone has advice it would be very much appreciated