Menu

[Solved]-Skills Loops Else Statements Random Numbers Cumulative Sum Printf Statements Optional Wr Q37206568

Skills: . while loops . if/else statements random numberS cumulative sum printf statements (optional) Write a program which w

Example #1: Drawing Panel File View Help Drawing Completed in 15844 moves. 5.45 percent of the canvas was colored.

Example #2: Drawing Panel Eile View Help x-92, y-18), r-255 g-255 b-255 Drawing Completed in 37225 moves 9.79 percent of the

Example #3: LI Drawing Panel File View Help Drawing Completed in 19212 moves. 5.27 percent of the canvas was colored.

Starter Code

import java.awt. import java.util. * Homework #3 Update, replace, or add to this code to form your solution CHANGE the class

Running this main nethod will dra a line A fron the top left corner of the canvas to 4 the botton right corner. It uses updat

/*Update the color with each move / updateColor); Update the pixel color *Want to compare the current pixel colc h something

Skills: . while loops . if/else statements random numberS cumulative sum printf statements (optional) Write a program which will: .Open a DrawingPanel of 300×300 this size can vary if you choose Starting in the middle of the panel, color one pixel at a time The color of each pixel should change, but how it changes is up to you: o The color could be random o Or the color could be determined based on the x y location of the pixel . The next pixel to be colored should be one random “move” from the previous o From each pixel, there are four possible next moves o Starting pixel example: (4, 4) o Next pixel: (3, 4), (5, 4), (4, 3) OR (4, 5) The program should continue drawing while the next pixel is within the panel boundaries After the drawing is complete, the program should print to the user: o The count of the “moves” o The percent of the canvas that is colored Example #1: Drawing Panel File View Help Drawing Completed in 15844 moves. 5.45 percent of the canvas was colored. Example #2: Drawing Panel Eile View Help x-92, y-18), r-255 g-255 b-255 Drawing Completed in 37225 moves 9.79 percent of the canvas was colored. Example #3: LI Drawing Panel File View Help Drawing Completed in 19212 moves. 5.27 percent of the canvas was colored. import java.awt. import java.util. * Homework #3 Update, replace, or add to this code to form your solution CHANGE the class name to Hw03_Your Nane public class Hw03_Starter_Code f Canvas Height and Width public static final int WIDTH 300; public static final int HEIGHT = 300; rae x& y can represent your current pixel location color can represent your current color *Because these are class variables, they can be *accessed from any nethod in this class public static int x0; public static int y 0; public static Color color This is a really boring way of creating a randon olor Can you think of a better way? This honework only requires a color change for e can be randon, but doesn’t have to be I used a of randonness and the current pixel location for * color schene h move, it bination public static void updateColor() Randon rand new Randon) color new Color (50, rand.nextInt(155), S0); Running this main nethod will dra a line A fron the top left corner of the canvas to 4 the botton right corner. It uses updateColor 4 to update the color of the pixel for each next A “nowe”Here, the noves are not randon. Your mov A will have to be randon * with a starting location of 《x, y), the next mo will have to be chosen randonly fron the below (x1. y) (x, y 1) * This progran uses a for loop because it knows how many moves it will make. Your program shoul * while loop. If the next nove crosses the boundar of the canvas, then your while loop should terninate Your progran should print two values to your use 1 The percentage of the canvas that is colore 16 of 100 pixels change color from white to new, then 16% of the canvas was colored in use a printf statenent to output this nicel If onething but that is optional 2. The total number of noves the progran made color in your canvas before you sent out of boun The progran below made 300 (or WIDTH) noves public static void nain(String[) args) f DrawingPanel canvas new DrawingPanel(WIDTH, GHT) for {int í ” 0; ì < WIDTH; i++) { /*Update the color with each move / updateColor); Update the pixel color *Want to compare the current pixel colc h something else? *Try the below boolean statement: * canvas.getPixel(x, y).equals (newC canvas.setPixel(i, i, color); /t * Below is a ‘sleep’ statement which pa * for 5 milliseconds, so that we can se * human eye. When you are testing, you * statement based on your preference your program draw with the emove or change this canvas.sleep(5) Show transcribed image text Skills: . while loops . if/else statements random numberS cumulative sum printf statements (optional) Write a program which will: .Open a DrawingPanel of 300×300 this size can vary if you choose Starting in the middle of the panel, color one pixel at a time The color of each pixel should change, but how it changes is up to you: o The color could be random o Or the color could be determined based on the x y location of the pixel . The next pixel to be colored should be one random “move” from the previous o From each pixel, there are four possible next moves o Starting pixel example: (4, 4) o Next pixel: (3, 4), (5, 4), (4, 3) OR (4, 5) The program should continue drawing while the next pixel is within the panel boundaries After the drawing is complete, the program should print to the user: o The count of the “moves” o The percent of the canvas that is colored
Example #1: Drawing Panel File View Help Drawing Completed in 15844 moves. 5.45 percent of the canvas was colored.
Example #2: Drawing Panel Eile View Help x-92, y-18), r-255 g-255 b-255 Drawing Completed in 37225 moves 9.79 percent of the canvas was colored.
Example #3: LI Drawing Panel File View Help Drawing Completed in 19212 moves. 5.27 percent of the canvas was colored.
import java.awt. import java.util. * Homework #3 Update, replace, or add to this code to form your solution CHANGE the class name to Hw03_Your Nane public class Hw03_Starter_Code f Canvas Height and Width public static final int WIDTH 300; public static final int HEIGHT = 300; rae x& y can represent your current pixel location color can represent your current color *Because these are class variables, they can be *accessed from any nethod in this class public static int x0; public static int y 0; public static Color color This is a really boring way of creating a randon olor Can you think of a better way? This honework only requires a color change for e can be randon, but doesn’t have to be I used a of randonness and the current pixel location for * color schene h move, it bination public static void updateColor() Randon rand new Randon) color new Color (50, rand.nextInt(155), S0);
Running this main nethod will dra a line A fron the top left corner of the canvas to 4 the botton right corner. It uses updateColor 4 to update the color of the pixel for each next A “nowe”Here, the noves are not randon. Your mov A will have to be randon * with a starting location of 《x, y), the next mo will have to be chosen randonly fron the below (x1. y) (x, y 1) * This progran uses a for loop because it knows how many moves it will make. Your program shoul * while loop. If the next nove crosses the boundar of the canvas, then your while loop should terninate Your progran should print two values to your use 1 The percentage of the canvas that is colore 16 of 100 pixels change color from white to new, then 16% of the canvas was colored in use a printf statenent to output this nicel If onething but that is optional 2. The total number of noves the progran made color in your canvas before you sent out of boun The progran below made 300 (or WIDTH) noves public static void nain(String[) args) f DrawingPanel canvas new DrawingPanel(WIDTH, GHT) for {int í ” 0; ì

Expert Answer


Answer to Skills: . while loops . if/else statements random numberS cumulative sum printf statements (optional) Write a program wh… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *