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