Question: In this code-writing practice, you will write two methods that paint Picture.The first method will paint the Picture a solid color, and the second method

In this code-writing practice, you will write two methods that "paint" Picture.The first method will "paint" the Picture a solid color, and the second method will "paint" the Picture a vertically striped pattern.

createSolid

  • Add a method to Picture.java (in the bookClasses folder) called createSolid.This method creates a "solid canvas" of a particular color, which is specified by the parameters.This method takes three (3) parameters, in this order:
  • the desired red component value
  • the desired green component value
  • the desired blue component value
  • The method should set ALL the pixels in the picture to the color values indicated by the parameters.
  • This method must be implemented using a "for each" loop of the style of section 4.3.1 of the reading for this module.I encourage you to try out for yourself how you would implement this method with other types of loops (e.g. a while loop), but this is not required.
  • This method is worth 4 points:
  • Produce a solid color(1 pt)
  • Proper use of parameters(1 pt)

createPattern

  • Add a method to Picture.java called createPattern.This method should set every other pixel in the picture to "black" and the other pixels to the color specified by the parameters.In other words: all pixels in the pixelArray with even indices (e.g. 0, 2, 4, 6, 8) should be black while the pixels with odd indices (e.g. 1, 3, 5, 7) should be set to the color values passed into the method as parameters.
  • This method takes three (3) parameters, in this order:
  • the desired red component value
  • the desired green component value
  • the desired blue component value
  • This methodmustbe implemented by using while loops.In fact, you should use two sequential while loops.That is, the first while loop should finish before the second while loop starts - don't nest the loops (put one loop inside the other) or you'll make the problem more challenging!
  • Hint:Think about how you might want to update the index variable so that one loop changes the even-numbered indices and the other loop changes the odd-numbered indices.
  • Do not use nested loops or conditional statements!
  • This method should NOT call createSolid
  • This method is worth 8 points:
  • Properly using two while loops(3 pts)
  • Proper use of parameters(1 pt)
  • Create the correct (striped) pattern(1 pt)

Painting.java

To test your methods (in an application), downloadPainting.javaand save it in your bookClasses folder.This is where the application to test the createSolid and createPattern methods.

  • Open Painting.java in Dr. Java and add the statements (inside the main method) that you need to test your newly created methods and show the results of your methods.
  • For each method, I suggest you use the FileChooser.pickAFile() command to pick the file "640x480.jpg" (in the mediasources folder)
  • Next, call your method
  • Finally, explore the result
  • Painting.java is worth 6 points:
  • Proper execution and calling the new createSolid and createPattern methods(3 pts)
  • Proper commenting of Painting.java and the methods in Picture.java(2 pt)

The final images will look similar to

Attach the following files to your submission:

  • Painting.java
  • Picture.java

There is no need to share a screenshot of this code-writing practice.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!