From a2ce13ff3e89623c6156275f25d1639fba7659ea Mon Sep 17 00:00:00 2001 From: Aitan Martinez <161392373+Tortuga-AM@users.noreply.github.com> Date: Mon, 13 Oct 2025 01:56:41 +0000 Subject: [PATCH 1/2] Update Java development environment and enhance challenge files - Upgrade dev container to Java 21 and adjust settings - Remove outdated setup script - Update .gitignore to include target directory - Revise README for clearer instructions - Refactor FundamentalsPractice class with new methods and examples - Add PasswordStrengthChecker class for password validation - Implement unit tests for FundamentalsPractice and PasswordStrengthChecker --- .devcontainer/devcontainer.json | 23 ++-- .devcontainer/setup.sh | 5 - .gitignore | 3 + README.md | 24 ++-- pom.xml | 75 +++++----- .../java/challenges/FundamentalsPractice.java | 130 ++++++++++++++++-- src/main/java/challenges/PasswordChecker.java | 56 ++++++++ .../challenges/FundamentalsPracticeTest.java | 46 ++++++- .../java/challenges/PasswordCheckerTest.java | 47 +++++++ 9 files changed, 330 insertions(+), 79 deletions(-) delete mode 100644 .devcontainer/setup.sh create mode 100644 src/main/java/challenges/PasswordChecker.java create mode 100644 src/test/java/challenges/PasswordCheckerTest.java diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3ebcb67..4025719 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,14 +1,19 @@ { - "name": "Java 17 Dev Container", - "image": "mcr.microsoft.com/devcontainers/java:0-17", + "name": "Java 21 Dev Container", + "image": "mcr.microsoft.com/devcontainers/java:21", "customizations": { "vscode": { - "extensions": [ - "vscjava.vscode-java-pack", - "redhat.java" - ] + "settings": { + "java.jdt.ls.java.home": "/usr/lib/jvm/msopenjdk-current", + "java.configuration.runtimes": [ + { + "name": "JavaSE-21", + "path": "/usr/lib/jvm/msopenjdk-current" + } + ] + } } }, - "forwardPorts": [], - "postCreateCommand": "./.devcontainer/setup.sh" -} \ No newline at end of file + "postCreateCommand": "sudo apt-get update && sudo apt-get install -y maven", + "remoteUser": "vscode" +} diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh deleted file mode 100644 index f17d66b..0000000 --- a/.devcontainer/setup.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# Disable Git LFS in Codespaces automatically -git lfs uninstall || true -rm -f "$(git rev-parse --git-dir)/hooks/pre-push" || true -mvn -q -DskipTests=true package || true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 524f096..77f5026 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Compiled class file *.class +# Target Directory +target + # Log file *.log diff --git a/README.md b/README.md index 43b00d9..cded820 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # Java Fundamentals Challenges -Open this repo in GitHub Codespaces: -[![Open in Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/FRC-7525/Java-Basics-Training-Assignment-2025) - -## How students should work -1. Fork this repository (or "Use this template" if the repo is set as a template). -2. Open your fork in Codespaces (use the button above). -3. Create a branch for your solution: `git checkout -b username-ch1` -4. Implement methods / files in `src/main/java` and run tests with: `mvn test` -5. Push your branch and open a Pull Request back to the upstream `main` branch. - -## Ignore this: -- Autograder: GitHub Actions runs `mvn test` on push and pull request. +DUE: Next meeting +Lmk if you have questions or can't complete it on time. + +## STEPS: +1. Fork this repository +2. Open your fork in Codespaces. +3. Create a branch for your solution: `git checkout -b [SOME_BRANCH_NAME]` +4. Complete FundamentalsPractice and then PasswordChecker +4. Run tests with: `mvn test` +5. Stage changes, commit, and push branch. + + diff --git a/pom.xml b/pom.xml index 63faeee..3537cb2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,36 +1,45 @@ - - 4.0.0 - edu.classroom - java-fundamentals-challenges - 1.0.0 - - 17 - 17 - UTF-8 - 5.9.3 - - - - org.junit.jupiter - junit-jupiter - ${junit.jupiter.version} - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M7 - - false - - - - + http://maven.apache.org/maven-v4_0_0.xsd"> + + 4.0.0 + + com.example + java-basics + 1.0-SNAPSHOT + + + 21 + 21 + UTF-8 + 5.10.0 + + + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 21 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + diff --git a/src/main/java/challenges/FundamentalsPractice.java b/src/main/java/challenges/FundamentalsPractice.java index 9c11e5c..ac975c4 100644 --- a/src/main/java/challenges/FundamentalsPractice.java +++ b/src/main/java/challenges/FundamentalsPractice.java @@ -9,25 +9,125 @@ public class FundamentalsPractice { - // Ex: helper used by unit tests (students implement) - public static int sum(int[] arr) { - int s = 0; - for (int v : arr) s += v; - return s; + // Example: sum of two integers + public static int sum(int a, int b) { // The values in parentheses are set for you. Ex: Here a and b are assigned to integers and can be used in code + int total = a + b; // Your code goes here + return total; // To submit the answer, return it like this. } - // Another example: average of doubles - public static double average(double[] arr) { - if (arr.length == 0) return 0.0; - double s = 0; - for (double v : arr) s += v; - return s / arr.length; + /** + * fizzbuzz - You are given an array of ints. + * Print "Fizz" for multiples of 3, + * "Buzz" for multiples of 5, + * and "FizzBuzz" for multiples of both 3 and 5. + * For other numbers, print the number itself. + * RETURN an array (NOT ARRAYLIST) that contains the number of times ["Fizz", "Buzz", "FizzBuzz"] were printed. + * 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; } - // main stays interactive for manual testing (optional) + /** + * reverseString - Given a String, return the reverse of the string. + * Ex: "hello" -> "olleh" + * Hint: You can convert an arary of characters back to a string like this: + * char[] charArray = {'h', 'e', 'l', 'l', 'o'}; + * String str = new String(charArray); // str is "hello" + * Hint: You can convert a string to an array of characters like this: + * String str = "hello"; + * char[] charArray = str.toCharArray(); // charArray is ['h', 'e', 'l', 'l', 'o'] + */ + public static String reverseString(String input) { + // Your code goes here + return null; + } + + /** + * maxInArray - Given an array of integers, return the largest value. + * Ex: [1, 5, 3, 9, 2] -> 9 + */ + public static int maxInArray(int[] arr) { + // Your code goes here + return 0; + } + + public static boolean stringsAreSame(String a, String b) { + // 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 null; + } + + /** + * countVowels - Given a string, return the number of vowels (a, e, i, o, u) in the string. + * Ex: "banana" -> 3 + * Hint: + * - strings can be accessed like this: variable.charAt(0) returns the first character + */ + public static int countVowels(String input) { + // Your code goes here + return 0; + } + + /** + * isPrime - Given an integer, return true if it is a prime number, false otherwise. + * Ex: 7 -> true, 8 -> false + * Hint: to check if n is prime, divide it by all integers from 2 to sqrt(n). + */ + public static boolean isPrime(int n) { + // Your code goes here + return false; + } + + /** + * factorial - Given a non-negative integer n, return n! (n factorial). + * Ex: 5 -> 120 + * Hint: n! = n * (n-1) * (n-2) * ... * 1, and 0! = 1 + * don't use recursion. + * THIS ONE IS HARD + */ + public static long factorial(int n) { + // Your code goes here + return 0L; + } + + + + // Use for Manual Testing public static void main(String[] args) { - Scanner in = new Scanner(System.in); - System.out.println("This is a starter file. Implement methods for unit tests."); - in.close(); + 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 ==============="); } } diff --git a/src/main/java/challenges/PasswordChecker.java b/src/main/java/challenges/PasswordChecker.java new file mode 100644 index 0000000..fd04b93 --- /dev/null +++ b/src/main/java/challenges/PasswordChecker.java @@ -0,0 +1,56 @@ +import java.util.Scanner; + +/* + * 🎯 Goal + * + * Create a program that: + * - Takes a password as input. + * - Checks: + * - Length ≥ 8 + * - Contains uppercase, lowercase, number, and symbol + * - Outputs a strength rating: + * - “Weak”, “Moderate”, or “Strong” + * - “Weak” if length < 8 or missing 2+ types + * - “Moderate” if length ≥ 8 and missing 1 type + * - “Strong” if length ≥ 8 and has all 4 types + * + * + * 💡 Hints + * - Loop through each character with: for (char c : password.toCharArray()). + * - Use Character.isUpperCase(), Character.isLowerCase(), and Character.isDigit(). + * - Symbol = not upper/lower/digit. + */ + + +public class PasswordStrengthChecker { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + // 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); + + // TODO: Output the strength rating + // System.out.println(strength); + + scanner.close(); + } + + /** + * Checks the strength of the given password. + * Returns "Weak", "Moderate", or "Strong". + * + * @param password The password to check + * @return The strength rating + */ + public static String checkPasswordStrength(String password) { + // TODO: Implement the logic to check password strength + // - Check length + // - Check for uppercase, lowercase, digit, and symbol + // - Return the appropriate rating + + return ""; // Placeholder + } +} \ No newline at end of file diff --git a/src/test/java/challenges/FundamentalsPracticeTest.java b/src/test/java/challenges/FundamentalsPracticeTest.java index eefd509..afeaaed 100644 --- a/src/test/java/challenges/FundamentalsPracticeTest.java +++ b/src/test/java/challenges/FundamentalsPracticeTest.java @@ -2,18 +2,54 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; +import java.util.Arrays; public class FundamentalsPracticeTest { @Test public void testSum() { - int[] a = {1,2,3,4}; - assertEquals(10, FundamentalsPractice.sum(a)); + assertEquals(8, FundamentalsPractice.sum(3, 5)); } @Test - public void testAverage() { - double[] a = {2.0, 4.0, 6.0}; - assertEquals(4.0, FundamentalsPractice.average(a), 1e-6); + public void testFizzBuzz() { + int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15}; + int[] expected = {3, 2, 1}; + assertArrayEquals(expected, FundamentalsPractice.fizzbuzz(arr)); + } + + @Test + public void testReverseString() { + assertEquals("olleh", FundamentalsPractice.reverseString("hello")); + assertEquals("", FundamentalsPractice.reverseString("")); + assertEquals("a", FundamentalsPractice.reverseString("a")); + } + + @Test + public void testMaxInArray() { + assertEquals(9, FundamentalsPractice.maxInArray(new int[]{1, 5, 3, 9, 2})); + assertEquals(-1, FundamentalsPractice.maxInArray(new int[]{-5, -1, -9})); + } + + @Test + public void testCountVowels() { + assertEquals(3, FundamentalsPractice.countVowels("banana")); + assertEquals(0, FundamentalsPractice.countVowels("rhythm")); + assertEquals(5, FundamentalsPractice.countVowels("aeiou")); + } + + @Test + public void testIsPrime() { + assertTrue(FundamentalsPractice.isPrime(7)); + assertFalse(FundamentalsPractice.isPrime(8)); + assertFalse(FundamentalsPractice.isPrime(1)); + assertTrue(FundamentalsPractice.isPrime(2)); + } + + @Test + public void testFactorial() { + assertEquals(120, FundamentalsPractice.factorial(5)); + assertEquals(1, FundamentalsPractice.factorial(0)); + assertEquals(1, FundamentalsPractice.factorial(1)); } } diff --git a/src/test/java/challenges/PasswordCheckerTest.java b/src/test/java/challenges/PasswordCheckerTest.java new file mode 100644 index 0000000..3fef9ab --- /dev/null +++ b/src/test/java/challenges/PasswordCheckerTest.java @@ -0,0 +1,47 @@ +package challenges; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class PasswordCheckerTest { + + @Test + public void testWeakPasswordShort() { + assertEquals("Weak", PasswordStrengthChecker.checkPasswordStrength("abc")); + } + + @Test + public void testWeakPasswordMissingTypes() { + // Only lowercase, length >= 8 + assertEquals("Weak", PasswordStrengthChecker.checkPasswordStrength("abcdefgh")); + // Only digits, length >= 8 + assertEquals("Weak", PasswordStrengthChecker.checkPasswordStrength("12345678")); + } + + @Test + public void testModeratePassword() { + // Missing symbol + assertEquals("Moderate", PasswordStrengthChecker.checkPasswordStrength("Abcdefg1")); + // Missing digit + assertEquals("Moderate", PasswordStrengthChecker.checkPasswordStrength("Abcdefg!")); + // Missing uppercase + assertEquals("Moderate", PasswordStrengthChecker.checkPasswordStrength("abcdef1!")); + // Missing lowercase + assertEquals("Moderate", PasswordStrengthChecker.checkPasswordStrength("ABCDEF1!")); + } + + @Test + public void testStrongPassword() { + assertEquals("Strong", PasswordStrengthChecker.checkPasswordStrength("Abcdef1!")); + assertEquals("Strong", PasswordStrengthChecker.checkPasswordStrength("A1b2c3d4!")); + } + + @Test + public void testEdgeCases() { + // Exactly 8 chars, all types + assertEquals("Strong", PasswordStrengthChecker.checkPasswordStrength("A1b2c3!d")); + // 8 chars, missing 2 types + assertEquals("Weak", PasswordStrengthChecker.checkPasswordStrength("Abcdefgh")); + } + +} From 8e47c9f8432333a2d7620e2b654014b5017ccab0 Mon Sep 17 00:00:00 2001 From: Aitan Martinez <161392373+Tortuga-AM@users.noreply.github.com> Date: Mon, 13 Oct 2025 02:04:02 +0000 Subject: [PATCH 2/2] test actions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cded820..f0c0a5f 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,6 @@ Lmk if you have questions or can't complete it on time. 3. Create a branch for your solution: `git checkout -b [SOME_BRANCH_NAME]` 4. Complete FundamentalsPractice and then PasswordChecker 4. Run tests with: `mvn test` -5. Stage changes, commit, and push branch. +5. Stage changes, commit, and push branch.