Problem Solving Assignment #3
Turnin for Extra Credit due Monday, January 28th, 11:59 pm
Turnin due Tuesday, January 29th, 11:59 pm
Interview due Friday, February 1st, 12:00 pm
Required Reading: Chapter 2, Chapter 3, Chapter 4, Chapter 5
Please read this whole page and be able to answer the understanding questions before starting on this assignment. Ask a tutor, TA or instructor if you have any questions before you begin. You must write your code in the files in your PSA3 folder.
You will work with a partner on this PSA. Before you begin you MUST have a partner. Please review the guidelines for pair programming. There is an individual interview required for this and every PSA worth 20% of each assignment grade.
Note: This PSA has a total of 16 points. However, all PSA assignments are weighted equally. The interview is always 20% of the total PSA grade (i.e. if you managed to obtain all 16 points but failed to complete an interview your total PSA grade would be 80%).
Please read this whole page and be able to answer the understanding questions before starting on this assignment. Ask a tutor, TA or instructor if you have any questions before you begin. You must write your code in the files in your PSA3 folder.
You will work with a partner on this PSA. Before you begin you MUST have a partner. Please review the guidelines for pair programming. There is an individual interview required for this and every PSA worth 20% of each assignment grade.
Note: This PSA has a total of 16 points. However, all PSA assignments are weighted equally. The interview is always 20% of the total PSA grade (i.e. if you managed to obtain all 16 points but failed to complete an interview your total PSA grade would be 80%).
Setup
1) Right-click in an open space on the Desktop and select 'Open in Terminal' from the drop down menu.
(it will bring up the following window)
(it will bring up the following window)
2) Highlight the following 10 lines with the mouse, right-click to copy:
cd ../public/PSA3
make directories
make install
cd
cd PSA3
mv PSA3A.java.empty PSA3A.java
mv PSA3B.java.empty PSA3B.java
mv Picture.java.empty Picture.java
ls
3) Select the terminal window with the mouse and right-click to paste.
4) Verify that the 'PSA3A.java', 'PSA3B.java', 'Picture.java' files are shown as the result of the last command.
Following these procedures, your files will be named correctly and be located in the correct places. For every assignment you need to follow correct
naming of assignments in the correct locations to get credit for your work.
5) Proceed to start your programming assignment. You must write your code in the files in your PSA3 folder.
Problem
Color Subtraction - 6 points Total
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 method in PSA3A.java to test your subtractColor method by showing and exploring the original and changed pictures.
Method: subtractColor (3 points Total - 2 pts for producing the proper effect, 1pt for proper parameters)
Method: PSA3A.java - main (3 points Total - 2 pt for proper execution, 1pt for calling the subtractColor method)
Method: negative (2 points Total - 1pt for proper parameters, 1pt for producing the proper effect)
Method: grayscale (2 points Total - 1pt for proper parameters, 1pt for producing the proper effect)
Method: myFilter (2 points Total - 1pt for proper parameters, 1pt for producing the proper effect)
Method: PSA3B.java - main (4 points Total - 3pts for calling the correct methods on the correct parts of the image, 1pt for displaying the new image)
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 method in PSA3A.java to test your subtractColor method by showing and exploring the original and changed pictures.
Method: subtractColor (3 points Total - 2 pts for producing the proper effect, 1pt for proper parameters)
- Add a method to Picture.java called subtractColor. Your method takes three int parameters which specify how much the color components of all pixels of the picture should be reduced (red, green and blue, in that order). 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 the red, green and blue color values should be reduced to (50, 180, 5), respectively, after your method is called. Note that a negative color value is automatically counted as 0. The order in which the color values are passed to the method should be red, green, and blue, in that order. .
- The method should reduce the color values of ALL the pixels in the picture.
- Test your method in PSA3A.java (in the main method):
Method: PSA3A.java - main (3 points Total - 2 pt for proper execution, 1pt for calling the subtractColor method)
- Fill in the statements (inside the main method) to test and show the results of your subtractColor method:
- Use the FileChooser.pickAFile() command to pick a picture (you can pick a picture in the mediasources directory -- or better yet -- use one of your own!).
- BEFORE you modify this picture, we want to make a COPY of it (so we can "see" the difference after it is changed (use the same technique shown in lab). Make another new Picture that is a copy of the one you just made. Use the constructor that has you do Picture copy = new Picture(original);
- Next explore the original picture you picked.
- Note that you can explore a picture by calling the predefined explore() method on that picture.
- Then call your method to change the COPY of the picture you made.
- Then explore the copy of the picture after you called your method on it to change it.
- Mouse around to explore the original and changed picture to make sure your method works correctly (that is a specific pixel in the original picture has been reduced by the right amounts in its red, green, and blue components for the copied picture).
Method: negative (2 points Total - 1pt for proper parameters, 1pt for producing the proper effect)
- Add a method (negative) to Picture.java that takes in two int parameters (1 pt), which are the first and last index of the region (part) of the pixel array to be modified.
- The method should access the pixel array of the calling picture object (that is use the this.getPixels() line to store the picture's pixels in an array).
- Then, using a while loop, invert the color (create the negative) of each pixel between (and including) the provided indices. (1 pt)
- The method header for this is:
Method: grayscale (2 points Total - 1pt for proper parameters, 1pt for producing the proper effect)
- Add another method to Picture.java named grayscale similar to the negative method which also has the first and last index in the pixel array as parameters (1 pt). For those pixels in range, you need to change the colors to their appropriate grayscale color using a while loop. (1 pt)
- The method header for this is:
Method: myFilter (2 points Total - 1pt for proper parameters, 1pt for producing the proper effect)
- Add another method to Picture.java, similar to the the negative and grayscale methods, which also takes at least two parameters (1 pt): the first and last index in the pixel array to be modified. Apply any effect of your choice to the pixels in range using a while loop. (1 pt)
- This filter cannot be grayscale, negative, a single color filter and and any filter mentioned in the book.
Method: PSA3B.java - main (4 points Total - 3pts for calling the correct methods on the correct parts of the image, 1pt for displaying the new image)
- This file will load a Picture of your choice (either a bookClasses image or a personal image) using FileChooser.pickAFile().
- Display the original image.
- Call the negative method on the first 1/3 of pixels in the image (1 pt). Next call the grayscale method on the middle 1/3 of pixels in the image (1 pt). Then apply the myFilter method to the bottom 1/3 of the pixels in the image(1 pt).
- Lastly, display your new image. (1 pt)
Sample Code
PSA3A.java
/* Filename: PSA3A.java
* Created by: Vinay Venkatesh, cs8w3 and Alberto Garcia, cs8w4
* Due Date: January 28, 2013
*
* Partner Histories:
* Vinay Venkatesh:
PSA1 Partner: Garret Rodriguez, cs8w1
PSA2 Partner: Shari Haynes, cw8w2
PSA3 Partner: Alberto Garcia, cs8w4
PSA4 Partner: To be determined...
PSA5 Partner: To be determined...
PSA6 Partner: To be determined...
PSA7 Partner: To be determined...
PSA8 Partner: To be determined...
PSA9 Partner: To be determined...
* Alberto Garcia:
PSA1 Partner: Shari Haynes, cs8w2
PSA2 Partner: Garret Rodriguez, cs8w1
PSA3 Partner: Vinay Venkatesh, cs8w3
PSA4 Partner: To be determined...
PSA5 Partner: To be determined...
PSA6 Partner: To be determined...
PSA7 Partner: To be determined...
PSA8 Partner: To be determined...
PSA9 Partner: To be determined...
*/
* Date:
* Description: This class is designed to... */
public class PSA3A
{
//The line below is magic, you don't have to understand it (yet)
public static void main (String[] args)
{
...
}
}
PSA3B.java
/* Filename: PSA3B.java
* Created by: Vinay Venkatesh, cs8w3 and Alberto Garcia, cs8w4
* Due Date: January 28, 2013
*
* Partner Histories:
* Vinay Venkatesh:
PSA1 Partner: Garret Rodriguez, cs8w1
PSA2 Partner: Shari Haynes, cw8w2
PSA3 Partner: Alberto Garcia, cs8w4
PSA4 Partner: To be determined...
PSA5 Partner: To be determined...
PSA6 Partner: To be determined...
PSA7 Partner: To be determined...
PSA8 Partner: To be determined...
PSA9 Partner: To be determined...
* Alberto Garcia:
PSA1 Partner: Shari Haynes, cs8w2
PSA2 Partner: Garret Rodriguez, cs8w1
PSA3 Partner: Vinay Venkatesh, cs8w3
PSA4 Partner: To be determined...
PSA5 Partner: To be determined...
PSA6 Partner: To be determined...
PSA7 Partner: To be determined...
PSA8 Partner: To be determined...
PSA9 Partner: To be determined...
*/
* Date:
* Description: This class is designed to... */
public class PSA3B
{
//The line below is magic, you don't have to understand it (yet)
public static void main (String[] args)
{
...
}
}
/* Filename: PSA3A.java
* Created by: Vinay Venkatesh, cs8w3 and Alberto Garcia, cs8w4
* Due Date: January 28, 2013
*
* Partner Histories:
* Vinay Venkatesh:
PSA1 Partner: Garret Rodriguez, cs8w1
PSA2 Partner: Shari Haynes, cw8w2
PSA3 Partner: Alberto Garcia, cs8w4
PSA4 Partner: To be determined...
PSA5 Partner: To be determined...
PSA6 Partner: To be determined...
PSA7 Partner: To be determined...
PSA8 Partner: To be determined...
PSA9 Partner: To be determined...
* Alberto Garcia:
PSA1 Partner: Shari Haynes, cs8w2
PSA2 Partner: Garret Rodriguez, cs8w1
PSA3 Partner: Vinay Venkatesh, cs8w3
PSA4 Partner: To be determined...
PSA5 Partner: To be determined...
PSA6 Partner: To be determined...
PSA7 Partner: To be determined...
PSA8 Partner: To be determined...
PSA9 Partner: To be determined...
*/
* Date:
* Description: This class is designed to... */
public class PSA3A
{
//The line below is magic, you don't have to understand it (yet)
public static void main (String[] args)
{
...
}
}
PSA3B.java
/* Filename: PSA3B.java
* Created by: Vinay Venkatesh, cs8w3 and Alberto Garcia, cs8w4
* Due Date: January 28, 2013
*
* Partner Histories:
* Vinay Venkatesh:
PSA1 Partner: Garret Rodriguez, cs8w1
PSA2 Partner: Shari Haynes, cw8w2
PSA3 Partner: Alberto Garcia, cs8w4
PSA4 Partner: To be determined...
PSA5 Partner: To be determined...
PSA6 Partner: To be determined...
PSA7 Partner: To be determined...
PSA8 Partner: To be determined...
PSA9 Partner: To be determined...
* Alberto Garcia:
PSA1 Partner: Shari Haynes, cs8w2
PSA2 Partner: Garret Rodriguez, cs8w1
PSA3 Partner: Vinay Venkatesh, cs8w3
PSA4 Partner: To be determined...
PSA5 Partner: To be determined...
PSA6 Partner: To be determined...
PSA7 Partner: To be determined...
PSA8 Partner: To be determined...
PSA9 Partner: To be determined...
*/
* Date:
* Description: This class is designed to... */
public class PSA3B
{
//The line below is magic, you don't have to understand it (yet)
public static void main (String[] args)
{
...
}
}
How to turnin your homework
1) Open the terminal
2) cd PSA3
3) autograder login -e yourucsdemailhere -p (wait for password prompt)
4) type in your password
5) turnin PSA3
2) cd PSA3
3) autograder login -e yourucsdemailhere -p (wait for password prompt)
4) type in your password
5) turnin PSA3
PSA3 Understanding Quiz
Which of the following is a correct header for the method subtractColor in Picture.java Choose one answer. a. public Picture subtractColor()
b. public Picture subtractColor(int r, int g, int b)
c. public void subtractColor(int r, int g, int b)
d. public void subtractColor()
What do the integer start and end parameters passed to the negative, grayscale, and myFilter methods represent? Choose one answer.
a. The region specified by the "start" x and the "end" x of the Picture - accessible via getPixel(x) - to apply the affect
b. The region specified by the "start" x and y and the "end" x and y of the Picture - accessible via getPixel(x,y) - to apply the affect
c. The region specified by the "start" and "end" index into the Picture's array of pixels - the array is accessible via getPixels() - to apply the affect
b. public Picture subtractColor(int r, int g, int b)
c. public void subtractColor(int r, int g, int b)
d. public void subtractColor()
What do the integer start and end parameters passed to the negative, grayscale, and myFilter methods represent? Choose one answer.
a. The region specified by the "start" x and the "end" x of the Picture - accessible via getPixel(x) - to apply the affect
b. The region specified by the "start" x and y and the "end" x and y of the Picture - accessible via getPixel(x,y) - to apply the affect
c. The region specified by the "start" and "end" index into the Picture's array of pixels - the array is accessible via getPixels() - to apply the affect