Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CS49J Remember not to create In these problems, you will revisit problems from h

ID: 3743539 • Letter: C

Question

CS49J Remember not to create In these problems, you will revisit problems from hw2 and represent the shapes with classes so that multiple objects can be drawn. There are only 2 problems this week. Note: for a quirky reason, the viewer class must import javax swing.: rather than javax.swing JFrame. Ask me if you want an explanation packages. Use the default package In this problem you will write a Rainbow class which will draw a-rainbow" at a specified (x, y). Rainbow will have a construct that takes the x, y coordinaties of the upper-left hand comer of the rainbow as well as the height of a color. Rainbow will have a draw method which takes the graphical context as a parameter and draws the The rainbow will be displayed as colored rectangles rather than arcs. The height of a rectangle is given in the constructor. The width of a rectangle is 5 times the height of a rectangle. The colors of the first 5 should be made with the pre-defined colors in the Color class. Use red, orange, yellow green, and blue in that order. The next color is indigo and has RGB values (75, 0, 130). The last rectangle is violet with RGB values of (143,0, 255). You will need to construct Color objects using these values. There are 7 rectangles. You will complete the RainbowComponent class to construct and draw three Rainbow objects given these criteria . Upper left-hand comer at 0,0. Height of 20 Upper left-hand comer at 100, 180. Height of 10 Upper left-hand comer at 0,200. Height of 5 Rainbowviewer is provided. In this application, you will create a Target class. A target consisting of three concentric cireles with specifications listed below The constructor takes the x,y coordinates of the center of the target and the radius of the smallest Provide a draw method that follows these specifications . The center is at x, y . The largest circle is red with a radius of 3 times that of the smallest circle(Use Color.RED) . The second circle is white with a radius of 2 times that of the smallest cirele. (Use Color.WHITE The smallest circle is red again with the radius given in the constructor. (Use Color.RED) You will write the TargetComponent class to construct and draw two Targets objects given The center is at 50, 60. The small radius is 15 The center is at 30, 150. The small radius is 5 TargetViewer is provided.

Explanation / Answer

1) As per in the given question we have to create a rainbow using java. Instead I'll provide you the basic code which wil be more interactive and easy to help you to display the rainbow using the program code.

2) Will start with the code:

3) Now, 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.

4) Follow the instructions below and fill in the blanks in Rainbow.java.

a) Start the Rainbow project.

b)Add a complete comment header with your name before the class declaration at the top of the file.

c) 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.

d) 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.

e) Declare a local variable largeRadius that represents the radius of the largest (red) semicircle and initialize it to 1/4 of width.

f) 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.

g) 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.

h) 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.

i) Test your program.

j) Submit your completed program and run output. Your run output (the rainbow picture) can be included by capturing the screen output (Alt-PrintScrn), pasting it into a graphics program (such as MS Paint) and then saving the image to your Eclipse project directory.

5)