Question
Please help me with the question below and add explanations for the lines of code please. Write a program that subtracts the red, blue, and
Please help me with the question below and add explanations for the lines of code please.
Write a program that subtracts the red, blue, and green components of all pixels of a Picture by specified values. To do this, you will write one method in Picture.java and a main program to test your method by showing and exploring the original and changed pictures.
Method: subtractColor
Add a method to Picture.java called subtractColor (be sure to use PSA3/bookClasses/Picture.java). Your method takes three parameters. These parameters specify how much the color components of all pixels of the picture should be reduced (2 pts).
o The order in which the color values are passed to the method should be red, green, and then blue.
o For example, if you pass (100, 20, 45) as parameters to your method and the color values of one of the pixels of the picture is (150, 200, 50), then these color values should be reduced to (50, 180, 5) after your method is called. Note that a negative color value is automatically counted as 0 as long as you are using setRed(), setGreen(), or setBlue(). If you try to use setColor() with a new Color() as a parameter, you will get an error when one of the color components is negative. The method should reduce the color values of ALL the pixels in the picture (2 pts).
Testing subtractColor:
Download PSA3A.java from the course website and save this file in PSA3/bookClasses.
PSA3A.java is worth 4 points:
o (2 pts) for proper execution and calling the new method in Picture.java
o (2 pts) for proper commenting of PSA3A.java and method in Picture.java
Fill in the statements (inside the main method) you need to test and show the results of your methods:
o Use the FileChooser.pickAFile() command to pick a picture. You can choose a file from the mediaSources directory from your book CD. However, it is more fun to use your own pictures to make it more personal.
o Before you modify this picture, we want to make a COPY of it so that we
can "see" the difference after it is changed. To make a copy of the
original, use the copy constructor that looks like this:
Picture copy = new Picture(original); o Next explore the original picture you picked. Note that you can explore a
picture by calling the predefined explore() method on that picture. o Then call your method to change the COPY of the picture you made. o Then explore the copy of the picture after you called your method on it to change it.
o Mouse around to explore the original and changed picture to make sure
your method works correctly. In other words, find a specific pixel and
make sure that it has been reduced by the correct amount of red, green, and blue in the copied picture.
****Code for PSA3:
public class PSA3B { //The line below is magic, you don't have to understand it (yet) public static void main (String[] args) { // Remove this comment and add your code here. } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started