Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is activity 5 and 6 Picture.java public class Picture extends SimplePicture { ///////////////////// constructors ////////////////////////////////// /** * Constructor that takes no arguments */ public

image text in transcribedimage text in transcribed

This is activity 5 and 6

Picture.java

public class Picture extends SimplePicture { ///////////////////// constructors ////////////////////////////////// /** * Constructor that takes no arguments */ public Picture () { /* not needed but use it to show students the implicit call to super() * child constructors always call a parent constructor */ super(); } /** * Constructor that takes a file name and creates the picture * @param fileName the name of the file to create the picture from */ public Picture(String fileName) { // let the parent class handle this fileName super(fileName); } /** * Constructor that takes the width and height * @param height the height of the desired picture * @param width the width of the desired picture */ public Picture(int height, int width) { // let the parent class handle this width and height super(width, height); } /** * Constructor that takes a picture and creates a * copy of that picture * @param copyPicture the picture to copy */ public Picture(Picture copyPicture) { // let the parent class do the copy super(copyPicture); } /** * Constructor that takes a buffered image * @param image the buffered image to use */ public Picture(BufferedImage image) { super(image); } ////////////////////// methods /////////////////////////////////////// /** * Method to return a string with information about this picture. * @return a string with information about the picture such as fileName, * height and width. */ public String toString() { String output = "Picture, filename " + getFileName() + " height " + getHeight() + " width " + getWidth(); return output; } /////////////////////////// Activity 5 //////////////////////////// /** Method to set the blue to 0 */ public void zeroBlue() { Pixel[][] pixels = this.getPixels2D(); for (Pixel[] rowArray : pixels) { for (Pixel pixelObj : rowArray) { pixelObj.setBlue(0); } } } // keepOnlyBlue // keepOnlyRed // keepOnlyGreen // nagate // grayscale // fixUnderWater - optional /////////////////////////// Activity 6 //////////////////////////// /** Method that mirrors the picture around a * vertical mirror in the center of the picture * from left to right */ public void mirrorVertical() { Pixel[][] pixels = this.getPixels2D(); Pixel leftPixel = null; Pixel rightPixel = null; int width = pixels[0].length; for (int row = 0; row

PictureTester.Java

public class PictureTester { /** Method to test zeroBlue - Activity 5 */ public static void testZeroBlue() { Picture beach = new Picture("beach.jpg"); beach.explore(); beach.zeroBlue(); beach.explore(); } /** Method to test mirrorVertical */ public static void testMirrorVertical() { Picture caterpillar = new Picture("caterpillar.jpg"); caterpillar.explore(); caterpillar.mirrorVertical(); caterpillar.explore(); } /** Method to test mirrorTemple */ public static void testMirrorTemple() { Picture temple = new Picture("temple.jpg"); temple.explore(); temple.mirrorTemple(); temple.explore(); } /** Method to test the collage method */ public static void testCollage() { Picture canvas = new Picture("640x480.jpg"); canvas.createCollage(); canvas.explore(); } /** Method to test edgeDetection */ public static void testEdgeDetection() { Picture swan = new Picture("swan.jpg"); swan.edgeDetection(10); swan.explore(); } /** Main method for testing. Every class can have a main * method in Java */ public static void main(String[] args) { // uncomment a call here to run a test and // comment out the ones you don't want to run // Activity 5 testZeroBlue(); //testKeepOnlyBlue(); //testKeepOnlyRed(); //testKeepOnlyGreen(); //testNegate(); //testGrayscale(); // Activity 5 Challenge - optional //testFixUnderwater(); // Activity 6 //testMirrorVertical(); //testMirrorVerticalRightToLeft(); //testMirrorHorizontal(); //testMirrorHorizontalBotToTop(); // Activity 6 Challenge - optional //testMirrorDiagonal(); // Activity 7 //testMirrorTemple(); //testMirrorArms(); //testMirrorGull(); }

}

Exercises Complete the exercises using the Java files and then make note of the results in the 08.07 Worksheet. 1. Using the zeroBlue method as a starting point, choose to write one of the following methods: keepOnlyBlue, keepOnlyRed, or keepOnlyGreen. For example, write the method keepOnlyBlue so that will keep only the blue values; that is, it will set the red and green values to zero. Create a class (static) method to test this new method in the class Picture Tester. Be sure to call the new test method in the main method in PictureTester. 2. Write the negate method to negate all the pixels in a picture. To negate a picture, set the red value to 255 minus the current red value, the green value to 255 minus the current green value, and the blue value to 255 minus the current blue value. Create a class (static) method to test this new method in the class PictureTester. Be sure to call the new test method in the main method in Picture Tester. 3. Write the grayscale method to turn the picture into shades of gray. For each pixel, set the red, green, and blue values to the average of the current red, green, and blue values (add all three values and divide by 3). Create a class (static) method to test this new method in the class PictureTester. Be sure to call the new test method in the main method in Picture Tester. 4. Challenge! Implementing this method is optional. Explore the water.jpg picture in the images folder. Write a method fixUnderwater to modify the pixel colors to make the fish easier to see. Create a class (static) method to test this new method in the class PictureTester. Be sure to call the new test method in the main method in Picture Tester. Complete the exercises using the Java files and then make note of the results in the 08.07 Worksheet. 1. Write the method mirrorVerticalRightToLeft that mirrors a picture around a mirror placed vertically from right to left. Hint: you can copy the body of mirrorvertical and only change one line in the body of the method to accomplish this. Write a class (static) test method called testMirrorverticalRightToLeft in PictureTester to test this new method and call it in the main method. 2. Write the method mirrorHorizontal that mirrors a picture around a mirror placed horizontally at the middle of the height of the picture. Mirror from top to bottom as shown in the pictures below (Figure 8). Write a class (static) test method in PictureTester to test this new method and call it in the main method. 2017 College Board Figure 8: Original picture (left) and mirrored from top to bottom (right) 3. Write the method mirrorHorizontalBotToTop that mirrors the picture around a mirror placed horizontally from bottom to top. Hint: you can copy the body of mirrorHorizontal and only change one line to accomplish this. Write a class (static) test method in PictureTester to test this new method and call it in the main method

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

Step: 3

blur-text-image

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago