Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

Are these written ground rules?

Answered: 1 week ago

Question

Have ground rules been established for the team?

Answered: 1 week ago

Question

a. How are members selected to join the team?

Answered: 1 week ago