The goal of this assignment is to use loop patterns to solve a variety of problems. Starting In Eclipse, create a new project or use an assignments one. Add a package a4, and a class LoopPatterns to...

The goal of this assignment is to use loop patterns to solve a variety of problems.

Starting


In Eclipse, create a new project or use an assignments one. Add a package a4, and a class LoopPatterns to that package. DownloadPicture.java(Links to an external site.)and an example image fileArches.jpg(Links to an external site.)and add then to the package. (Check that the Picture.java file has package a4; as the first line).


In your class, implement the static methods specified below.


All methods you write should have a Javadoc comment with a description of what the method does and a @param for each parameter and a @return describing what information is returned. Add a Javadoc for the class with basic class and author information.


Add a main method with tests for each method. Your tests should cover possible return values (such as true or false) as well as special cases (for example, empty strings). Your tests should print what was tested, how it was tested, and the actual result from the method in a neatly formatted way.


For testing the image processing methods, you should load an image, call the method, and show the result as one way of testing. You should also write a test that shows how a single pixel changes. Use get to extract a single pixel Color from both the original image and the result image and print those out. If you do a println on a Color object, it will print a reasonable text representation of the reg, green, and blue components.


You do not need to test for cases that are prohibited in the description. If the description says that there is at least X in the parameter, then you do not need to test for the truth of that constraint.


None of your methods except for main may print anything to the console. None of your methods except for main may show an image (this will definitely crash the autograder).


Ensure you have consistent spacing and indenting in your file (look at Source->Format or Indent as a way to start getting good structure) and meaningful variable names.


For optimization loops, make sure you are starting off the search as described in the lecture video on optimization. Other approaches will not receive full credit.


Required Methods


You must implement each of the described methods with method name, return type and parameters carefully checked against the specification. When parameters are specified you must use the order they are listed in. You may implement additional methods if they aid your problem-solving.



Method name: lowestAlphabetically

Parameter(s): A String array of lower-case words, each made up only of the letters a-z. The array will have at least one word.

Return value: A String containing the lowest alphabetical word. The String method compareTo() does a lexicographic comparison between two strings, which allows you to test for the lowest alphabetical word. Read documentation on compareTo() in order to understand how to use it.

Example: lowestAlphabetically(["cat", "dog", "apple", "fish"]) would return "apple".

Hint: This example is as much about getting practice reading documentation about code as it is applying a loop pattern to this problem.


Method name: findSmallestNumberInTwoArrays

Parameter(s): Two int array parameters. The first array must be at least length 1. The second array may be length 0.

Return value: An int containing the smallest number found in the two arrays.

Example: findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10]) would return -1.


Method name: curveScores

Parameter(s): An int array containing numbers that can range from 0 to 100. The array is at least length 1.

Return value: A new int array of numbers changed so that the highest number in the parameter array becomes 100 and all the other numbers are moved up by the same amount. The ordering should remain the same between the input and output array.

Example: curveScores([45, 85, 90]) would return [55, 95, 100] as the 90 gets curved to 100 and the other numbers are shifted up by 10.


Method name: findSmallestPositiveNumber

Parameter(s): A double array. There will be at least one positive number in the array.

Return value: A double value that is the smallest number greater than 0.0 in the array.

Example: findSmallestPositiveNumber([2.0, -4.0, 5.0]) should return 2.0.

Note: This one is a little tricky. Work out some examples by hand. Make sure you can state your problem-solving approach in words before trying to code. If you are asking for help with code, be ready to show examples worked by hand and be ready to state how you think you are solving it. It is not acceptable to jump to coding without doing these preparatory steps.

For these next problems, make sure you have looked at materials for Lecture 13 (at the end of the Week 5 activities page).


Method name: containsThisColor

Parameter(s): A Picture object that is at least 1x1 pixels and a Color object.

Return value: A boolean value. Return true if the Color parameter matches one of the pixels in the image and false otherwise. A color match is done by using the .equals method rather than ==.

Example: For a 1 pixel picture with a color of (100, 200, 50) and a color to search for of (100, 100, 100), this method would return false.


Method name: makeGrey

Parameter(s): A Picture object. This is the source image.

Return value: A new Picture object. Each pixel in the returned Picture should have a color that is the grey scale equivalent of the corresponding pixel (the pixel with the same x and y coordinate) in the source image. In general, a grey scale color has different ways of being calculated - you must calculate it by averaging the red, green, and blue values from the pixel in the source image and then setting each of the red, green, and blue components of the pixel in the new image to this grey intensity.

Example: A single pixel image with a color (100, 200, 50) would have a grey intensity of XXXXXXXXXX)/3 = 116 and the new image would be a single pixel with color (116, 116, 116). An example of what a result might look like is the following (please don't treat this as a reference image as I am unsure of what compression or changes might be applied by Canvas).|


Method name: makeNegative

Parameter(s): A Picture object. This is the source image.

Return value: A new Picture object with the colors changed to a photonegative style. Each pixel in the returned Picture should have a color that is a "negative" of the corresponding pixel (the pixel with the same x and y coordinate) in the source image. You must calculate this by taking each red, green, and blue value in the source and setting it to 255 - each value in the returned image.

Example: A single pixel image with a color (100, 200, 50) would make a new image with a single pixel with color (155, 55, 205).

An example of what a result might look like is the following (please don't treat this as a reference image as I am unsure of what compression or changes might be applied by Canvas).


Method name: safeColor

Parameter(s): A single int value representing one of a red, green, or blue value.

Return value: An int that is the same as the parameter, except that it is 0 if the original value is less than zero and it is 255 if the original value is greater than 255.

Example: If the parameter is 100, then the return value should be 100. If the parameter is 300, then the return value should be 255.


Method name: makeBrighter

Parameter(s): A Picture object. This is the source image.

Return value: A new Picture object with the color values doubled. Each pixel in the returned Picture should have a color that has each red, green, and blue component twice that of the corresponding pixel (the pixel with the same x and y coordinate) in the source image. Unthinkingly applied, this doubling will yield color values outside the allowed 0-255 range, which crashes the program. Clamp each calculated red, green, and blue value to a safe range by applying the safeColor method written above to the colors you calculate.

Example: A single pixel image with a color (100, 200, 50) would make a new image with a single pixel with color (200, 255, 100).

An example of what a result might look like is the following (please don't treat this as a reference image as I am unsure of what compression or changes might be applied by Canvas).



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here