Question: Write the comments on every line of the following code. import info.gridworld.actor.Bug; public class DancingBug extends Bug { private int[] turn; private int currentStep; public

Write the comments on every line of the following code.

import info.gridworld.actor.Bug;

public class DancingBug extends Bug

{

private int[] turn;

private int currentStep;

public DancingBug(int[] turns)

{

turn = turns;

currentStep = 0;

}

public void turn(int times)

{

for(int i = 1; i <= times; i++)

{

turn();

}

}

public void act()

{

if(currentStep == turn.length)

currentStep = 0;

turn (turn[currentStep]);

super.act();

currentStep++;

}

}

Explain : This DancingBug Class makes different turns before each move. The DancingBug constructor has an integer array as a parameter. The integer entries in the array represent how many times the bug turns before it moves. For example, an array entry of 5 represents a turn of 225 degrees (recall one turn is 45 degrees). When a dancing bug acts, it turns the number of times given by the current array entry, then act like a Bug. In the next move, it use the next entry in the array. After carrying out the last turn in the array, it should start again with the initial array value so that the dancing, bugs continually repeat the same turning pattern

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!