diff --git a/.idea/modules.xml b/.idea/modules.xml index 5a8155d33..caf004d26 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/classes-part-one/exercises/Course.java b/classes-part-one/exercises/Course.java new file mode 100644 index 000000000..3e1fbd4bc --- /dev/null +++ b/classes-part-one/exercises/Course.java @@ -0,0 +1,12 @@ +package exercises.classespart1; + +import exercises.classespart2.Teacher; + +import java.util.ArrayList; + +public class Course { + private String topic; + private Teacher instructor; + private ArrayList enrolledStudents; + } +} diff --git a/classes-part-one/exercises/Student.java b/classes-part-one/exercises/Student.java new file mode 100644 index 000000000..5bfc4c60b --- /dev/null +++ b/classes-part-one/exercises/Student.java @@ -0,0 +1,42 @@ +package exercises.classespart1; + +public class Student { + + private String name; + private int studentId; + private int numberOfCredits = 0; + private double gpa = 0; + + public void setName(String name) { + this.name = name; + } + + public void setStudentId(int studentId) { + this.studentId = studentId; + } + + public void setGpa(double gpa) { + this.gpa = gpa; + } + + private void setNumberOfCredits(int numberOfCredits) { + this.numberOfCredits = numberOfCredits; + } + + public String getName() { + return name; + } + + public int getStudentId() { + return studentId; + } + + public int getNumberOfCredits() { + return numberOfCredits; + } + + public double getGpa() { + return gpa; + } + +} diff --git a/classes-part-one/exercises/StudentPractice.java b/classes-part-one/exercises/StudentPractice.java new file mode 100644 index 000000000..5fe511b93 --- /dev/null +++ b/classes-part-one/exercises/StudentPractice.java @@ -0,0 +1,12 @@ +public class StudentPractice { + public static void main(String[] args){ + //insantiate your Student class below + Student student = new Student("Your Name", 12345, 1, 4.0); + + //access properties if student took this step + String name = student.getName(); + int studentId = student.getStudentId(); + int numberOfCredits = student.getNumberOfCredits(); + double gpa = student.getGpa(); + } +} diff --git a/classes-part-one/studio/Main.java b/classes-part-one/studio/Main.java new file mode 100644 index 000000000..cad5849f1 --- /dev/null +++ b/classes-part-one/studio/Main.java @@ -0,0 +1,8 @@ +package org.launchcode; + +public class Main { + + public static void main(String[] args) { + // write your code here + } +} diff --git a/classes-part-one/studio/Menu.java b/classes-part-one/studio/Menu.java new file mode 100644 index 000000000..fc892ffe9 --- /dev/null +++ b/classes-part-one/studio/Menu.java @@ -0,0 +1,30 @@ +package org.launchcode; + +import java.util.ArrayList; +import java.util.Date; + +public class Menu { + private Date lastUpdated; + private ArrayList items; + + public Menu(Date d, ArrayList i) { + this.lastUpdated = d; + this.items = i; + } + + public void setLastUpdated(Date lastUpdated) { + this.lastUpdated = lastUpdated; + } + + public void setItems(ArrayList items) { + this.items = items; + } + + public Date getLastUpdated() { + return lastUpdated; + } + + public ArrayList getItems() { + return items; + } +} diff --git a/classes-part-one/studio/MenuItem.java b/classes-part-one/studio/MenuItem.java new file mode 100644 index 000000000..776c2764d --- /dev/null +++ b/classes-part-one/studio/MenuItem.java @@ -0,0 +1,31 @@ +package org.launchcode; + +public class MenuItem { + private double price; + private String description; + private String category; + private boolean isNew; + + public MenuItem(double p, String d, String c, boolean iN) { + this.price = p; + this.description = d; + this.category = c; + this.isNew = iN; + } + + public void setPrice(double price) { + this.price = price; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setCategory(String category) { + this.category = category; + } + + public void setNew(boolean aNew) { + isNew = aNew; + } +} diff --git a/control-flow-and-collections/chapter-example/student-example/.idea/gradle.xml b/control-flow-and-collections/chapter-example/student-example/.idea/gradle.xml new file mode 100644 index 000000000..5128e8731 --- /dev/null +++ b/control-flow-and-collections/chapter-example/student-example/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/chapter-example/student-example/.idea/misc.xml b/control-flow-and-collections/chapter-example/student-example/.idea/misc.xml new file mode 100644 index 000000000..87a20fc38 --- /dev/null +++ b/control-flow-and-collections/chapter-example/student-example/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/chapter-example/student-example/.idea/uiDesigner.xml b/control-flow-and-collections/chapter-example/student-example/.idea/uiDesigner.xml new file mode 100644 index 000000000..2b63946d5 --- /dev/null +++ b/control-flow-and-collections/chapter-example/student-example/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/chapter-example/student-example/.idea/vcs.xml b/control-flow-and-collections/chapter-example/student-example/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/control-flow-and-collections/chapter-example/student-example/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/.gitignore b/control-flow-and-collections/exercises/collections-exercises/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/.idea/.gitignore b/control-flow-and-collections/exercises/collections-exercises/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/control-flow-and-collections/exercises/collections-exercises/.idea/gradle.xml b/control-flow-and-collections/exercises/collections-exercises/.idea/gradle.xml new file mode 100644 index 000000000..5128e8731 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/.idea/misc.xml b/control-flow-and-collections/exercises/collections-exercises/.idea/misc.xml new file mode 100644 index 000000000..87a20fc38 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/.idea/uiDesigner.xml b/control-flow-and-collections/exercises/collections-exercises/.idea/uiDesigner.xml new file mode 100644 index 000000000..2b63946d5 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/.idea/vcs.xml b/control-flow-and-collections/exercises/collections-exercises/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/build.gradle.kts b/control-flow-and-collections/exercises/collections-exercises/build.gradle.kts new file mode 100644 index 000000000..a6c5d7d78 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") +} + +group = "org.example" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/gradle/wrapper/gradle-wrapper.jar b/control-flow-and-collections/exercises/collections-exercises/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/control-flow-and-collections/exercises/collections-exercises/gradle/wrapper/gradle-wrapper.jar differ diff --git a/control-flow-and-collections/exercises/collections-exercises/gradle/wrapper/gradle-wrapper.properties b/control-flow-and-collections/exercises/collections-exercises/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..6a5bde679 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Jun 22 15:57:30 CDT 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/control-flow-and-collections/exercises/collections-exercises/gradlew b/control-flow-and-collections/exercises/collections-exercises/gradlew new file mode 100755 index 000000000..1b6c78733 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/control-flow-and-collections/exercises/collections-exercises/gradlew.bat b/control-flow-and-collections/exercises/collections-exercises/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/control-flow-and-collections/exercises/collections-exercises/settings.gradle.kts b/control-flow-and-collections/exercises/collections-exercises/settings.gradle.kts new file mode 100644 index 000000000..d3c7387f2 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "collections-exercises" + diff --git a/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/ArrayListPractice.java b/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/ArrayListPractice.java new file mode 100644 index 000000000..51a492419 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/ArrayListPractice.java @@ -0,0 +1,44 @@ +package org.launchcode; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + +public class ArrayListPractice { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + + // Declare and initialize the integer list and word list: + ArrayList someIntegers = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 33, 42, 101, 1138)); + String phrase = "I would not could not in a box I would not could not with a fox I will not eat them in a house I will not eat them with a mouse"; + ArrayList wordList = new ArrayList<>(Arrays.asList(phrase.split(" "))); + + // Call the sumEven method to calculate the sum of the even numbers in a list: + System.out.println(sumEven(someIntegers)); + + // Prompt the user for a word length: + System.out.println("Enter a word length: "); + int numChars = input.nextInt(); + + // Call the method to print out list words of the chosen length: + printFiveLetterWords(wordList, numChars); + } + + public static int sumEven(ArrayList arr){ + int total = 0; + for (int integer : arr) { + if (integer % 2 == 0) { + total += integer; + } + } + return total; + } + + public static void printFiveLetterWords(ArrayList arr, int length){ + for (String word : arr) { + if (word.length() == length) { + System.out.println(word); + } + } + } +} \ No newline at end of file diff --git a/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/ArrayPractice.java b/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/ArrayPractice.java new file mode 100644 index 000000000..344a037bf --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/ArrayPractice.java @@ -0,0 +1,31 @@ +package org.launchcode; + +import java.util.Arrays; + +public class ArrayPractice { + public static void main(String[] args) { + int[] integerArray = {1, 1, 2, 3, 5, 8}; + String phrase = "I would not, could not, in a box. I would not, could not with a fox. I will not eat them in a house. I will not eat them with a mouse."; + + // Print out each number in the array using a for-each loop. + for (int integer: integerArray) { + System.out.println(integer); + } + + // Print out each even number in the array using a for loop (for-each works as well). + for (int i = 0; i < integerArray.length; i++) { + if (integerArray[i]%2 == 0){ + System.out.println(integerArray[i]); + } + } + + // Split 'phrase' into an array of words, then print the array. + String[] words = phrase.split(" "); + System.out.println(Arrays.toString(words)); + + // Split 'phrase' into an array of sentences, then print the array. + // "." does not work as-is for the deliminator. "\\." escapes it's special meaning. + String[] sentences = phrase.split("\\."); + System.out.println(Arrays.toString(sentences)); + } +} diff --git a/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/HashMapPractice.java b/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/HashMapPractice.java new file mode 100644 index 000000000..28fca3a76 --- /dev/null +++ b/control-flow-and-collections/exercises/collections-exercises/src/main/java/org/launchcode/HashMapPractice.java @@ -0,0 +1,41 @@ +package org.launchcode; + +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class HashMapPractice { + public static void main(String[] args) { + HashMap classRoster = new HashMap<>(); + Scanner input = new Scanner(System.in); + String newStudent; + + System.out.println("Enter your students' names and ID numbers (or ENTER to finish):"); + + // Get student names and IDs + do { + System.out.print("Student: "); + newStudent = input.nextLine(); + + if (!newStudent.equals("")) { + System.out.print("ID: "); + Integer newID = input.nextInt(); + classRoster.put(newID, newStudent); + + // Read in the new line before looping back + input.nextLine(); + } + } while(!newStudent.equals("")); + + input.close(); + + // Print class roster + System.out.println("\nClass roster:"); + + for (Map.Entry student : classRoster.entrySet()) { + System.out.println(student.getValue() + "'s ID: " + student.getKey()); + } + + System.out.println("Number of students in roster: " + classRoster.size()); + } +} diff --git a/control-flow-and-collections/studio/counting-characters/.gitignore b/control-flow-and-collections/studio/counting-characters/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/.idea/.gitignore b/control-flow-and-collections/studio/counting-characters/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/control-flow-and-collections/studio/counting-characters/.idea/gradle.xml b/control-flow-and-collections/studio/counting-characters/.idea/gradle.xml new file mode 100644 index 000000000..5128e8731 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/.idea/misc.xml b/control-flow-and-collections/studio/counting-characters/.idea/misc.xml new file mode 100644 index 000000000..87a20fc38 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/.idea/uiDesigner.xml b/control-flow-and-collections/studio/counting-characters/.idea/uiDesigner.xml new file mode 100644 index 000000000..2b63946d5 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/.idea/vcs.xml b/control-flow-and-collections/studio/counting-characters/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/build.gradle.kts b/control-flow-and-collections/studio/counting-characters/build.gradle.kts new file mode 100644 index 000000000..ebe72c2da --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") +} + +group = "org.launchcode" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/control-flow-and-collections/studio/counting-characters/gradle/wrapper/gradle-wrapper.jar b/control-flow-and-collections/studio/counting-characters/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/control-flow-and-collections/studio/counting-characters/gradle/wrapper/gradle-wrapper.jar differ diff --git a/control-flow-and-collections/studio/counting-characters/gradle/wrapper/gradle-wrapper.properties b/control-flow-and-collections/studio/counting-characters/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..53bf6475e --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Jun 22 16:08:39 CDT 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/control-flow-and-collections/studio/counting-characters/gradlew b/control-flow-and-collections/studio/counting-characters/gradlew new file mode 100755 index 000000000..1b6c78733 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/control-flow-and-collections/studio/counting-characters/gradlew.bat b/control-flow-and-collections/studio/counting-characters/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/control-flow-and-collections/studio/counting-characters/settings.gradle.kts b/control-flow-and-collections/studio/counting-characters/settings.gradle.kts new file mode 100644 index 000000000..5b37dd82c --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "counting-characters" + diff --git a/control-flow-and-collections/studio/counting-characters/src/main/java/org/launchcode/CountingCharacters.java b/control-flow-and-collections/studio/counting-characters/src/main/java/org/launchcode/CountingCharacters.java new file mode 100644 index 000000000..2bd318f28 --- /dev/null +++ b/control-flow-and-collections/studio/counting-characters/src/main/java/org/launchcode/CountingCharacters.java @@ -0,0 +1,26 @@ +package org.launchcode; + +import java.util.HashMap; +import java.util.Map; + +public class CountingCharacters { + public static void main(String[] args) { + + HashMap characterCounts = new HashMap<>(); + String testString = "If the product of two terms is zero then common sense says at least one of the two terms has to be zero to start with. So if you move all the terms over to one side, you can put the quadratics into a form that can be factored allowing that side of the equation to equal zero. Once you’ve done that, it’s pretty straightforward from there."; + char[] charactersInString = testString.toCharArray(); + + for (char character : charactersInString) { + if (characterCounts.containsKey(character)) { + characterCounts.put(character, characterCounts.get(character) + 1); + } + else { + characterCounts.put(character, 1); + } + } + for (Map.Entry oneChar : characterCounts.entrySet()) { + System.out.println(oneChar.getKey() + ": " + oneChar.getValue()); + } + + } +} \ No newline at end of file diff --git a/controllers-and-routing/exercises/.gitignore b/controllers-and-routing/exercises/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/controllers-and-routing/exercises/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/.gitignore b/controllers-and-routing/exercises/controllers-routing-exercises/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/.idea/.gitignore b/controllers-and-routing/exercises/controllers-routing-exercises/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/.idea/gradle.xml b/controllers-and-routing/exercises/controllers-routing-exercises/.idea/gradle.xml new file mode 100644 index 000000000..2a65317ef --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/.idea/misc.xml b/controllers-and-routing/exercises/controllers-routing-exercises/.idea/misc.xml new file mode 100644 index 000000000..24e284c34 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/.idea/vcs.xml b/controllers-and-routing/exercises/controllers-routing-exercises/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/build.gradle b/controllers-and-routing/exercises/controllers-routing-exercises/build.gradle new file mode 100644 index 000000000..fd7630a89 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.1.1' + id 'io.spring.dependency-management' version '1.1.0' +} + +group = 'org.launchcode' +version = '1.0-SNAPSHOT' + +java { + sourceCompatibility = '17' +} + + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/gradle/wrapper/gradle-wrapper.jar b/controllers-and-routing/exercises/controllers-routing-exercises/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/controllers-and-routing/exercises/controllers-routing-exercises/gradle/wrapper/gradle-wrapper.jar differ diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/gradle/wrapper/gradle-wrapper.properties b/controllers-and-routing/exercises/controllers-routing-exercises/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..412b9b442 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Jun 28 14:05:20 CDT 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/gradlew b/controllers-and-routing/exercises/controllers-routing-exercises/gradlew new file mode 100755 index 000000000..1b6c78733 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/gradlew.bat b/controllers-and-routing/exercises/controllers-routing-exercises/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/settings.gradle b/controllers-and-routing/exercises/controllers-routing-exercises/settings.gradle new file mode 100644 index 000000000..919aaa325 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'controllers-routing-exercises' + diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java b/controllers-and-routing/exercises/controllers-routing-exercises/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java new file mode 100644 index 000000000..4fa46655f --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java @@ -0,0 +1,13 @@ +package org.launchcode.hellospring; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HelloSpringApplication { + + public static void main(String[] args) { + SpringApplication.run(HelloSpringApplication.class, args); + } + +} diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/src/main/java/org/launchcode/hellospring/controllers/HelloController.java b/controllers-and-routing/exercises/controllers-routing-exercises/src/main/java/org/launchcode/hellospring/controllers/HelloController.java new file mode 100644 index 000000000..2cc722bbc --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/src/main/java/org/launchcode/hellospring/controllers/HelloController.java @@ -0,0 +1,86 @@ +package org.launchcode.hellospring.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +@Controller +public class HelloController { + +// @RequestMapping(value="") +// @ResponseBody +// public String index(@RequestParam String name) { +// if (name == null) { +// name = "World"; +// } +// return "Hello " + name; +// } + + @RequestMapping(value="hello", method = RequestMethod.GET) + @ResponseBody + public String helloForm() { + + String html = "
" + + "" + + "" + + "" + + "
"; + return html; + + // For a bonus mission, the options of the select need to be pulled in from a model. + // If a student has chosen to try this mission, they need to add a models package that contains a model for the different language options. + } + + @RequestMapping(value="hello", method = RequestMethod.POST) + @ResponseBody + public String helloPost(@RequestParam String name, @RequestParam String language) { + if (name == null) { + name = "World"; + } + + return createMessage(name, language); + + // For a bonus mission, students can change this response text to look nicer. + // This is subjective, but students should be modifying the HTML of the response string. + } + + public static String createMessage(String n, String l) { + String greeting = ""; + + if (l.equals("english")) { + greeting = "Hello"; + } + else if (l.equals("french")) { + greeting = "Bonjour"; + } + else if (l.equals("italian")) { + greeting = "Bonjourno"; + } + else if (l.equals("spanish")) { + greeting = "Hola"; + } + else if (l.equals("german")) { + greeting = "Hallo"; + } + + return greeting + " " + n; + } + + @RequestMapping(value="hello/{name}") + @ResponseBody + public String helloUrlSegment(@PathVariable String name) { + return "Hello " + name; + } + + @RequestMapping(value="goodbye") + @ResponseBody + public String goodbye() { + return "Goodbye!"; + } +} + diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/src/main/resources/application.properties b/controllers-and-routing/exercises/controllers-routing-exercises/src/main/resources/application.properties new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/controllers-and-routing/exercises/controllers-routing-exercises/src/test/java/org/launchcode/hellospring/HelloSpringApplicationTests.java b/controllers-and-routing/exercises/controllers-routing-exercises/src/test/java/org/launchcode/hellospring/HelloSpringApplicationTests.java new file mode 100644 index 000000000..5d46a99f7 --- /dev/null +++ b/controllers-and-routing/exercises/controllers-routing-exercises/src/test/java/org/launchcode/hellospring/HelloSpringApplicationTests.java @@ -0,0 +1,13 @@ +package org.launchcode.hellospring; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class HelloSpringApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/controllers-and-routing/studio/controllers-routing-studio/.gitignore b/controllers-and-routing/studio/controllers-routing-studio/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/controllers-and-routing/studio/controllers-routing-studio/.idea/.gitignore b/controllers-and-routing/studio/controllers-routing-studio/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/controllers-and-routing/studio/controllers-routing-studio/.idea/gradle.xml b/controllers-and-routing/studio/controllers-routing-studio/.idea/gradle.xml new file mode 100644 index 000000000..14746e766 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/controllers-and-routing/studio/controllers-routing-studio/.idea/misc.xml b/controllers-and-routing/studio/controllers-routing-studio/.idea/misc.xml new file mode 100644 index 000000000..87a20fc38 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/controllers-and-routing/studio/controllers-routing-studio/.idea/vcs.xml b/controllers-and-routing/studio/controllers-routing-studio/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/controllers-and-routing/studio/controllers-routing-studio/build.gradle b/controllers-and-routing/studio/controllers-routing-studio/build.gradle new file mode 100644 index 000000000..416fe0aa0 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/build.gradle @@ -0,0 +1,30 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.1.1' + id 'io.spring.dependency-management' version '1.1.0' +} + +group = 'org.launchcode' +version = '1.0-SNAPSHOT' + +java { + sourceCompatibility = '17' +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' + implementation 'org.springframework.boot:spring-boot-starter-web' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/controllers-and-routing/studio/controllers-routing-studio/gradle/wrapper/gradle-wrapper.jar b/controllers-and-routing/studio/controllers-routing-studio/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..ccebba771 Binary files /dev/null and b/controllers-and-routing/studio/controllers-routing-studio/gradle/wrapper/gradle-wrapper.jar differ diff --git a/controllers-and-routing/studio/controllers-routing-studio/gradle/wrapper/gradle-wrapper.properties b/controllers-and-routing/studio/controllers-routing-studio/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..42defcc94 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/controllers-and-routing/studio/controllers-routing-studio/gradlew b/controllers-and-routing/studio/controllers-routing-studio/gradlew new file mode 100755 index 000000000..79a61d421 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/gradlew @@ -0,0 +1,244 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/controllers-and-routing/studio/controllers-routing-studio/gradlew.bat b/controllers-and-routing/studio/controllers-routing-studio/gradlew.bat new file mode 100644 index 000000000..6689b85be --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/controllers-and-routing/studio/controllers-routing-studio/settings.gradle b/controllers-and-routing/studio/controllers-routing-studio/settings.gradle new file mode 100644 index 000000000..018664cb9 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'controllers-routing-studio' + diff --git a/controllers-and-routing/studio/controllers-routing-studio/src/main/java/org/launchcode/SkillsTrackerApplication.java b/controllers-and-routing/studio/controllers-routing-studio/src/main/java/org/launchcode/SkillsTrackerApplication.java new file mode 100644 index 000000000..8c523d873 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/src/main/java/org/launchcode/SkillsTrackerApplication.java @@ -0,0 +1,13 @@ +package org.launchcode; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SkillsTrackerApplication { + + public static void main(String[] args) { + SpringApplication.run(SkillsTrackerApplication.class, args); + } + +} diff --git a/controllers-and-routing/studio/controllers-routing-studio/src/main/java/org/launchcode/controllers/SkillsController.java b/controllers-and-routing/studio/controllers-routing-studio/src/main/java/org/launchcode/controllers/SkillsController.java new file mode 100644 index 000000000..3cc70cda3 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/src/main/java/org/launchcode/controllers/SkillsController.java @@ -0,0 +1,64 @@ +package org.launchcode.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +@Controller +public class SkillsController { + + @RequestMapping(value="") + @ResponseBody + public String startSkills () { + String html = "

Skills Tracker

" + + "

We have a few skills we would like to learn. Here is the list!

" + + "
    " + + "
  1. Java
  2. " + + "
  3. JavaScript
  4. " + + "
  5. Python
  6. " + + "
"; + + return html; + } + + @GetMapping(value="form") + @ResponseBody + public String formSkills() { + String html = "
" + + "Name:
" + + "" + + "
My favorite language:
" + + "" + + "
My second favorite language:
" + + "" + + "
My third favorite language:
" + + "
" + + "" + + "
"; + + return html; + } + + @PostMapping(value="form") + @ResponseBody + public String namePage(@RequestParam String name, @RequestParam String firstChoice, @RequestParam String secondChoice, @RequestParam String thirdChoice) { + String html = "

" + name + "

" + + "
    " + + "
  1. " + firstChoice + "
  2. " + + "
  3. " + secondChoice + "
  4. " + + "
  5. " + thirdChoice + "
  6. " + + "
"; + return html; + } +} diff --git a/controllers-and-routing/studio/controllers-routing-studio/src/main/resources/application.properties b/controllers-and-routing/studio/controllers-routing-studio/src/main/resources/application.properties new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/controllers-and-routing/studio/controllers-routing-studio/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/unit-testing/chapter-example/car-example/.gitignore b/unit-testing/chapter-example/car-example/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/unit-testing/chapter-example/car-example/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/unit-testing/chapter-example/car-example/.idea/.gitignore b/unit-testing/chapter-example/car-example/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/unit-testing/chapter-example/car-example/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/unit-testing/chapter-example/car-example/.idea/gradle.xml b/unit-testing/chapter-example/car-example/.idea/gradle.xml new file mode 100644 index 000000000..5128e8731 --- /dev/null +++ b/unit-testing/chapter-example/car-example/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/unit-testing/chapter-example/car-example/.idea/misc.xml b/unit-testing/chapter-example/car-example/.idea/misc.xml new file mode 100644 index 000000000..87a20fc38 --- /dev/null +++ b/unit-testing/chapter-example/car-example/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/unit-testing/chapter-example/car-example/.idea/vcs.xml b/unit-testing/chapter-example/car-example/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/unit-testing/chapter-example/car-example/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/unit-testing/chapter-example/car-example/build.gradle.kts b/unit-testing/chapter-example/car-example/build.gradle.kts new file mode 100644 index 000000000..ebe72c2da --- /dev/null +++ b/unit-testing/chapter-example/car-example/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") +} + +group = "org.launchcode" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/unit-testing/chapter-example/car-example/gradle/wrapper/gradle-wrapper.jar b/unit-testing/chapter-example/car-example/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/unit-testing/chapter-example/car-example/gradle/wrapper/gradle-wrapper.jar differ diff --git a/unit-testing/chapter-example/car-example/gradle/wrapper/gradle-wrapper.properties b/unit-testing/chapter-example/car-example/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..694b92f2e --- /dev/null +++ b/unit-testing/chapter-example/car-example/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Jun 29 14:44:47 CDT 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/unit-testing/chapter-example/car-example/gradlew b/unit-testing/chapter-example/car-example/gradlew new file mode 100755 index 000000000..1b6c78733 --- /dev/null +++ b/unit-testing/chapter-example/car-example/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/unit-testing/chapter-example/car-example/gradlew.bat b/unit-testing/chapter-example/car-example/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/unit-testing/chapter-example/car-example/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/unit-testing/chapter-example/car-example/settings.gradle.kts b/unit-testing/chapter-example/car-example/settings.gradle.kts new file mode 100644 index 000000000..b85944034 --- /dev/null +++ b/unit-testing/chapter-example/car-example/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "car-example" + diff --git a/unit-testing/chapter-example/car-example/src/main/java/org/launchcode/Car.java b/unit-testing/chapter-example/car-example/src/main/java/org/launchcode/Car.java new file mode 100644 index 000000000..d10c16f72 --- /dev/null +++ b/unit-testing/chapter-example/car-example/src/main/java/org/launchcode/Car.java @@ -0,0 +1,87 @@ +package org.launchcode; + +public class Car { + private String make; + private String model; + private int gasTankSize; + private double gasTankLevel; + private double milesPerGallon; + private double odometer = 0; + + public Car(String make, String model, int gasTankSize, double milesPerGallon) { + this.make = make; + this.model = model; + this.gasTankSize = gasTankSize; + // Gas tank level defaults to a full tank + this.gasTankLevel = gasTankSize; + this.milesPerGallon = milesPerGallon; + } + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public int getGasTankSize() { + return gasTankSize; + } + + public void setGasTankSize(int gasTankSize) { + this.gasTankSize = gasTankSize; + } + + public double getGasTankLevel() { + return gasTankLevel; + } + + public void setGasTankLevel(double gasTankLevel) { + this.gasTankLevel = gasTankLevel; + } + + public double getMilesPerGallon() { + return milesPerGallon; + } + + public void setMilesPerGallon(double milesPerGallon) { + this.milesPerGallon = milesPerGallon; + } + + public double getOdometer() { + return odometer; + } + + /** + * Drive the car an amount of miles. If not enough fuel, drive as far as fuel allows. + * Adjust fuel levels based on amount needed to drive the distance requested. + * Add miles to odometer. + * + * @param miles - the miles to drive + */ + public void drive(double miles) + { + //adjust fuel based on mpg and miles requested to drive + double maxDistance = this.milesPerGallon * this.gasTankLevel; + /**the double below uses some syntax called the ternary operator. + * if the value of miles is greater than the value of maxDistance, + * then milesAbleToTravel = maxDistance. + * otherwise, if miles is not greater than maxDistance, + * then milesAbleToTravel = miles + */ + double milesAbleToTravel = miles > maxDistance ? maxDistance : miles; + double gallonsUsed = milesAbleToTravel / this.milesPerGallon; + this.gasTankLevel = this.gasTankLevel - gallonsUsed; + this.odometer += milesAbleToTravel; + } + +} diff --git a/unit-testing/chapter-example/car-example/src/main/java/org/launchcode/Main.java b/unit-testing/chapter-example/car-example/src/main/java/org/launchcode/Main.java new file mode 100644 index 000000000..a98111f47 --- /dev/null +++ b/unit-testing/chapter-example/car-example/src/main/java/org/launchcode/Main.java @@ -0,0 +1,8 @@ +package org.launchcode; + +public class Main { + public static void main(String[] args) { + Car car = new Car("Toyota", "Prius", 10, 50); + System.out.println(car.getMake() + " - " + car.getModel()); + } +} \ No newline at end of file diff --git a/unit-testing/chapter-example/car-example/src/test/java/org/launchcode/CarTest.java b/unit-testing/chapter-example/car-example/src/test/java/org/launchcode/CarTest.java new file mode 100644 index 000000000..f7b0c6f6e --- /dev/null +++ b/unit-testing/chapter-example/car-example/src/test/java/org/launchcode/CarTest.java @@ -0,0 +1,11 @@ +package org.launchcode; + +import static org.junit.jupiter.api.Assertions.*; + +class CarTest { + //TODO: add emptyTest so we can configure our runtime environment (remove this test before pushing to your personal GitLab account) + //TODO: constructor sets gasTankLevel properly + //TODO: gasTankLevel is accurate after driving within tank range + //TODO: gasTankLevel is accurate after attempting to drive past tank range + //TODO: can't have more gas than tank size, expect an exception +} \ No newline at end of file diff --git a/unit-testing/exercises/car-exercises/.gitignore b/unit-testing/exercises/car-exercises/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/unit-testing/exercises/car-exercises/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/unit-testing/exercises/car-exercises/.idea/.gitignore b/unit-testing/exercises/car-exercises/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/unit-testing/exercises/car-exercises/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/unit-testing/exercises/car-exercises/.idea/gradle.xml b/unit-testing/exercises/car-exercises/.idea/gradle.xml new file mode 100644 index 000000000..5128e8731 --- /dev/null +++ b/unit-testing/exercises/car-exercises/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/unit-testing/exercises/car-exercises/.idea/misc.xml b/unit-testing/exercises/car-exercises/.idea/misc.xml new file mode 100644 index 000000000..87a20fc38 --- /dev/null +++ b/unit-testing/exercises/car-exercises/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/unit-testing/exercises/car-exercises/.idea/vcs.xml b/unit-testing/exercises/car-exercises/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/unit-testing/exercises/car-exercises/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/unit-testing/exercises/car-exercises/build.gradle.kts b/unit-testing/exercises/car-exercises/build.gradle.kts new file mode 100644 index 000000000..a6c5d7d78 --- /dev/null +++ b/unit-testing/exercises/car-exercises/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") +} + +group = "org.example" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/unit-testing/exercises/car-exercises/gradle/wrapper/gradle-wrapper.jar b/unit-testing/exercises/car-exercises/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/unit-testing/exercises/car-exercises/gradle/wrapper/gradle-wrapper.jar differ diff --git a/unit-testing/exercises/car-exercises/gradle/wrapper/gradle-wrapper.properties b/unit-testing/exercises/car-exercises/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..fe8a17614 --- /dev/null +++ b/unit-testing/exercises/car-exercises/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Jun 29 15:08:34 CDT 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/unit-testing/exercises/car-exercises/gradlew b/unit-testing/exercises/car-exercises/gradlew new file mode 100755 index 000000000..1b6c78733 --- /dev/null +++ b/unit-testing/exercises/car-exercises/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/unit-testing/exercises/car-exercises/gradlew.bat b/unit-testing/exercises/car-exercises/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/unit-testing/exercises/car-exercises/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/unit-testing/exercises/car-exercises/settings.gradle.kts b/unit-testing/exercises/car-exercises/settings.gradle.kts new file mode 100644 index 000000000..c08e1dfb1 --- /dev/null +++ b/unit-testing/exercises/car-exercises/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "car-exercises" + diff --git a/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Car.java b/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Car.java new file mode 100644 index 000000000..d10c16f72 --- /dev/null +++ b/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Car.java @@ -0,0 +1,87 @@ +package org.launchcode; + +public class Car { + private String make; + private String model; + private int gasTankSize; + private double gasTankLevel; + private double milesPerGallon; + private double odometer = 0; + + public Car(String make, String model, int gasTankSize, double milesPerGallon) { + this.make = make; + this.model = model; + this.gasTankSize = gasTankSize; + // Gas tank level defaults to a full tank + this.gasTankLevel = gasTankSize; + this.milesPerGallon = milesPerGallon; + } + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public int getGasTankSize() { + return gasTankSize; + } + + public void setGasTankSize(int gasTankSize) { + this.gasTankSize = gasTankSize; + } + + public double getGasTankLevel() { + return gasTankLevel; + } + + public void setGasTankLevel(double gasTankLevel) { + this.gasTankLevel = gasTankLevel; + } + + public double getMilesPerGallon() { + return milesPerGallon; + } + + public void setMilesPerGallon(double milesPerGallon) { + this.milesPerGallon = milesPerGallon; + } + + public double getOdometer() { + return odometer; + } + + /** + * Drive the car an amount of miles. If not enough fuel, drive as far as fuel allows. + * Adjust fuel levels based on amount needed to drive the distance requested. + * Add miles to odometer. + * + * @param miles - the miles to drive + */ + public void drive(double miles) + { + //adjust fuel based on mpg and miles requested to drive + double maxDistance = this.milesPerGallon * this.gasTankLevel; + /**the double below uses some syntax called the ternary operator. + * if the value of miles is greater than the value of maxDistance, + * then milesAbleToTravel = maxDistance. + * otherwise, if miles is not greater than maxDistance, + * then milesAbleToTravel = miles + */ + double milesAbleToTravel = miles > maxDistance ? maxDistance : miles; + double gallonsUsed = milesAbleToTravel / this.milesPerGallon; + this.gasTankLevel = this.gasTankLevel - gallonsUsed; + this.odometer += milesAbleToTravel; + } + +} diff --git a/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Main.java b/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Main.java new file mode 100644 index 000000000..a98111f47 --- /dev/null +++ b/unit-testing/exercises/car-exercises/src/main/java/org/launchcode/Main.java @@ -0,0 +1,8 @@ +package org.launchcode; + +public class Main { + public static void main(String[] args) { + Car car = new Car("Toyota", "Prius", 10, 50); + System.out.println(car.getMake() + " - " + car.getModel()); + } +} \ No newline at end of file diff --git a/unit-testing/exercises/car-exercises/src/test/java/org/launchcode/CarTest.java b/unit-testing/exercises/car-exercises/src/test/java/org/launchcode/CarTest.java new file mode 100644 index 000000000..1a3f2a04a --- /dev/null +++ b/unit-testing/exercises/car-exercises/src/test/java/org/launchcode/CarTest.java @@ -0,0 +1,31 @@ +package org.launchcode; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class CarTest { + Car test_car; + + @BeforeEach + public void initCar() { + test_car = new Car("Toyota", "Prius", 10, 50); + } + + //TODO: add emptyTest so we can configure our runtime environment + @Test + public void emptyTest() { + assertEquals(10, 10, .001); + } + + //TODO: constructor sets gasTankLevel properly + @Test + public void testInitialGasTank() { + assertEquals( 10, test_car.getGasTankLevel(),.001); + } + + //TODO: gasTankLevel is accurate after driving within tank range + //TODO: gasTankLevel is accurate after attempting to drive past tank range + //TODO: can't have more gas than tank size, expect an exception +} \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/.gitignore b/unit-testing/studio/balanced-brackets/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/.idea/.gitignore b/unit-testing/studio/balanced-brackets/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/unit-testing/studio/balanced-brackets/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/unit-testing/studio/balanced-brackets/.idea/gradle.xml b/unit-testing/studio/balanced-brackets/.idea/gradle.xml new file mode 100644 index 000000000..5128e8731 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/.idea/misc.xml b/unit-testing/studio/balanced-brackets/.idea/misc.xml new file mode 100644 index 000000000..87a20fc38 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/.idea/uiDesigner.xml b/unit-testing/studio/balanced-brackets/.idea/uiDesigner.xml new file mode 100644 index 000000000..2b63946d5 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/.idea/vcs.xml b/unit-testing/studio/balanced-brackets/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/build.gradle.kts b/unit-testing/studio/balanced-brackets/build.gradle.kts new file mode 100644 index 000000000..ebe72c2da --- /dev/null +++ b/unit-testing/studio/balanced-brackets/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") +} + +group = "org.launchcode" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/gradle/wrapper/gradle-wrapper.jar b/unit-testing/studio/balanced-brackets/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/unit-testing/studio/balanced-brackets/gradle/wrapper/gradle-wrapper.jar differ diff --git a/unit-testing/studio/balanced-brackets/gradle/wrapper/gradle-wrapper.properties b/unit-testing/studio/balanced-brackets/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..79b23a65d --- /dev/null +++ b/unit-testing/studio/balanced-brackets/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Jun 29 15:20:13 CDT 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/unit-testing/studio/balanced-brackets/gradlew b/unit-testing/studio/balanced-brackets/gradlew new file mode 100755 index 000000000..1b6c78733 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/unit-testing/studio/balanced-brackets/gradlew.bat b/unit-testing/studio/balanced-brackets/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/unit-testing/studio/balanced-brackets/settings.gradle.kts b/unit-testing/studio/balanced-brackets/settings.gradle.kts new file mode 100644 index 000000000..d8cae6c64 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "balanced-brackets" + diff --git a/unit-testing/studio/balanced-brackets/src/main/java/org/launchcode/BalancedBrackets.java b/unit-testing/studio/balanced-brackets/src/main/java/org/launchcode/BalancedBrackets.java new file mode 100644 index 000000000..890783e59 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/src/main/java/org/launchcode/BalancedBrackets.java @@ -0,0 +1,33 @@ +package org.launchcode; +public class BalancedBrackets { + /* + * The function BalancedBrackets should return true if and only if + * the input string has a set of "balanced" brackets. + * + * That is, whether it consists entirely of pairs of opening/closing + * brackets (in that order), none of which mis-nest. We consider a bracket + * to be square-brackets: [ or ]. + * + * The string may contain non-bracket characters as well. + * + * These strings have balanced brackets: + * "[LaunchCode]", "Launch[Code]", "[]LaunchCode", "", "[]" + * + * While these do not: + * "[LaunchCode", "Launch]Code[", "[", "][" + * + * @param str - to be validated + * @return true if balanced, false otherwise + */ + public static boolean hasBalancedBrackets(String str) { + int brackets = 0; + for (char ch : str.toCharArray()) { + if (ch == '[') { + brackets++; + } else if (ch == ']') { + brackets--; + } + } + return brackets == 0; + } +} \ No newline at end of file diff --git a/unit-testing/studio/balanced-brackets/src/test/java/org/launchcode/BalancedBracketsTest.java b/unit-testing/studio/balanced-brackets/src/test/java/org/launchcode/BalancedBracketsTest.java new file mode 100644 index 000000000..a9d8821b3 --- /dev/null +++ b/unit-testing/studio/balanced-brackets/src/test/java/org/launchcode/BalancedBracketsTest.java @@ -0,0 +1,13 @@ +package org.launchcode; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BalancedBracketsTest { + //TODO: add tests here + @Test + public void emptyTest() { + assertEquals(true, true); + } +} \ No newline at end of file