Question: Hacker Challenge Java Project Name: IC10_HackerChallenge Extend your program from the IC09_LoopyFaces so that it displays 100 faces (10 rows, 10 columns), alternating colors between
Hacker Challenge
Java Project Name: IC10_HackerChallenge
Extend your program from the IC09_LoopyFaces so that it displays 100 faces (10 rows, 10 columns), alternating colors between each face. Feel free to modify the look of the faces, or even define a new shape of your own! For example, you could transform the snowman (or even Olaf) that you drew in IC #02 (Week 1 content) and display that graphic 100 times. The main objective here is to repeat the shape on multiple rows and columns. For example:
// can anyone help? this is my code.
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JApplet;
public class HackerChallenge extends JApplet {
public static final int FACE_DIAMETERa = 50;
public static final int X_FACEDO = 10;
public static final int Y_FACEDO = 5;
public static final int EYE_WIDTH = 5;
public static final int EYE_HEIGHT = 10;
public static final int X_RIGHT_EYED = 20;
public static final int Y_RIGHT_EYED = 15;
public static final int X_LEFT_EYED = 45;
public static final int Y_LEFT_EYED = Y_RIGHT_EYED;
public static final int NOSE_DIAMETER = 5;
public static final int X_NOSED = 32;
public static final int Y_NOSED = 25;
public static final int MOUTH_WIDTH = 30;
public static final int MOUTH_HEIGHT = 0;
public static final int X_MOUTH= 20;
public static final int Y_MOUTH = 35;
public static final int MOUTH_START_ANGLE = 180;
public static final int MOUTH_EXTENT_ANGLE = 180;
public void paint(Graphics canvas)
{
super.paint(canvas);
int i, xOffset, yOffset;
for (i = 0; i
{
xOffset = 50 * i;
yOffset = 30 * i;
// drawing face circle
if (i % 1 == 0) //even number for the row of faces
// make the face ORANGE
canvas.setColor(Color.BLUE);
canvas.fillOval(X_FACEDO + xOffset, Y_FACEDO + yOffset, FACE_DIAMETERa, FACE_DIAMETERa);
if (i % 2 == 0)
canvas.setColor(Color.ORANGE);
canvas.fillOval(X_FACEDO + xOffset, Y_FACEDO + yOffset, FACE_DIAMETERa, FACE_DIAMETERa);
{
}
//drawing mouth
canvas.setColor(Color.BLACK);
canvas.drawArc(X_MOUTH + xOffset, Y_MOUTH + yOffset, MOUTH_WIDTH, MOUTH_HEIGHT + 3 * 1, MOUTH_START_ANGLE, MOUTH_EXTENT_ANGLE);
//drawing ayes
canvas.setColor(Color.BLACK);
canvas.fillOval(X_RIGHT_EYED + xOffset, Y_RIGHT_EYED + yOffset, EYE_WIDTH, EYE_HEIGHT);
canvas.fillOval(X_LEFT_EYED + xOffset, Y_LEFT_EYED + yOffset, EYE_WIDTH, EYE_HEIGHT);
// drawing nose
canvas.setColor(Color.BLACK);
canvas.fillOval(X_NOSED + xOffset, Y_NOSED + yOffset, NOSE_DIAMETER, NOSE_DIAMETER);
// drawing mouth
canvas.setColor(Color.BLACK);
canvas.drawArc(X_MOUTH + xOffset, Y_MOUTH + yOffset, MOUTH_WIDTH, MOUTH_HEIGHT + 3 * 1, MOUTH_START_ANGLE, MOUTH_EXTENT_ANGLE);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
