Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Rainbow

eroy823
eroy823 


The “rainbow” is made of four overlapping semicircles. The outer ring is red (Color.RED), the middle one is green (Color.GREEN), and the inner ring has the magenta color (Color.MAGENTA). The innermost semicircle has the same color as the background. Follow the instructions below and fill in the blanks in Rainbow.java. 1.Start the Rainbow project. 2.Add a complete comment header with your name before the class declaration at the top of the file. 3.Add to the Rainbow class a declaration of a private final field skyColor of the type Color, initialized to Color.CYAN (the color of the sky). In Rainbow’s constructor, set the window’s background to skyColor rather than Color.WHITE. 4.In the paint method, declare local integer variables xCenter and yCenter that represent the coordinates of the center of the rings. Initialize them to 1/2 width and 3/4 height (down) of the content pane, respectively. (Recall that the origin of graphics coordinates in Java is at the upper left corner of the content pane with the y-axis pointing down.) Do not plug in fixed numbers from the window’s dimensions. 5.Declare a local variable largeRadius that represents the radius of the largest (red) semicircle and initialize it to 1/4 of width. 6.A method call g.fillArc(x, y, size, size, from, degrees) (with all integer arguments) draws a sector of a circle. x and y are the coordinates of the upper left corner of the rectangle (in this case a square) into which the oval is (logically) inscribed; size is the side of the square (and the diameter of the circle); from is the starting point of the arc in degrees (with 0 at the easternmost point of the horizontal diameter), and degrees (a positive number) is the measure of the arc, going counterclockwise. Add a statement to the paint method to draw the largest (red) semicircle. Test your program. 7.Add statements to display the medium (green) and small (magenta) semicircles. The radius of the magenta semicircle should be 1/4 of height. The radius of the green one should be the geometric mean (the square root of the product) of the radius of the red semicircle and the radius of the magenta semicircle, rounded to the nearest integer. (A call to Math.sqrt(x) returns the value of square root of x, a double.) Retest your program. 8.Add statements to display the innermost semicircle of the background (“sky”) color to complete the rainbow. Use the skyColor constant for this semicircle’s color. Choose the radius of the sky-color semicircle in such a way that the width of the middle (green) ring is the arithmetic mean of the widths of the red and magenta rings. 9.Test your program. My code is attached. My group bent the rules a little and everything works except for skRadius. If you run the program and resize the window you will see what my problem is. Thank you! Attachments Tags
Clarifications

Answers

Rainbow

felo
felo 



find attached Attachments
Rainbow.txt (2 K) Download Preview
/ 2, yCenter - (medRadius + largeRadius) / 2, medRadius, medRadius, 0, 180); //MAGENTA g.setColor(Color.MAGENTA); g.fillArc(xCenter - (smallRadius + largeRadius)/2, yCenter - (smallRadius + largeRadius)/2, smallRadius, smallRadius, 0, 180); // Calculate the radius of the innermost (sky-color) semicircle // so that the width

Rainbow.png (98 K) Download Preview

Screenshots
Screenshot
Purchase Answer