Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions