Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The goal of this assignment is to use loop patterns to solve a variety of problems Starting 1. In Eclipse, create a new project or

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

The goal of this assignment is to use loop patterns to solve a variety of problems Starting 1. In Eclipse, create a new project or use an assignments one. Add a package a4, and a class SearchAndOptimizingLoops to that package. Copy and paste Picture.java and an image file from prior work into this package (Picture.java should update itself to the a4 package). 2. In your class, implement the static methods specified below 3. 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 4. 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 expected as well as the actual result from the method in a neatly formatted way. 5. 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 6. None of your methods except for main may print anything to the console. 7. Ensure you have consistent spacing and indenting in your file, proper and consistent indenting, and a Javadoc comment about the start of the class definition with your name, assignment number and class 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 1. Method name: findSmallestPositiveNumber Parameter(s): A String containing integer numbers separated by spaces. There must be at least one positive number in the String. Return value: An int value that is the smallest number greater than O in the input string Example: findSmallestPositiveNumber"2 -4 5") should return 2. 2. Method name: lowestAlphabetically Parameter(s): A String of lower-case words separated by spaces and made up of the letters a-z. The String will have at least one word. Return value: A String containing the lowest alphabetical word. The String method comparelo0 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" 3. Method name: findSmallestNumberlnTwoStrings Parameter(s): Two String parameters. Each string is made up of numbers separated by spaces. The first string must have at least one number. Return value: An int containing the smallest number found in the two strings. Example: findSmallestNumberlnTwoStrings("12 3 5" "2-1 10") would return -1 4. Method name: curveScores Parameter(s): A String containing numbers from O to 100. Each number is separated by a space. There must be at least one number in the String. Return value: A String of numbers scaled so that the highest number in the parameter String becomes 100 and all the other numbers are moved up by the same amount. This String should also be numbers separated by spaces with no additional characters. Example: curveScores("45 85 90") would return "55 95 100 5. 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, 1 package a3; Compilation: javac Picture.javal 20 21 import Java.awt.Color:D 41 42/** 43 This class provides methods for manipulating individual pixels of 44an image using the RGB color format. The alpha component (for transparency) 45 * is not currently supported. 46The original image can be read from a f@code PNG), (@code GIF), 47or {@code 3PEG) file or the user can create a blank image of a given dimension. 48 This class includes methods for displaying the image in a window on 49the screen or saving it to a file 50 *

51 *Pixel ( col, row) is column col/e> and row row. 52* By default, the origin (e, 0) is the pixel in the top-left corner, 53 which is a common convention in image processing. 54 * The method {@link #setoriginLowerLeft()) change the origin to the lower left 55 *

56 The (@code get()) and (@code setO methods use {@link Color objects to get 57*or set the color of the specified pixel 58 The @code getRGB) and (@code setRGB) methods use a 32-bit (@code int) 59 *to encode the color, thereby avoiding the need to create temporary 60 *@code Color objects. The red (R), green (G), and blue (B) components 61 are encoded using the least significant 24 bits. 62 Given a 32-bit (@code int encoding the color, the following code extracts 63 the RGB components: 64 * > 16) & 0xFF; 66 * int g= (rgb>> 8) & 0xFF; 67 * int b= (rgb>> 0) & 0xFF; 68 /prex/blockquote> 69 Given the RGB components (8-bits each) of a color, 70 *the following statement packs it into a 32-bit (@code intj: 71 *

 72 * int rgb (r  74 *

75 A WK/em>-by-Ken>H picture uses 4 Kem>W Hk/em> bytes of memory, 76 *since the color of each pixel is encoded as a 32-bit . 77*

78 For additional documentation, see 79 *a href-"https://introcs.cs.princeton.edu/31datatype" Section 3.1 of 80 * Computer Science: An Interdisciplinary Approach 81by Robert Sedgewick and Kevin Wayne 82 *See (@link GrayscalePicture for a version that supports grayscale images. 84 *@author Robert Sedgewick 85author Kevin Wayne 86*/ 87 public final class Picture implements ActionListener { private BufferedImage image; private JFrame frame; private String filename; private boolean isOriginUppe r Left = true; // location of origin private final int width, height; // the rasterized image // on-screen view // name of file 89 90 91 92 93 94 ** 95 96 97 98 // width and height Creates a f@code width-by-(@code height picture, with @code width columns * and @code height} rows, where each pixel is black. @param width the width of the picture @param height the height of the picture @throws IllegalArgumentException if @code width is negative @throws IllegalArgumentException if @code height) is negative 100 101 102 103 public Picture(int width, int height) 104 105 106 107 108 109 110 if (width = height()) throw new IllegalArgumentException("row index must be between 0 and " + (height() - 1) + ": " + row); if (col = width()) throw new IllegalArgumentException("column index must be between0 and "+ (width() - 1) + ": " + col); Returns the color of pixel (@code col), @code row)) as a (@link java.awt.Color). @param col the column index @param row the row index ereturn the color of pixel (f@code col), (@code row)) * @throws IllegalArgumentException unless both {@code 0 widthheightmatrix of pixels, the red, green, and blue components. @return a string representation of this picture *where the color of a pixel is represented using 6 hex digits to encode StringBuilder sb = new StringBuilder(); sb.append(width +"-by-"height " picture (RGB values given in hex) "); 378 379 380 381 382 383 384 385 386 387 388 389 390 391 /** 392 393 394 395 396 for (int row = 0; row

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

Identify three improper customer etiquette behaviors.

Answered: 1 week ago