From 532ed6ebe9d6bd96fe60ef6aa840430db5edecaa Mon Sep 17 00:00:00 2001 From: Connie-bread Date: Sun, 19 Oct 2025 20:11:20 +0000 Subject: [PATCH 1/3] Version 1 --- .../java/challenges/FundamentalsPractice.java | 163 +++++++++++++----- src/main/java/challenges/PasswordChecker.java | 53 +++++- 2 files changed, 173 insertions(+), 43 deletions(-) diff --git a/src/main/java/challenges/FundamentalsPractice.java b/src/main/java/challenges/FundamentalsPractice.java index 64e2aca..bd9126c 100644 --- a/src/main/java/challenges/FundamentalsPractice.java +++ b/src/main/java/challenges/FundamentalsPractice.java @@ -25,7 +25,22 @@ public static int sum(int a, int b) { // The values in parentheses are set for y * Ex: Given [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15], you would RETURN: [3, 2, 1] */ public static int[] fizzbuzz(int[] arr) { - return null; + int [] array = {0, 0, 0}; + for (int num : arr) { + if (num % 3 == 0 && num % 5 == 0) { + System.out.println("FizzBuzz"); + array[2] += 1; + } else if (num % 3 == 0) { + System.out.println("Fizz"); + array[0] += 1; + } else if (num % 5 == 0) { + System.out.println("Buzz"); + array[1] += 1; + } else { + System.out.println(num); + } + } + return array; } /** @@ -40,7 +55,14 @@ public static int[] fizzbuzz(int[] arr) { */ public static String reverseString(String input) { // Your code goes here - return null; + char[] charArray = input.toCharArray(); + for (int i = 0; i < Math.round(charArray.length / 2); i++) { + char temp = charArray[i]; + charArray[i] = charArray[charArray.length - i - 1]; + charArray[charArray.length - i - 1] = temp; + } + String str = new String(charArray); + return str; } /** @@ -49,14 +71,32 @@ public static String reverseString(String input) { */ public static int maxInArray(int[] arr) { // Your code goes here - return 0; + for (int i = 0; i < arr.length - 1; i++) { + for (int j = 0; j < arr.length - 1 - i; j++) { + if (arr[j] > arr[j+1]) { + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + + } + } + } + return arr[arr.length-1]; } public static boolean stringsAreSame(String a, String b) { + // use just .equals() if caps matter, otherwise, use the method below + if (a.equalsIgnoreCase(b)) { + System.out.println("strings are equal"); + return true; + } else { + System.out.println("strings are not equal"); + return false; + } + // If strings are equal, return true. Else, return false // Hint: use .equals() to compare strings not == // Do not care about capitals HI is equal to hi look up how to do. - return false; } /** @@ -66,8 +106,16 @@ public static boolean stringsAreSame(String a, String b) { * - strings can be accessed like this: variable.charAt(0) returns the first character */ public static int countVowels(String input) { + char[] charVowels = input.toCharArray(); // Your code goes here - return 0; + int vowels = 0; + for (int i = 0; i < charVowels.length; i++) { + if (input.charAt(i) == 'a' || input.charAt(i) == 'e' || input.charAt(i) == 'i' || input.charAt(i) == 'o' || input.charAt(i) == 'u') { + vowels++; + } + } + return vowels; + } /** @@ -77,7 +125,13 @@ public static int countVowels(String input) { */ public static boolean isPrime(int n) { // Your code goes here - return false; + boolean prime = true; + for (double i = 2; i <= Math.sqrt(n); i++) { + if (n % i == 0) { + prime = false; + } + } + return prime; } /** @@ -89,45 +143,70 @@ public static boolean isPrime(int n) { */ public static long factorial(int n) { // Your code goes here - return 0L; - } - + int value = 1; + for (int i = 2; i <= n; i++) { + value = (value) * (i); + } + return value; +} // Use for Manual Testing public static void main(String[] args) { - System.out.println("================ RUNNING CODE ================"); - // sum - int a = 3; - int b = 5; - System.out.println("sum(" + a + ", " + b + ") = " + sum(a, b)); // Expected: 8 - - // fizzbuzz - int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 35, 36}; - System.out.println("fizzbuzz(arr) = " + Arrays.toString(fizzbuzz(arr))); // Expected: [5, 4, 3] - - // reverseString - String str = "hello"; - System.out.println("reverseString('" + str + "') = '" + reverseString(str) + "'"); // Expected: 'olleh' - - // maxInArray - int[] nums = {1, 5, 3, 9, 2}; - System.out.println("maxInArray([1,5,3,9,2]) = " + maxInArray(nums)); // Expected: 9 - - // countVowels - String word = "banana"; - System.out.println("countVowels('banana') = " + countVowels(word)); // Expected: 3 - - // isPrime - int primeTest = 7; - int notPrimeTest = 8; - System.out.println("isPrime(7) = " + isPrime(primeTest)); // Expected: true - System.out.println("isPrime(8) = " + isPrime(notPrimeTest)); // Expected: false - - // factorial - int factTest = 5; - System.out.println("factorial(5) = " + factorial(factTest)); // Expected: 120 - - System.out.println("=============== DONE RUNNING ==============="); + // System.out.println("================ RUNNING CODE ================"); + // // sum + // int a = 3; + // int b = 5; + // System.out.println("sum(" + a + ", " + b + ") = " + sum(a, b)); // Expected: 8 + + // // fizzbuzz + // int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 35, 36}; + // System.out.println("fizzbuzz(arr) = " + Arrays.toString(fizzbuzz(arr))); // Expected: [5, 4, 3] + + // // reverseString + // String str = "hello"; + // System.out.println("reverseString('" + str + "') = '" + reverseString(str) + "'"); // Expected: 'olleh' + + // // maxInArray + // int[] nums = {1, 5, 3, 9, 2}; + // System.out.println("maxInArray([1,5,3,9,2]) = " + maxInArray(nums)); // Expected: 9 + + // // countVowels + // String word = "banana"; + // System.out.println("countVowels('banana') = " + countVowels(word)); // Expected: 3 + + // // isPrime + // int primeTest = 7; + // int notPrimeTest = 8; + // System.out.println("isPrime(7) = " + isPrime(primeTest)); // Expected: true + // System.out.println("isPrime(8) = " + isPrime(notPrimeTest)); // Expected: false + + // // factorial + // int factTest = 5; + // System.out.println("factorial(5) = " + factorial(factTest)); // Expected: 120 + + // System.out.println("=============== DONE RUNNING ==============="); + + // for static methods (the fundprac.sum print code below) different than calling classes + + System.out.println(FundamentalsPractice.sum(3,7)); + + + + int[] someArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15}; + int[] result = FundamentalsPractice.fizzbuzz(someArray); + System.out.println(Arrays.toString(result)); + + + System.out.println(FundamentalsPractice.reverseString("bestfriend")); + + + int[] maxArray = {1, 3, 1082, 86, 23}; + System.out.println(FundamentalsPractice.maxInArray(maxArray)); + + System.out.println(FundamentalsPractice.stringsAreSame("hi", "hI")); + System.out.println(FundamentalsPractice.countVowels("eee")); + System.out.println(FundamentalsPractice.isPrime(9)); + System.out.println(FundamentalsPractice.factorial(5)); } } diff --git a/src/main/java/challenges/PasswordChecker.java b/src/main/java/challenges/PasswordChecker.java index c42aafb..99da0d5 100644 --- a/src/main/java/challenges/PasswordChecker.java +++ b/src/main/java/challenges/PasswordChecker.java @@ -26,15 +26,20 @@ public class PasswordChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); + System.out.print("What do you want your password to be?: "); + String password = scanner.nextLine(); // TODO: Prompt the user to enter a password and read it from input // String password = scanner.nextLine(); + // Call the method to check password strength // String strength = checkPasswordStrength(password); + String strength = checkPasswordStrength(password); // TODO: Output the strength rating // System.out.println(strength); + System.out.println(strength); scanner.close(); } @@ -42,6 +47,7 @@ public static void main(String[] args) { /** * Checks the strength of the given password. * Returns "Weak", "Moderate", or "Strong". + * the things (@param and @return) below are tags for documentation * * @param password The password to check * @return The strength rating @@ -51,7 +57,52 @@ public static String checkPasswordStrength(String password) { // - Check length // - Check for uppercase, lowercase, digit, and symbol // - Return the appropriate rating + char[] charString = password.toCharArray(); + int strengthRate = 0; + boolean cd1 = false; + boolean cd2 = false; + boolean cd3 = false; + boolean cd4 = false; + boolean cdLength = false; - return ""; // Placeholder + for (int i = 0; i < charString.length; i++) { + if (Character.isUpperCase(charString[i]) == true) { + cd1 = true; + } else if (Character.isLowerCase(charString[i])) { + cd2 = true; + } else if (Character.isDigit(charString[i])) { + cd3 = true; + } else if (Character.isLetterOrDigit(charString[i]) == false) { + cd4 = true; + } + } + + if (charString.length >= 8) { + cdLength = true; + } + + if (cd1 == true) { + strengthRate++; + } + if (cd2 == true) { + strengthRate++; + } + if (cd3 == true) { + strengthRate++; + } + if (cd4 == true) { + strengthRate++; + } + // System.out.println(strengthRate); + + if (strengthRate == 4 && cdLength == true) { + return "Your password is strong."; + } else if (strengthRate == 3 && cdLength == true) { + return "Your password is mid."; + } else { + return "Your password is trash."; + } } + + } \ No newline at end of file From 59b5b97a7abad9bc35cb50dcc1d32049ae8bbdcc Mon Sep 17 00:00:00 2001 From: Connie-bread Date: Sun, 19 Oct 2025 20:22:20 +0000 Subject: [PATCH 2/3] MORE COMMIT MESSAGES --- .../java/challenges/FundamentalsPractice.java | 26 +++++++++++-------- src/main/java/challenges/PasswordChecker.java | 6 ++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/challenges/FundamentalsPractice.java b/src/main/java/challenges/FundamentalsPractice.java index bd9126c..11391eb 100644 --- a/src/main/java/challenges/FundamentalsPractice.java +++ b/src/main/java/challenges/FundamentalsPractice.java @@ -131,6 +131,9 @@ public static boolean isPrime(int n) { prime = false; } } + if (n <= 1 ) { + prime = false; + } return prime; } @@ -189,24 +192,25 @@ public static void main(String[] args) { // for static methods (the fundprac.sum print code below) different than calling classes - System.out.println(FundamentalsPractice.sum(3,7)); + + // System.out.println(FundamentalsPractice.sum(3,7)); - int[] someArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15}; - int[] result = FundamentalsPractice.fizzbuzz(someArray); - System.out.println(Arrays.toString(result)); + // int[] someArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15}; + // int[] result = FundamentalsPractice.fizzbuzz(someArray); + // System.out.println(Arrays.toString(result)); - System.out.println(FundamentalsPractice.reverseString("bestfriend")); + // System.out.println(FundamentalsPractice.reverseString("bestfriend")); - int[] maxArray = {1, 3, 1082, 86, 23}; - System.out.println(FundamentalsPractice.maxInArray(maxArray)); + // int[] maxArray = {1, 3, 1082, 86, 23}; + // System.out.println(FundamentalsPractice.maxInArray(maxArray)); - System.out.println(FundamentalsPractice.stringsAreSame("hi", "hI")); - System.out.println(FundamentalsPractice.countVowels("eee")); - System.out.println(FundamentalsPractice.isPrime(9)); - System.out.println(FundamentalsPractice.factorial(5)); + // System.out.println(FundamentalsPractice.stringsAreSame("hi", "hI")); + // System.out.println(FundamentalsPractice.countVowels("eee")); + // System.out.println(FundamentalsPractice.isPrime(7)); + // System.out.println(FundamentalsPractice.factorial(5)); } } diff --git a/src/main/java/challenges/PasswordChecker.java b/src/main/java/challenges/PasswordChecker.java index 99da0d5..3952831 100644 --- a/src/main/java/challenges/PasswordChecker.java +++ b/src/main/java/challenges/PasswordChecker.java @@ -96,11 +96,11 @@ public static String checkPasswordStrength(String password) { // System.out.println(strengthRate); if (strengthRate == 4 && cdLength == true) { - return "Your password is strong."; + return "Strong"; } else if (strengthRate == 3 && cdLength == true) { - return "Your password is mid."; + return "Moderate"; } else { - return "Your password is trash."; + return "Weak"; } } From a7c3ad076a7990ede6c458b7f7e22709f7e92b33 Mon Sep 17 00:00:00 2001 From: Connie-bread Date: Mon, 20 Oct 2025 23:37:21 +0000 Subject: [PATCH 3/3] MORE CHANGES --- .../java/challenges/FundamentalsPractice.java | 8 +++-- src/main/java/challenges/PasswordChecker.java | 33 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/challenges/FundamentalsPractice.java b/src/main/java/challenges/FundamentalsPractice.java index 11391eb..f1da865 100644 --- a/src/main/java/challenges/FundamentalsPractice.java +++ b/src/main/java/challenges/FundamentalsPractice.java @@ -25,9 +25,9 @@ public static int sum(int a, int b) { // The values in parentheses are set for y * Ex: Given [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15], you would RETURN: [3, 2, 1] */ public static int[] fizzbuzz(int[] arr) { - int [] array = {0, 0, 0}; + int[] array = {0, 0, 0}; for (int num : arr) { - if (num % 3 == 0 && num % 5 == 0) { + if ((num % 3 == 0) && (num % 5 == 0)) { System.out.println("FizzBuzz"); array[2] += 1; } else if (num % 3 == 0) { @@ -126,13 +126,15 @@ public static int countVowels(String input) { public static boolean isPrime(int n) { // Your code goes here boolean prime = true; - for (double i = 2; i <= Math.sqrt(n); i++) { + for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { prime = false; + return prime; } } if (n <= 1 ) { prime = false; + return prime; } return prime; } diff --git a/src/main/java/challenges/PasswordChecker.java b/src/main/java/challenges/PasswordChecker.java index 3952831..84ef4ea 100644 --- a/src/main/java/challenges/PasswordChecker.java +++ b/src/main/java/challenges/PasswordChecker.java @@ -59,45 +59,46 @@ public static String checkPasswordStrength(String password) { // - Return the appropriate rating char[] charString = password.toCharArray(); int strengthRate = 0; - boolean cd1 = false; - boolean cd2 = false; - boolean cd3 = false; - boolean cd4 = false; - boolean cdLength = false; + // cond = condition + boolean condUpper = false; + boolean condLower = false; + boolean condDigit = false; + boolean condSymbol = false; + boolean condLength = false; for (int i = 0; i < charString.length; i++) { if (Character.isUpperCase(charString[i]) == true) { - cd1 = true; + condUpper = true; } else if (Character.isLowerCase(charString[i])) { - cd2 = true; + condLower = true; } else if (Character.isDigit(charString[i])) { - cd3 = true; + condDigit = true; } else if (Character.isLetterOrDigit(charString[i]) == false) { - cd4 = true; + condSymbol = true; } } if (charString.length >= 8) { - cdLength = true; + condLength = true; } - if (cd1 == true) { + if (condUpper == true) { strengthRate++; } - if (cd2 == true) { + if (condLower == true) { strengthRate++; } - if (cd3 == true) { + if (condDigit == true) { strengthRate++; } - if (cd4 == true) { + if (condSymbol == true) { strengthRate++; } // System.out.println(strengthRate); - if (strengthRate == 4 && cdLength == true) { + if (strengthRate == 4 && condLength == true) { return "Strong"; - } else if (strengthRate == 3 && cdLength == true) { + } else if (strengthRate == 3 && condLength == true) { return "Moderate"; } else { return "Weak";