The goal of this assignment is to deepen your understanding of loops and conditionals.
Do not use a conditional or loop (such as an if, while, or for statement) on this question.% java Ordered 10 17 49 true % java Ordered 49 17 10 true % java Ordered 10 49 17 false
Write a program RGBtoCMYK.java that converts from RGB format to CMYK format. Your program should take three integer command-line arugments red, green, and blue; print the RGB values; then print the equivalent CMYK values using these mathematical formulas:
white=max{red255,green255,blue255}cyan=(white−red255)÷whitemagenta=(white−green255)÷whiteyellow=(white−blue255)÷whiteblack=1−white
Hint. Math.max(x, y) returns the maximum of x and y.
% java RGBtoCMYK 75 0 130 // indigo red = 75 green = 0 blue = 130 cyan = 0.423076923076923 magenta = 1.0 yellow = 0.0 black = 0.4901960784313726 |
% java RGBtoCMYK 255 143 0 // Princeton orange red = 255 green = 143 blue = 0 cyan = 0.0 magenta = 0.4392156862745098 yellow = 1.0 black = 0.0 |
If the red, green, and blue values are each 0, the resulting color is black. Here is what your program should do:
% java RGBtoCMYK 0 0 0 // black red = 0 green = 0 blue = 0 cyan = 0.0 magenta = 0.0 yellow = 0.0 black = 1.0
% java Checkerboard 4 % java Checkerboard 5 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
% java RandomWalker 10 % java RandomWalker 20 (0, 0) (0, 0) (0, -1) (0, 1) (0, 0) (-1, 1) (0, 1) (-1, 2) (0, 2) (0, 2) (-1, 2) (1, 2) (-2, 2) (1, 3) (-2, 1) (0, 3) (-1, 1) (-1, 3) (-2, 1) (-2, 3) (-3, 1) (-3, 3) squared distance = 10 (-3, 2) (-4, 2) (-4, 1) (-3, 1) (-3, 0) (-4, 0) (-4, -1) (-3, -1) (-3, -2) (-3, -3) squared distance = 18
% java RandomWalkers 100 10000 % java RandomWalkers 400 2000 mean squared distance = 101.446 mean squared distance = 383.12 % java RandomWalkers 100 10000 % java RandomWalkers 800 5000 mean squared distance = 99.1674 mean squared distance = 811.8264 % java RandomWalkers 200 1000 % java RandomWalkers 1600 100000 mean squared distance = 195.75 mean squared distance = 1600.13064
As n increases, we expect the random walk to end up farther and farther away from the origin. But how much farther? Use RandomWalkers to formulate a hypothesis as to how the mean squared distance grows as a function of n. Use trials = 100,000 to get a sufficiently accurate estimate.
This process is a discrete version of a natural phenomenon known as Brownian motion. It serves as a scientific model for an astonishing range of physical processes from the dispersion of ink flowing in water, to the formation of polymer chains in chemistry, to cascades of neurons firing in the brain.
Program style and format. Follow the guidelines in the Assignment FAQ. Is your header complete? Did you comment appropriately? Is your code indented consistently? Did you use descriptive variable names? Did you follow the input and output specifications? Are there any redundant conditions? Did you click the Check All Submitted Files button?
Submission. Submit the files Ordered.java, RGBtoCMYK.java, Checkerboard.java, RandomWalker.java, RandomWalkers.java, and a completed readme.txt file.