Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Learning to Program with Robots (JAVA) The link of the textbook: http://www.lear

ID: 3866817 • Letter: L

Question

Learning to Program with Robots (JAVA)

The link of the textbook: http://www.learningwithrobots.com/textbook/PDFs/WholeThing.pdf

5.14 Write a new Robot class, Houdini, that includes a method namcd escapeRoom. It will cause the robot to search for an exit to a rectangular room-a break in the wall. Such an exit always exists and is never in a corner. The robot may start any where in the room, but it will not be facing the exit. When the exit is found, the robot will move through the exit and then stop. See Figure 5-24 for two of many possible initial situations. h) h. Create a checkerboard, as shown in Figure 5-29h.

Explanation / Answer

import java.awt.*;

import java.applet.*;

  

public class Checkerboard extends Applet {

  

/* This applet draws a red-and-black checkerboard.

It is assumed that the size of the applet is 160

by 160 pixels.

*/

  

public void paint(Graphics g) {

  

int row; // Row number, from 0 to 7

int col; // Column number, from 0 to 7

int x,y; // Top-left corner of square

for ( row = 0; row < 8; row++ ) {

  

for ( col = 0; col < 8; col++) {

x = col * 20;

y = row * 20;

if ( (row % 2) == (col % 2) )

g.setColor(Color.red);

else

g.setColor(Color.black);

g.fillRect(x, y, 20, 20);

}

  

} // end for row

} // end paint()

} // end class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote