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...

1 answer below ยป

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 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).

  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. Add a Javadoc for the class with basic class and author information.

  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 tested, how it was tested, and the actual result from the method in a neatly formatted way.

  5. 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.

  6. 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.

  7. 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).

  8. 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.

  9. 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.





    1. 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.


    2. 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.


    3. 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.


    4. 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).


    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.


    6. 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 (100+200+50)/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).|

      A grey image



    7. 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).

      A color-inverted image



    8. 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.


    9. 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).

      A brightened image example.



Answered Same DaySep 29, 2021

Answer To: The goal of this assignment is to use loop patterns to solve a variety of problems. Starting In...

Shivani answered on Oct 01 2021
149 Votes
Picture/.metadata/.lock
Picture/.metadata/.log
!SESSION 2020-09-30 23:08:23.082 -----------------------------------------------
eclipse.buildId=4.17.0.I20200902-1800
java.version=11.0.4
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product org.eclipse.epp.package.java.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product
!ENTRY org.eclipse.jface 2 0 2020-09-30 23:09:16.746
!MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation.
!SUBENTRY 1 org.eclipse.jface 2 0 2020-09-30 23:09:16.746
!MESSAGE A conflict occurred for CTRL+SHIFT+T:
Binding(CTRL+SHIFT+T,
    ParameterizedCommand(Command(org.eclipse.jdt.ui.navigate.open.type,Open Type,
        Open a type in a Java editor,
        Category(org.eclipse.ui.category.navigate,Navigate,null,true),
        org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@74ab8610,
        ,,true),null),
    org.eclipse.ui.defaultAcceleratorConfiguration,
    org.eclipse.ui.contexts.window,,,system)
Binding(CTRL+SHIFT+T,
    ParameterizedCommand(Command(org.eclipse.lsp4e.symbolinworkspace,Go to Symbol in Workspace,
        ,
        Category(org.eclipse.lsp4e.category,Language Servers,null,true),
        org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@231c521e,
        ,,true),null),
    org.eclipse.ui.defaultAcceleratorConfiguration,
    org.eclipse.ui.contexts.window,,,system)
!ENTRY org.eclipse.egit.ui 2 0 2020-09-30 23:09:22.315
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
user global configuration and to define the default location to store repositories: 'C:\Users\Shivani'. If this is
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
EGit might behave differently since they see different configuration options.
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
!SESSION 2020-10-01 12:18:56.875 -----------------------------------------------
eclipse.buildId=4.17.0.I20200902-1800
java.version=11.0.4
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product org.eclipse.epp.package.java.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product
!ENTRY org.eclipse.jface 2 0 2020-10-01 12:19:13.078
!MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation.
!SUBENTRY 1 org.eclipse.jface 2 0 2020-10-01 12:19:13.078
!MESSAGE A conflict occurred for CTRL+SHIFT+T:
Binding(CTRL+SHIFT+T,
    ParameterizedCommand(Command(org.eclipse.jdt.ui.navigate.open.type,Open Type,
        Open a type in a Java editor,
        Category(org.eclipse.ui.category.navigate,Navigate,null,true),
        org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@683fe7b5,
        ,,true),null),
    org.eclipse.ui.defaultAcceleratorConfiguration,
    org.eclipse.ui.contexts.window,,,system)
Binding(CTRL+SHIFT+T,
    ParameterizedCommand(Command(org.eclipse.lsp4e.symbolinworkspace,Go to Symbol in Workspace,
        ,
        Category(org.eclipse.lsp4e.category,Language Servers,null,true),
        org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@5b5b8730,
        ,,true),null),
    org.eclipse.ui.defaultAcceleratorConfiguration,
    org.eclipse.ui.contexts.window,,,system)
!ENTRY org.eclipse.egit.ui 2 0 2020-10-01 12:19:22.927
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
user global configuration and to define the default location to store repositories: 'C:\Users\Shivani'. If this is
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
EGit might behave differently since they see different configuration options.
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
!ENTRY org.eclipse.jdt.core 4 4 2020-10-01 13:30:58.321
!MESSAGE Exception occurred during compilation unit conversion:
----------------------------------- SOURCE BEGIN -------------------------------------
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
            
             /*Method: curveScores(): method to find lowest alphabetical word
             * @param: arr-An int array containing numbers that can range from 0 to 100.
             * @return: 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.
             */
             public static int[] curveScores(int arr[])
             {
                 int maxIndx=0;
                 int offset=10;
                
                 // finding the index of the array where the max value lies
                 for(int i=1;i                 {
                     if(arr[i]>arr[maxIndx])
                         maxIndx=i;
                 }
                
                 // setting the maximum value to 100 now
                 arr[maxIndx]=100;
                
                 // traversing through the array to move up all the other values by offset amount
                 for(int i=0;i                 {
                     if(i != maxIndx)
                         arr[i] = arr[i] + offset;
                 }
                
                 return(arr);
                
             }
    
             /*Method: findSmallestPositiveNumber(): method to find smallest number greater than 0.0 in the array
             * @param: arr-A double array with atleast one positive number
             * @return: A double value that is the smallest number greater than 0.0 in the array.
             */
             public static double findSmallestPositiveNumber(double arr[])
             {
                 int countOfPositives=0;
                
                 // checking number of positives numbers in the array
                 for(int i=0; i                     {
                         if(arr[i]>0.0)
                             countOfPositives++;
                     }
                 if(countOfPositives<1)
                 {
                     System.out.println("There MUST BE ATLEAST 1 POSITIVE NUMBER in the array.");
                     return(0);
                 }
                
                 // traversing the array to find smallest number greater than 0.0 in the array
                 double smallest;
                 int foundFirst=0;
                 for(int i=0; i                 {
                     if(arr[i]>=0.0)
                     {
                         if(arr[i]>0.0 && foundFirst==0)
                             {
                             smallest = arr[i];
                             foundFirst = 1;
                             }
                         else(arr[i]0.0)
                             smallest=arr[i];
                     }
                 }
                
                 return(smallest);
             }
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
              int arrCurveScores[] = {45,85,90};
              System.out.println("Testing curveScores() method.");
              System.out.println("curveScores([45, 85, 90])");
              int[] arr2CurveScores;
              arr2CurveScores = curveScores(arrCurveScores);
              System.out.print("Got : [");
              for(int i=0;i                    System.out.print(arr2CurveScores[i] + ",");
              System.out.println("]");
             
                   double arrSmallestDouble[] = {2.0,-4.0,5.0};
                   System.out.println("Testing findSmallestPositiveNumber() method.");
                   System.out.println("findSmallestPositiveNumber([2.0,-4.0,5.0])");
                   double smallestDouble = findSmallestPositiveNumber(arrSmallestDouble);
                   System.out.print("Got : "+ smallestDouble);
                  
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
----------------------------------- SOURCE END -------------------------------------
!STACK 0
java.lang.IllegalArgumentException
    at org.eclipse.jdt.core.dom.InfixExpression.setOperator(InfixExpression.java:383)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:880)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2011)
    at org.eclipse.jdt.core.dom.ASTConverter.convertToParenthesizedExpression(ASTConverter.java:3750)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1932)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1204)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1963)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3023)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2203)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2193)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2965)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:751)
    at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3302)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1513)
    at org.eclipse.jdt.core.dom.AST.convertCompilationUnit(AST.java:449)
    at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:200)
    at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:268)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:596)
    at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:1141)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:173)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:94)
    at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:736)
    at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:802)
    at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1318)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrateg
y.reconcile(JavaReconcilingStrategy.java:131)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.access$0(JavaReconcilingStrategy.java:113)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:93)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:90)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:157)
    at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:94)
    at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:107)
    at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:76)
    at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:210)
!ENTRY org.eclipse.jdt.ui 4 2 2020-10-01 13:30:58.342
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ui".
!STACK 0
java.lang.IllegalArgumentException
    at org.eclipse.jdt.core.dom.InfixExpression.setOperator(InfixExpression.java:383)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:880)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2011)
    at org.eclipse.jdt.core.dom.ASTConverter.convertToParenthesizedExpression(ASTConverter.java:3750)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1932)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1204)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1963)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3023)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2203)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2193)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2965)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:751)
    at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3302)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1513)
    at org.eclipse.jdt.core.dom.AST.convertCompilationUnit(AST.java:449)
    at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:200)
    at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:268)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:596)
    at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:1141)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:173)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:94)
    at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:736)
    at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:802)
    at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1318)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:131)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.access$0(JavaReconcilingStrategy.java:113)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:93)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:90)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:157)
    at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:94)
    at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:107)
    at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:76)
    at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:210)
!ENTRY org.eclipse.jdt.ui 4 0 2020-10-01 13:30:58.351
!MESSAGE Error in JDT Core during reconcile
!STACK 0
java.lang.IllegalArgumentException
    at org.eclipse.jdt.core.dom.InfixExpression.setOperator(InfixExpression.java:383)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:880)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2011)
    at org.eclipse.jdt.core.dom.ASTConverter.convertToParenthesizedExpression(ASTConverter.java:3750)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1932)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1204)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1963)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3023)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2203)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2193)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2965)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:751)
    at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3302)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1513)
    at org.eclipse.jdt.core.dom.AST.convertCompilationUnit(AST.java:449)
    at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:200)
    at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:268)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:596)
    at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:1141)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:173)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:94)
    at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:736)
    at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:802)
    at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1318)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:131)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.access$0(JavaReconcilingStrategy.java:113)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:93)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:90)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:157)
    at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:94)
    at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:107)
    at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:76)
    at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:210)
!ENTRY org.eclipse.jdt.core 4 4 2020-10-01 13:30:58.365
!MESSAGE Exception occurred during compilation unit conversion:
----------------------------------- SOURCE BEGIN -------------------------------------
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
            
             /*Method: curveScores(): method to find lowest alphabetical word
             * @param: arr-An int array containing numbers that can range from 0 to 100.
             * @return: 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.
             */
             public static int[] curveScores(int arr[])
             {
                 int maxIndx=0;
                 int offset=10;
                
                 // finding the index of the array where the max value lies
                 for(int i=1;i                 {
                     if(arr[i]>arr[maxIndx])
                         maxIndx=i;
                 }
                
                 // setting the maximum value to 100 now
                 arr[maxIndx]=100;
                
                 // traversing through the array to move up all the other values by offset amount
                 for(int i=0;i                 {
                     if(i != maxIndx)
                         arr[i] = arr[i] + offset;
                 }
                
                 return(arr);
                
             }
    
             /*Method: findSmallestPositiveNumber(): method to find smallest number greater than 0.0 in the array
             * @param: arr-A double array with atleast one positive number
             * @return: A double value that is the smallest number greater than 0.0 in the array.
             */
             public static double findSmallestPositiveNumber(double arr[])
             {
                 int countOfPositives=0;
                
                 // checking number of positives numbers in the array
                 for(int i=0; i                     {
                         if(arr[i]>0.0)
                             countOfPositives++;
                     }
                 if(countOfPositives<1)
                 {
                     System.out.println("There MUST BE ATLEAST 1 POSITIVE NUMBER in the array.");
                     return(0);
                 }
                
                 // traversing the array to find smallest number greater than 0.0 in the array
                 double smallest;
                 int foundFirst=0;
                 for(int i=0; i                 {
                     if(arr[i]>=0.0)
                     {
                         if(arr[i]>0.0 && foundFirst==0)
                             {
                             smallest = arr[i];
                             foundFirst = 1;
                             }
                         else(arr[i]0.0)
                             smallest=arr[i];
                     }
                 }
                
                 return(smallest);
             }
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
              int arrCurveScores[] = {45,85,90};
              System.out.println("Testing curveScores() method.");
              System.out.println("curveScores([45, 85, 90])");
              int[] arr2CurveScores;
              arr2CurveScores = curveScores(arrCurveScores);
              System.out.print("Got : [");
              for(int i=0;i                    System.out.print(arr2CurveScores[i] + ",");
              System.out.println("]");
             
                   double arrSmallestDouble[] = {2.0,-4.0,5.0};
                   System.out.println("Testing findSmallestPositiveNumber() method.");
                   System.out.println("findSmallestPositiveNumber([2.0,-4.0,5.0])");
                   double smallestDouble = findSmallestPositiveNumber(arrSmallestDouble);
                   System.out.print("Got : "+ smallestDouble);
                  
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
----------------------------------- SOURCE END -------------------------------------
!STACK 0
java.lang.IllegalArgumentException
    at org.eclipse.jdt.core.dom.InfixExpression.setOperator(InfixExpression.java:383)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:880)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2011)
    at org.eclipse.jdt.core.dom.ASTConverter.convertToParenthesizedExpression(ASTConverter.java:3750)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1932)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1204)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1963)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3023)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2203)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2193)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2965)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:751)
    at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3302)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1513)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:323)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1231)
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:820)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:272)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.createAST(CoreASTProvider.java:264)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:197)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:187)
    at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.run(SelectionListenerWithASTManager.java:152)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
!ENTRY org.eclipse.jdt.core.manipulation 4 2 2020-10-01 13:30:58.372
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.core.manipulation".
!STACK 0
java.lang.IllegalArgumentException
    at org.eclipse.jdt.core.dom.InfixExpression.setOperator(InfixExpression.java:383)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:880)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2011)
    at org.eclipse.jdt.core.dom.ASTConverter.convertToParenthesizedExpression(ASTConverter.java:3750)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1932)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1204)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1963)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3023)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2203)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2193)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2965)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:751)
    at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3302)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1513)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:323)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1231)
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:820)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:272)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.createAST(CoreASTProvider.java:264)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:197)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:187)
    at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.run(SelectionListenerWithASTManager.java:152)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
!ENTRY org.eclipse.jdt.core.manipulation 4 0 2020-10-01 13:30:58.378
!MESSAGE Error in JDT Core during AST creation
!STACK 0
java.lang.IllegalArgumentException
    at org.eclipse.jdt.core.dom.InfixExpression.setOperator(InfixExpression.java:383)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:880)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2011)
    at org.eclipse.jdt.core.dom.ASTConverter.convertToParenthesizedExpression(ASTConverter.java:3750)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1932)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1204)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1963)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3023)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2203)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2968)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1372)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2193)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2965)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:751)
    at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3302)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1513)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:323)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1231)
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:820)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:272)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.createAST(CoreASTProvider.java:264)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:197)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:187)
    at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.run(SelectionListenerWithASTManager.java:152)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/11/a026938bb603001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              System.out.println("Got : " + lowestString);
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         /*System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor); */
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/1a/30e3503cb503001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String[] strArray)
             {
                 int count = strArray.length();
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String lowestString=lowestAlphabetically(["cat", "dog", "apple", "fish"]);
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              Sytem.out.println("Got : " + lowestString);
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         /*System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor); */
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/1b/c0c2e481bc03001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
            
             /*Method: curveScores(): method to find lowest alphabetical word
             * @param: arr-An int array containing numbers that can range from 0 to 100.
             * @return: 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.
             */
             public static int[] curveScores(int arr[])
             {
                 int maxIndx=0;
                 int offset=10;
                
                 // finding the index of the array where the max value lies
                 for(int i=1;i                 {
                     if(arr[i]>arr[maxIndx])
                         maxIndx=i;
                 }
                
                 // setting the maximum value to 100 now
                 arr[maxIndx]=100;
                
                 // traversing through the array to move up all the other values by offset amount
                 for(int i=0;i                 {
                     if(i != maxIndx)
                         arr[i] = arr[i] + offset;
                 }
                
                 return(arr);
                
             }
    
             /*Method: findSmallestPositiveNumber(): method to find smallest number greater than 0.0 in the array
             * @param: arr-A double array with atleast one positive number
             * @return: A double value that is the smallest number greater than 0.0 in the array.
             */
             public static double findSmallestPositiveNumber(double arr[])
             {
                 int countOfPositives=0;
                
                 // checking number of positives numbers in the array
                 for(int i=0; i                     {
                         if(arr[i]>0.0)
                             countOfPositives++;
                     }
                 if(countOfPositives<1)
                 {
                     System.out.println("There MUST BE ATLEAST 1 POSITIVE NUMBER in the array.");
                     return(0);
                 }
                
                 // traversing the array to find smallest number greater than 0.0 in the array
                 double smallest;
                 int foundFirst=0;
                 for(int i=0; i                 {
                     if(arr[i]>=0.0)
                     {
                         if(arr[i]>0.0 && foundFirst==0)
                             {
                             smallest = arr[i];
                             foundFirst = 1;
                             }
                         else if (arr[i]0.0)
                             smallest=arr[i];
                     }
                 }
                
                 return(smallest);
             }
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
              int arrCurveScores[] = {45,85,90};
              System.out.println("Testing curveScores() method.");
              System.out.println("curveScores([45, 85, 90])");
              int[] arr2CurveScores;
              arr2CurveScores = curveScores(arrCurveScores);
              System.out.print("Got : [");
              for(int i=0;i                    System.out.print(arr2CurveScores[i] + ",");
              System.out.println("]");
             
                   double arrSmallestDouble[] = {2.0,-4.0,5.0};
                   System.out.println("Testing findSmallestPositiveNumber() method.");
                   System.out.println("findSmallestPositiveNumber([2.0,-4.0,5.0])");
                   double smallestDouble = findSmallestPositiveNumber(arrSmallestDouble);
                   System.out.print("Got : "+ smallestDouble);
                  
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/22/50a9697cb703001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int first_len = first.length;
                 int second_len = second.length;
                 int smallest, second_min, first_min;
                
                 if (first_len < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                 }
                
                 if (first_min <= second_min)
                     smallest = first_min;
                 else
                     smallest = second_min;
                
                 return(smallest);
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              System.out.println("Got : " + lowestString);
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         /*System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor); */
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/22/e098399eb903001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
            
             /*Method: curveScores(): method to find lowest alphabetical word
             * @param: arr-An int array containing numbers that can range from 0 to 100.
             * @return: 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.
             */
             public static int[] curveScores(int arr[])
             {
                 int maxIndx=0;
                 int offset=10;
                
                 // finding the index of the array where the max value lies
                 for(int i=1;i                 {
                     if(arr[i]>arr[maxIndx])
                         maxIndx=i;
                 }
                
                 // setting the maximum value to 100 now
                 arr[maxIndx]=100;
                
                 // traversing through the array to move up all the other values by offset amount
                 for(i=0;i                 {
                     if(i!=maxIndx)
                         arr[i] = arr[i] + offset;
                 }
                
                 return(arr);
                
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/23/10dc64bab803001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/26/50d5ef84bb03001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
            
             /*Method: curveScores(): method to find lowest alphabetical word
             * @param: arr-An int array containing numbers that can range from 0 to 100.
             * @return: 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.
             */
             public static int[] curveScores(int arr[])
             {
                 int maxIndx=0;
                 int offset=10;
                
                 // finding the index of the array where the max value lies
                 for(int i=1;i                 {
                     if(arr[i]>arr[maxIndx])
                         maxIndx=i;
                 }
                
                 // setting the maximum value to 100 now
                 arr[maxIndx]=100;
                
                 // traversing through the array to move up all the other values by offset amount
                 for(int i=0;i                 {
                     if(i != maxIndx)
                         arr[i] = arr[i] + offset;
                 }
                
                 return(arr);
                
             }
    
             /*Method: findSmallestPositiveNumber(): method to find smallest number greater than 0.0 in the array
             * @param: arr-A double array with atleast one positive number
             * @return: A double value that is the smallest number greater than 0.0 in the array.
             */
             public static double findSmallestPositiveNumber(double arr[])
             {
                 int countOfPositives=0;
                
                 // checking number of positives numbers in the array
                 for(int i=0; i                     {
                         if(arr[i]>0.0)
                             countOfPositives++;
                     }
                 if(countOfPositives<1)
                 {
                     System.out.println("There MUST BE ATLEAST 1 POSITIVE NUMBER in the array.");
                     return(0);
                 }
                
                 // traversing the array to find smallest number greater than 0.0 in the array
                 int smallest=0.0;
                 for(int i=0; i                 {
                     if(arr[i]>=0.0)
                     {
                         if(arr[i]                             smallest=arr[i];
                     }
                 }
                
                 return(smallest);
             }
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
              int arrCurveScores[] = {45,85,90};
              System.out.println("Testing curveScores() method.");
              System.out.println("curveScores([45, 85, 90])");
              int[] arr2CurveScores;
              arr2CurveScores = curveScores(arrCurveScores);
              System.out.print("Got : [");
              for(int i=0;i                    System.out.print(arr2CurveScores[i] + ",");
              System.out.println("]");
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/2a/809b48edb303001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 String tmpList[] = s.split("");
                
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         /*System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor); */
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/2b/d0e08ccabb03001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
            
             /*Method: curveScores(): method to find lowest alphabetical word
             * @param: arr-An int array containing numbers that can range from 0 to 100.
             * @return: 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.
             */
             public static int[] curveScores(int arr[])
             {
                 int maxIndx=0;
                 int offset=10;
                
                 // finding the index of the array where the max value lies
                 for(int i=1;i                 {
                     if(arr[i]>arr[maxIndx])
                         maxIndx=i;
                 }
                
                 // setting the maximum value to 100 now
                 arr[maxIndx]=100;
                
                 // traversing through the array to move up all the other values by offset amount
                 for(int i=0;i                 {
                     if(i != maxIndx)
                         arr[i] = arr[i] + offset;
                 }
                
                 return(arr);
                
             }
    
             /*Method: findSmallestPositiveNumber(): method to find smallest number greater than 0.0 in the array
             * @param: arr-A double array with atleast one positive number
             * @return: A double value that is the smallest number greater than 0.0 in the array.
             */
             public static double findSmallestPositiveNumber(double arr[])
             {
                 int countOfPositives=0;
                
                 // checking number of positives numbers in the array
                 for(int i=0; i                     {
                         if(arr[i]>0.0)
                             countOfPositives++;
                     }
                 if(countOfPositives<1)
                 {
                     System.out.println("There MUST BE ATLEAST 1 POSITIVE NUMBER in the array.");
                     return(0);
                 }
                
                 // traversing the array to find smallest number greater than 0.0 in the array
                 double smallest=0.0;
                 for(int i=0; i                 {
                     if(arr[i]>=0.0)
                     {
                         if(arr[i]                             smallest=arr[i];
                     }
                 }
                
                 return(smallest);
             }
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
              int arrCurveScores[] = {45,85,90};
              System.out.println("Testing curveScores() method.");
              System.out.println("curveScores([45, 85, 90])");
              int[] arr2CurveScores;
              arr2CurveScores = curveScores(arrCurveScores);
              System.out.print("Got : [");
              for(int i=0;i                    System.out.print(arr2CurveScores[i] + ",");
              System.out.println("]");
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c050d6e9b603001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int first_len = first.length;
                 int second_len = second.length;
                 int temp;
                
                 if (first_len < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 int first_min = first[0];
                 for(int i=1;i                 {
                    
                
                     }
                
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              System.out.println("Got : " + lowestString);
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         /*System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor); */
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/3/8003fa72ba03001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
            
             /*Method: curveScores(): method to find lowest alphabetical word
             * @param: arr-An int array containing numbers that can range from 0 to 100.
             * @return: 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.
             */
             public static int[] curveScores(int arr[])
             {
                 int maxIndx=0;
                 int offset=10;
                
                 // finding the index of the array where the max value lies
                 for(int i=1;i                 {
                     if(arr[i]>arr[maxIndx])
                         maxIndx=i;
                 }
                
                 // setting the maximum value to 100 now
                 arr[maxIndx]=100;
                
                 // traversing through the array to move up all the other values by offset amount
                 for(int i=0;i                 {
                     if(i != maxIndx)
                         arr[i] = arr[i] + offset;
                 }
                
                 return(arr);
                
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
              int arrCurveScores[] = {45,85,90};
              System.out.println("Testing curveScores() method.");
              System.out.println("curveScores([45, 85, 90])");
              int[] arr2CurveScores;
              arr2CurveScores = curveScores(arrCurveScores);
              System.out.println("Got : [");
              for(int i=0;i                    System.out.print(arr2CurveScores[i] + ",");
              System.out.print("]");
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/3/e0066173b303001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         /*System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor); */
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/31/30869faab403001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 String tmpList[] = s.split("");
                
                 String
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         /*System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor); */
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/38/201a1ae7ba03001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.util.Objects;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static String lowestAlphabetically(String strArray[])
             {
                 int count = strArray.length;
                 String temp;
                
                 for (int i = 0; i < count; i++)
             {
             for (int j = i + 1; j < count; j++)
             {
             if (strArray[i].compareTo(strArray[j]) > 0)
             {
             temp = strArray[i];
             strArray[i] = strArray[j];
             strArray[j] = temp;
             }
             }
             }
                
                 return(strArray[0]);
             }
            
             /*Method: findSmallestNumberInTwoArrays(): method to find smallest number in two arrays
             * @param: arr1-first array of numbers
             *          arr2-second array of numbers
             * @return: An int containing the smallest number found in the two arrays
             */
             public static int findSmallestNumberInTwoArrays(int first[], int second[])
             {
                 int smallest, second_min, first_min;
                
                 if (first.length < 1)
                     {
                         System.out.println("Length of first array MUST BE ATLEAST 1.");
                         return(0);
                     }
                
                 // traversing the first array to find the smallest number
                 first_min = first[0];
                 for(int i=1;i                 {
                     if(first[i]                         first_min=first[i];
                 }
                 smallest = first_min;
                
                 if(second.length>0) // because length of second array can be 0 also
                 {
                     second_min = second[0];
                     for(int i=1;i                     {
                         if(second[i]                             second_min=second[i];
                     }
                    
                     if (first_min <= second_min)
                         smallest = first_min;
                     else
                         smallest = second_min;
                 }
                
                 return(smallest);
             }
            
             /*Method: curveScores(): method to find lowest alphabetical word
             * @param: arr-An int array containing numbers that can range from 0 to 100.
             * @return: 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.
             */
             public static int[] curveScores(int arr[])
             {
                 int maxIndx=0;
                 int offset=10;
                
                 // finding the index of the array where the max value lies
                 for(int i=1;i                 {
                     if(arr[i]>arr[maxIndx])
                         maxIndx=i;
                 }
                
                 // setting the maximum value to 100 now
                 arr[maxIndx]=100;
                
                 // traversing through the array to move up all the other values by offset amount
                 for(int i=0;i                 {
                     if(i != maxIndx)
                         arr[i] = arr[i] + offset;
                 }
                
                 return(arr);
                
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
              String[] testArray = new String[] {"cat", "dog", "apple", "fish"};
              System.out.println("Testing lowestAlphabetically() method.");
              System.out.println("lowestAlphabetically([\"cat\", \"dog\", \"apple\", \"fish\"])");
              String lowestString=lowestAlphabetically(testArray);
              System.out.println("Got : " + lowestString);
             
              int arr1[] = {12,3,5};
              int arr2[]= {2,-1,10};
              System.out.println("Testing findSmallestNumberInTwoArrays() method.");
              System.out.println("findSmallestNumberInTwoArrays([12, 3, 5], [2, -1, 10])");
              int smallestNum=findSmallestNumberInTwoArrays(arr1, arr2);
              System.out.println("Got : " + smallestNum);
             
              int arrCurveScores[] = {45,85,90};
              System.out.println("Testing curveScores() method.");
              System.out.println("curveScores([45, 85, 90])");
              int[] arr2CurveScores;
              arr2CurveScores = curveScores(arrCurveScores);
              System.out.print("Got : [");
              for(int i=0;i                    System.out.print(arr2CurveScores[i] + ",");
              System.out.println("]");
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit has a carrot)");
System.out.println("Expected: A r*bbit h*s * c*rrot");
System.out.println("Got : " + hideLetterA(str));
str = "1 2 3 4 5 6 8";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5 6 8)");
System.out.println("Expected: true");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "1 2 3 4 5";
System.out.println("Testing hasMoreEvenThanOdd(1 2 3 4 5)");
System.out.println("Expected: false");
System.out.println("Got : " + hasMoreEvenThanOdd(str));
str = "* ** *** **** ";
System.out.println("Testing makeTextTriangle(4)");
System.out.println("Expected:");
System.out.println(str);
System.out.println("Got:");
System.out.println(makeTextTriangle(4)); */

/**
* trying to open Arches.jpg file. Make sure you pasted Arches.jpg file
* in the root directory of your project, make sure everything match, if
* the file name is valid or if you pasted it in wrong folder, the image
* will not be opened, an exception will be thrown otherwise.
*/
String fileName = "src\\a4\\Arches.jpg";
System.out.println("Now the program will try to open " + fileName);
Picture original = new Picture(new File(fileName));

System.out.println("Image opened, now displaying original image,"
+ " image converted to grayscale, negative image"
+ " and brightened image in order.");
original.show();
makeGrey(original).show();// converting to gray and displaying
makeNegative(original).show();// converting to negative and displaying
makeBrighter(original).show();// brightening and displaying
                        
                         System.out.println("Now Checking if the image contains a particular color");
                         Color colorObj = new Color(250,250,250);
                         Boolean containsColor = containsThisColor(original,colorObj);
                         System.out.println("Did the picture contains the color ? " + containsColor);
}
}
Picture/.metadata/.plugins/org.eclipse.core.resources/.history/3d/70be30e8b303001b1ef28fd7b2c60187
package a4;
import java.awt.Color;
import java.io.File;
import java.util.Scanner;
public class LoopPatterns
{
             /*Method: lowestAlphabetically(): method to find lowest alphabetical word
             * @param: strArr-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: A String containing the lowest alphabetical word.
             */
             public static string lowestAlphabetically(string strArray[])
             {
                
             }
    
             /*Method: containsThisColor(): method to find out if Color parameter matches one of the pixels in the image
             * @param: obj- picture object
             * checkColor - Color object
             * @return: Boolean
             */
             public static boolean containsThisColor(Picture obj, Color checkColor)
             {
                for (int row = 0; row < obj.height(); row++)
                {
                    for (int col = 0; col < obj.width(); col++)
                    {
                        Color c = obj.get(col, row);
                        int Blue = (c.getBlue());
                        int Red = (c.getRed());
                        int Green = (c.getGreen());
                        
                        Color thisPixel = new Color(Blue, Red, Green);
                        if (Objects.equals(thisPixel, checkColor))
                            return true;
                    }
                }
                return false;
             }
            
/*Method: makeGrey(): method to convert a picture to grayscale and return it
* @param obj-picture object
* @return a new picture with colors converted to grayscale
*/
public static Picture makeGrey(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                        {
                            Color color = obj.get(column, row);
// finding average of r,g,b values
int avgRGB = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// creating a new color with same r g b values
Color gray = new Color(avgRGB, avgRGB, avgRGB);
// setting color to current position in newPic
newPic.set(column, row, gray);
}
return newPic;
}
            
/*Method: makeNegative(): method to find and return negative of a picture
* @param obj-picture object
* @return a new picture with colors negated
*/
public static Picture makeNegative(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color colorOfPic = obj.get(column, row);
// creating a new color with r g b values subtracted from 255
Color negativePic = new Color(255 - colorOfPic.getRed(),255 - colorOfPic.getGreen(), 255 - colorOfPic.getBlue());
// setting color to current position in newPic
newPic.set(column, row, negativePic);
}
return newPic;
}
            
/*Method: safeColor(): method to wrap the given value within 0-255 range and return it
* @param value, a numeric value
* @return value if 0<=value<=255, 0 if value<0, 255 if value>255
*/
public static int safeColor(int value)
             {
                    if (value < 0)
                        return 0; // if value is less than 0, returning 0
                    else if (value > 255)
                        return 255; // if value is greater than 255, returning 255
                    else
                        return value; // unchanged
}

             /*Method: makeBrighter(): method to make a picture brighter and return it
* @param obj- input picture
* @return a new picture where all colors are made brighter by doubling rgb values safely
*/
public static Picture makeBrighter(Picture obj)
             {
                Picture newPic = new Picture(obj);
int width = obj.width();
int height = obj.height();
                
for (int column = 0; column < width; column++)
                    for (int row = 0; row < height; row++)
                    {
                        Color color = obj.get(column, row);

                        // Doubling the r g b values
Color brighter = new Color(safeColor(color.getRed() * 2),safeColor(color.getGreen() * 2),safeColor(color.getBlue() * 2));
// setting the newPic object
newPic.set(column, row, brighter);
}

                return newPic;
}
            
             /*Method: main(): Definition of main function
             **/
public static void main(String[] args)
{
// testing of the methods
/*String str = "A rabbit has a carrot";
System.out.println("Testing hideLetterA(A rabbit...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here