Page 1 of 1

PLEASE USING JAVA LANGUAGE NO using nested loops for method draw • using independent if statements in method getRandomC

Posted: Tue Apr 12, 2022 10:19 am
by answerhappygod
PLEASE USING JAVA LANGUAGE
NO using nested loops for method draw
• using independent if statements in method getRandomColor()
• -NO not calling getRandomColor() in method draW()
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 1
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 1 (39.21 KiB) Viewed 40 times
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 2
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 2 (25.51 KiB) Viewed 40 times
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 3
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 3 (58.55 KiB) Viewed 40 times
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 4
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 4 (60.11 KiB) Viewed 40 times
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 5
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 5 (68.58 KiB) Viewed 40 times
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 6
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 6 (43.26 KiB) Viewed 40 times
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 7
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 7 (55.97 KiB) Viewed 40 times
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 8
Please Using Java Language No Using Nested Loops For Method Draw Using Independent If Statements In Method Getrandomc 8 (50.07 KiB) Viewed 40 times
Open class X in BlueJ and press Ctrl+J to see the documentation. The X class represents a graphical X and can draw itself at a specified location in a specified color. You need to complete class XRectangle. An XRectangle object represents a rectangle of X objects in random colors in 4 rows and 5 columns, and also stores the (x, y) coordinates of the upper left-hand corner of the rectangle. Run the main() method of class XRectangleViewer before submitting your XRectangle to Codecheck. Your output will look like this. 1

Х O - -

// Step 1: Import Java class Random 2 3 ** 4 * A Java class represents a rectangle at a specified location * that contains of X's with 4 rows and 5 columns in random colors. 5 5 * 7 B * Step 2: Enter your name for @author and today's date for @version * @author * @version 10 */ 11 public class XRectangle 9 12 13 public static final int ROWS = 4; public static final int COLUMNS = 5; 14 15 16 17 10 19 public static final int NUMBER_OF_COLORS = 4; public static final int RED = 0; public static final int BLUE 1; public static final int BLACK = 2; public static final int GREEN = 3; I W Step 3: Declare three instance variables for the (x, y) coordinates and a random generator 20 21 22 23 24 25 26 27 20 W Step 4: Write the following constructor inclucing 17 possible Javadoc tags according to the 1/ description /** * The constructor has three parameters: two integers for * the (x, y) coordinates of the upper left-hand corner 29 30 31

ompile Undo Cut Copy Paste Find... Close public static final int ROWS = 4; public static final int COLUMNS = 5; public static final int NUMBER_OF_COLORS = 4; public static final int RED = 0; public static final int BLUE 1; public static final int BLACK = 2; public static final int GREEN = 3; 0 1 2 I/ Step 3: Declare three instance variables for the (x, y) 17 coordinates and a random generator 23 24 25 26 21 26 29 30 1/ Step 4: Write the following constructor inclucing possible Javadoc tags according to the // description /** * The constructor has three parameters: two integers for * the (x, y) coordinates of the upper left-hand corner * of the rectangle, one integer as the seed for the random * generator. It initializes the (x) y) coordinates and * creates a Random object with the seed as the generator. 31 32 14 * */ 36 37 18 0 40 Il Step 5: Write the method draw() inclucing 17 possible Javadoc tags according to the / description /** * Draws the rectangle of 4 rows and 5 columns of X objects 2

le Undo Cut Copy Paste Find... Close // Step 5: Write the method draw() inclucing 17 possible Javadoc tags according to the description /** * Draws the rectangle of 4 rows and 5 columns of X objects * in random color of red, blue, black, and green. * You must use nested for loops, draw the rows from the top. + and draw the X objects from left to right within each row. * For each X object, call method getRandomColor() to get the * color */ ** W/ Step 6: Write the method getRandomColor() inclucing 17 possible Javadoc tags according to the 1 description I * Generates a random integer in the range of [0, 3) using * the random generator created by the constructor, and * return the corresponding color, RED, BLUE, BLACK, and * GREEN * 1 */ 63 6) 65

1 */ 8 public class XRectangleViewer 9 { public static void main(String[] args) { XRectangle grid1 = new XRectangle(1054319577.): XRectangle grid2 = new XRectangle(30.120.54319579); 10 11 12 13 14 15 grid1.draw(); grid2.draw(); I 16 17 18)

public class X 10 { public static final int HEIGHT = 20; public static final int WIDTH 15; 11 12 13 14 15 private int x; private int y: private Color color; I 16 17 18 /** * Constructs an X object at the given coordinates in the given color. 13 20 * 21 22 23 24 25 * @param x the coordinate of the upper left hand corner of this X * @param y the coordinate of the upper left hand corner of this Y * @param c the color of this X */ public X(int x, int y, Color, c) { this.x = x; this.y = y: color = C: } 26 27 28 29 31 32 33 /** * Draws the X on the Canvas */ public void draw()

X 15 private int y: private Color color; 16 17 ** 19 * Constructs an X object at the given coordinates in the given color. 30 * 21 22 23 24 25 * @param x the coordinate of the upper left hand corner of this X * @param y the coordinate of the upper left hand corner of this Y * @param c the color of this X */ public X(int x, int y. Color c) { this.x = x; this.y = y; color = c; } 21 21 20 29 30 31 1 34 /** * Draws the X on the Canvas */ public void draw() { Line line1 = new Line(x, y, X + WIDTH, Y + HEIGHT): Ling line2 - new line(x + WIDTH, y, y + HEIGHT); line1.setColor(color); line2.setColor(color): line1.draw: line2.draw(); 30 41