diff --git a/FindAllPairs.java b/FindAllPairs.java new file mode 100644 index 0000000..7b9dd7d --- /dev/null +++ b/FindAllPairs.java @@ -0,0 +1,74 @@ +package com.company; + +import java.util.ArrayList; +import java.util.Arrays; + +public class FindAllPairs { + public static void findPairs(int[] testArray, int targetSum){ + ArrayList newArray = new ArrayList(); + //Array to store new sorted list without duplicates + + Arrays.sort(testArray); + //Sorts test Array + //(1,2,4,4,5,5) + + newArray.add(testArray[0]); + //Adds first element of testArray to the Arraylist + + boolean targetSumHalf = false; + //boolean if exists a pair of numbers that are the same value, but added up equal targetSum + + for (int i = 0; i < testArray.length-1; i ++){ + //If there are a pair of duplicates (Pairs where both the numbers are the same, but their sums equal targetSum), + //they are counted as a pair. + if (newArray.get(newArray.size()-1)!=testArray[i+1]){ + //Since list is expanding, checks previously added element with the testArray + newArray.add(testArray[i+1]); + //Adds testArray element if its unique to the recently added Arraylist element + } + else{ + if (testArray[i+1]*2 == targetSum && targetSumHalf == false ){ + System.out.println ("("+ newArray.get(newArray.size()-1)+","+ testArray[i+1]+")"); + targetSumHalf = true; + } + } + } + //Now uses newArray, which has list with non-duplicate numbers + //(1,2,4,5) + + //Starting at ends of the newArray + int start = 0; + int end = newArray.size()-1; + + //Keeps on looping until the two ends have met. + while (start < end){ + int sum = newArray.get(start) + newArray.get(end); + + //checking if sum of the start and end index elements are equal to target sum + if (sum == targetSum){ + //prints the pair, increments start and decrements end and continues + System.out.println ("("+ newArray.get(start)+","+ newArray.get(end)+")"); + start++; + end--; + } + else if (sum < targetSum){ + //if sum is less than targetSum, range moves up to use bigger numbers for comparison. + start++; + } + else{ + // If sum is more than targetSum, range moves down to use smaller numbers. + end--; + } + } + } + public static void main(String[] args){ + //Example values + int[] testArray = {2, 4, 5, 1, 3, 5, 4}; + int targetSum = 6; + + //Values to be printed on the console are + //(2,4) + //(1,5) + findPairs(testArray, targetSum); + } +} \ No newline at end of file diff --git a/Palindrome.java b/Palindrome.java new file mode 100644 index 0000000..1aa4772 --- /dev/null +++ b/Palindrome.java @@ -0,0 +1,26 @@ +public class Palindrome{ + public static boolean isPalindrome(String testString){ + //starts at both ends of the word. Compares each letter and gets close to the middle letters. + //loop ends in the middle of the word. + //If its odd number of characters or word is one letter, middle letter is avoided. + for (int i = 0; i < testString.length()/2; i ++){ + //If the two chars are not the same letter, return false + if (testString.charAt(i) != testString.charAt(testString.length()-i-1)){ + return false; + } + } + //All letters of the word have been compared and resemble a palindrome + return true; + } + public static void main(String[] args) { + //Words that return true (Taken from question) + System.out.println(isPalindrome("radar")); + System.out.println(isPalindrome("bob")); + System.out.println(isPalindrome("asdfdsa")); + + //Words that return false (I made these up) + System.out.println(isPalindrome("apple")); + System.out.println(isPalindrome("love")); + System.out.println(isPalindrome("asdsdfdsafdsgfherfdsa")); + } +} \ No newline at end of file diff --git a/PictureApp/.gitignore b/PictureApp/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/PictureApp/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/PictureApp/.idea/codeStyles/Project.xml b/PictureApp/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/PictureApp/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/PictureApp/.idea/codeStyles/codeStyleConfig.xml b/PictureApp/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..f2c6773 --- /dev/null +++ b/PictureApp/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/PictureApp/.idea/gradle.xml b/PictureApp/.idea/gradle.xml new file mode 100644 index 0000000..b9f8a5e --- /dev/null +++ b/PictureApp/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/PictureApp/.idea/jarRepositories.xml b/PictureApp/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/PictureApp/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/PictureApp/.idea/misc.xml b/PictureApp/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/PictureApp/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/PictureApp/.idea/runConfigurations.xml b/PictureApp/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/PictureApp/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/PictureApp/.idea/vcs.xml b/PictureApp/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/PictureApp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PictureApp/app/.gitignore b/PictureApp/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/PictureApp/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/PictureApp/app/build.gradle b/PictureApp/app/build.gradle new file mode 100644 index 0000000..ec4971e --- /dev/null +++ b/PictureApp/app/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + + defaultConfig { + applicationId "com.example.pictureapp" + minSdkVersion 28 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + +} \ No newline at end of file diff --git a/PictureApp/app/proguard-rules.pro b/PictureApp/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/PictureApp/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/PictureApp/app/src/androidTest/java/com/example/pictureapp/ExampleInstrumentedTest.java b/PictureApp/app/src/androidTest/java/com/example/pictureapp/ExampleInstrumentedTest.java new file mode 100644 index 0000000..7cd46f3 --- /dev/null +++ b/PictureApp/app/src/androidTest/java/com/example/pictureapp/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.pictureapp; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.pictureapp", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/PictureApp/app/src/main/AndroidManifest.xml b/PictureApp/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e011eb3 --- /dev/null +++ b/PictureApp/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PictureApp/app/src/main/java/com/example/pictureapp/Display.java b/PictureApp/app/src/main/java/com/example/pictureapp/Display.java new file mode 100644 index 0000000..9251dcc --- /dev/null +++ b/PictureApp/app/src/main/java/com/example/pictureapp/Display.java @@ -0,0 +1,46 @@ +package com.example.pictureapp; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; + +public class Display extends AppCompatActivity { + //private properties + private int picNum; + + //Widgets + Intent toMain; + + ImageView image; + + Button returnButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_display); + + //Intent to send user back to Main Activity + toMain = new Intent(this, MainActivity.class); + + //gets value of R.drawable and puts it into picNum + picNum = getIntent().getIntExtra("picture",0); + + //sets image based on picNum (R.drawable) number + image = findViewById(R.id.imageView); + image.setImageResource(picNum); + + returnButton = findViewById(R.id.return_button); + //if return button is clicked, its sends user back to first screen + returnButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(toMain); + } + }); + } +} \ No newline at end of file diff --git a/PictureApp/app/src/main/java/com/example/pictureapp/MainActivity.java b/PictureApp/app/src/main/java/com/example/pictureapp/MainActivity.java new file mode 100644 index 0000000..8ccabd5 --- /dev/null +++ b/PictureApp/app/src/main/java/com/example/pictureapp/MainActivity.java @@ -0,0 +1,82 @@ +package com.example.pictureapp; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.ImageButton; + +public class MainActivity extends AppCompatActivity { + //private Properties + private String[] pictures; + + //All imageButton widgets for the different pictures + ImageButton beeButton; + ImageButton minionButton; + ImageButton rabbitButton; + ImageButton flowerButton; + ImageButton sunflowerButton; + + //Intent moving on to next screen + Intent toDisplay; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + //Array containing the list of pictures from top to bottom + pictures = new String[]{"bee", "minion", "rabbit", "flower", "sunflower"}; + + beeButton = findViewById(R.id.bee_button); + minionButton = findViewById(R.id.minion_button); + rabbitButton = findViewById(R.id.rabbit_button); + flowerButton = findViewById(R.id.flower_button); + sunflowerButton = findViewById(R.id.sunflower_button); + + //Intent to move to the Display screen + toDisplay = new Intent(this, Display.class); + + //Whenever an ImageButton is clicked, it sends its R.drawable number to sendPicture method + beeButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sendPicture(R.drawable.bee); + } + }); + + minionButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sendPicture(R.drawable.minion); + } + }); + + rabbitButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sendPicture(R.drawable.rabbit); + } + }); + + flowerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sendPicture(R.drawable.flower); + } + }); + + sunflowerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + sendPicture(R.drawable.sunflower); + } + }); + } + //Receives R.drawable number of a picture and sends it to the Display screen + private void sendPicture(int picNum){ + toDisplay.putExtra("picture", picNum); + startActivity(toDisplay); + } +} \ No newline at end of file diff --git a/PictureApp/app/src/main/res/drawable-v24/bee.jpg b/PictureApp/app/src/main/res/drawable-v24/bee.jpg new file mode 100644 index 0000000..7ffa760 Binary files /dev/null and b/PictureApp/app/src/main/res/drawable-v24/bee.jpg differ diff --git a/PictureApp/app/src/main/res/drawable-v24/flower.jpeg b/PictureApp/app/src/main/res/drawable-v24/flower.jpeg new file mode 100644 index 0000000..af0660a Binary files /dev/null and b/PictureApp/app/src/main/res/drawable-v24/flower.jpeg differ diff --git a/PictureApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/PictureApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..3990a15 --- /dev/null +++ b/PictureApp/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/PictureApp/app/src/main/res/drawable-v24/minion.jpg b/PictureApp/app/src/main/res/drawable-v24/minion.jpg new file mode 100644 index 0000000..2468eae Binary files /dev/null and b/PictureApp/app/src/main/res/drawable-v24/minion.jpg differ diff --git a/PictureApp/app/src/main/res/drawable-v24/rabbit.jpg b/PictureApp/app/src/main/res/drawable-v24/rabbit.jpg new file mode 100644 index 0000000..c5a027b Binary files /dev/null and b/PictureApp/app/src/main/res/drawable-v24/rabbit.jpg differ diff --git a/PictureApp/app/src/main/res/drawable-v24/sunflower.jpg b/PictureApp/app/src/main/res/drawable-v24/sunflower.jpg new file mode 100644 index 0000000..0cc70fc Binary files /dev/null and b/PictureApp/app/src/main/res/drawable-v24/sunflower.jpg differ diff --git a/PictureApp/app/src/main/res/drawable/ic_launcher_background.xml b/PictureApp/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..61bb79e --- /dev/null +++ b/PictureApp/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PictureApp/app/src/main/res/layout/activity_display.xml b/PictureApp/app/src/main/res/layout/activity_display.xml new file mode 100644 index 0000000..cae49f3 --- /dev/null +++ b/PictureApp/app/src/main/res/layout/activity_display.xml @@ -0,0 +1,28 @@ + + + + +