diff --git a/class8-studio/.gitattributes b/class8-studio/.gitattributes new file mode 100644 index 000000000..8af972cde --- /dev/null +++ b/class8-studio/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/class8-studio/.gitignore b/class8-studio/.gitignore new file mode 100644 index 000000000..c2065bc26 --- /dev/null +++ b/class8-studio/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/class8-studio/build.gradle b/class8-studio/build.gradle new file mode 100644 index 000000000..1cbe3b97a --- /dev/null +++ b/class8-studio/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.5' + id 'io.spring.dependency-management' version '1.1.6' +} + +group = 'org.launchcode' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/class8-studio/gradle/wrapper/gradle-wrapper.jar b/class8-studio/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..a4b76b953 Binary files /dev/null and b/class8-studio/gradle/wrapper/gradle-wrapper.jar differ diff --git a/class8-studio/gradle/wrapper/gradle-wrapper.properties b/class8-studio/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..df97d72b8 --- /dev/null +++ b/class8-studio/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/class8-studio/gradlew b/class8-studio/gradlew new file mode 100644 index 000000000..f5feea6d6 --- /dev/null +++ b/class8-studio/gradlew @@ -0,0 +1,252 @@ +#!/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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# 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/platforms/jvm/plugins-application/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##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# 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 + if ! command -v java >/dev/null 2>&1 + then + 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 +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=SC2039,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=SC2039,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 + + +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +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/class8-studio/gradlew.bat b/class8-studio/gradlew.bat new file mode 100644 index 000000000..9d21a2183 --- /dev/null +++ b/class8-studio/gradlew.bat @@ -0,0 +1,94 @@ +@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 +@rem SPDX-License-Identifier: Apache-2.0 +@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. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +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/class8-studio/settings.gradle b/class8-studio/settings.gradle new file mode 100644 index 000000000..3ba208457 --- /dev/null +++ b/class8-studio/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'class8-studio' diff --git a/class8-studio/src/main/java/org/launchcode/class8_studio/Class8StudioApplication.java b/class8-studio/src/main/java/org/launchcode/class8_studio/Class8StudioApplication.java new file mode 100644 index 000000000..77a46699a --- /dev/null +++ b/class8-studio/src/main/java/org/launchcode/class8_studio/Class8StudioApplication.java @@ -0,0 +1,13 @@ +package org.launchcode.class8_studio; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Class8StudioApplication { + + public static void main(String[] args) { + SpringApplication.run(Class8StudioApplication.class, args); + } + +} diff --git a/class8-studio/src/main/java/org/launchcode/class8_studio/controllers/SkillsController.java b/class8-studio/src/main/java/org/launchcode/class8_studio/controllers/SkillsController.java new file mode 100644 index 000000000..d4e93dee3 --- /dev/null +++ b/class8-studio/src/main/java/org/launchcode/class8_studio/controllers/SkillsController.java @@ -0,0 +1,82 @@ +package org.launchcode.class8_studio.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +//studio +@Controller +@ResponseBody + +public class SkillsController { + @GetMapping("/") + public String displayHomePage() { + return "" + + "Skills Tracker" + + "

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

" + + "
    " + + "
  1. Java
  2. " + + "
  3. JavaScript
  4. " + + "
  5. TypeScript
  6. " + + "
  7. Python
  8. " + + "
  9. Ruby
  10. " + + "
" + + "

Click here to select your favorite.

" + + "" + + ""; + } + + @GetMapping("/form") + public String displaySkillsForm() { + return "" + + "" + + "
" + + "" + + "
" + + "" + + "
" + + "" + + "
" + + "" + + "
" + + "" + + "
" + + "" + + ""; + } + + @PostMapping("/form") + public String processSkillsForm(@RequestParam String userName, String fave1, String fave2, String fave3) { + return "" + + "" + + "

" + userName + "

" + + "

Favorite Languages" + + "
  • " + fave1 + "
  • " + + "
  • " + fave2 + "
  • " + + "
  • " + fave3 + "
  • " + + "" + + ""; + } + +} diff --git a/class8-studio/src/main/resources/application.properties b/class8-studio/src/main/resources/application.properties new file mode 100644 index 000000000..2e8bfd56f --- /dev/null +++ b/class8-studio/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=class8-studio diff --git a/class8-studio/src/test/java/org/launchcode/class8_studio/Class8StudioApplicationTests.java b/class8-studio/src/test/java/org/launchcode/class8_studio/Class8StudioApplicationTests.java new file mode 100644 index 000000000..2bc2f47ff --- /dev/null +++ b/class8-studio/src/test/java/org/launchcode/class8_studio/Class8StudioApplicationTests.java @@ -0,0 +1,13 @@ +package org.launchcode.class8_studio; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Class8StudioApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/classes-part-2/studio/src/main/java/org/launchcode/Menu.java b/classes-part-2/studio/src/main/java/org/launchcode/Menu.java index b4601316b..c70fde830 100644 --- a/classes-part-2/studio/src/main/java/org/launchcode/Menu.java +++ b/classes-part-2/studio/src/main/java/org/launchcode/Menu.java @@ -1,32 +1,52 @@ package org.launchcode; +import java.awt.*; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Date; +import java.util.List; -public class Menu { - private Date lastUpdated; - private ArrayList items; +public class Menu +{ - public Menu(Date d, ArrayList i) { - this.lastUpdated = d; - this.items = i; + private List menuItems = new ArrayList<>(); + private LocalDate lastUpdated; + + public Menu(List menuItems, LocalDate lastUpdated){ + this.menuItems = menuItems; + this.lastUpdated = lastUpdated; } - public void setLastUpdated(Date lastUpdated) { + public void setLastUpdated(LocalDate lastUpdated){ this.lastUpdated = lastUpdated; } - public void setItems(ArrayList items) { - this.items = items; + public LocalDate getLastUpdated(){ + return this.lastUpdated; } - public Date getLastUpdated() { - return lastUpdated; + public List getMenuItems(){ + return this.menuItems; } - public ArrayList getItems() { - return items; + public void addMenuItem(MenuItem menuItem){ + this.menuItems.add(menuItem); } -} + public void removeMenuItem(MenuItem menuItem) { + this.menuItems.remove(menuItem); + } + + @Override + public String toString(){ + String output = "Today's Menu \n"; + // Loop through each menu item + for(MenuItem item: this.menuItems){ + // Use the toString method on the MenuItem to add the item to the output + output += item + "\n"; + } + // Add the last updated + output += "Last updated: " + this.lastUpdated; + return output; + } +} diff --git a/classes-part-2/studio/src/main/java/org/launchcode/MenuItem.java b/classes-part-2/studio/src/main/java/org/launchcode/MenuItem.java index 22ba70e45..9cc1de60f 100644 --- a/classes-part-2/studio/src/main/java/org/launchcode/MenuItem.java +++ b/classes-part-2/studio/src/main/java/org/launchcode/MenuItem.java @@ -1,32 +1,86 @@ -package org.launchcode; +package org.example; + +import java.util.Objects; public class MenuItem { + + private String itemName; 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 MenuItem(String itemName, double price, String description, String category) { + this.itemName = itemName; + this.price = price; + this.description = description; + this.category = category; + this.isNew = true; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; } - public void setPrice(double price) { + public void setPrice(double price){ this.price = price; } - public void setDescription(String description) { + public void setDescription(String description){ this.description = description; } - public void setCategory(String category) { + public void setCategory(String category){ this.category = category; } - public void setNew(boolean aNew) { - isNew = aNew; + public void setIsNew(boolean isNew){ + this.isNew = isNew; + } + + public double getPrice(){ + return this.price; } -} + public String getDescription() { + return this.description; + } + + public String getCategory() { + return this.category; + } + + public boolean getIsNew(){ + return this.isNew; + } + + // To print out a menu item + @Override + public String toString(){ + return (this.isNew ? "NEW! - " : "") + + this.itemName + + " - " + + this.description + + " - " + + this.category + + " - $" + + this.price; + } + + @Override + public boolean equals(Object toBeCompared) { + if (this == toBeCompared) { + return true; + } + if (toBeCompared == null || this.getClass() != toBeCompared.getClass()) { + return false; + } + MenuItem item = (MenuItem) toBeCompared; + return this.itemName.equals(item.itemName); + } + +} diff --git a/classes-part-one/exercises/src/main/java/Course.java b/classes-part-one/exercises/src/main/java/Course.java new file mode 100644 index 000000000..8dddd36b6 --- /dev/null +++ b/classes-part-one/exercises/src/main/java/Course.java @@ -0,0 +1,29 @@ +import java.util.ArrayList; + +public class Course { + private String topic; + private Teacher instructor; + private ArrayList enrolledStudents; + + public Course(String topic, Teacher instructor) { + this.topic = topic; + this.instructor = instructor; + this.enrolledStudents = new ArrayList<>(); + } + + public String getTopic() { + return topic; + } + + public Teacher getInstructor() { + return instructor; + } + + public ArrayList getEnrolledStudents() { + return enrolledStudents; + } + + public void addStudent(Student student) { + enrolledStudents.add(student); + } +} diff --git a/classes-part-one/exercises/src/main/java/Student.java b/classes-part-one/exercises/src/main/java/Student.java index d06997866..4d7f01193 100644 --- a/classes-part-one/exercises/src/main/java/Student.java +++ b/classes-part-one/exercises/src/main/java/Student.java @@ -1,10 +1,51 @@ public class Student { private String name; private int studentId; - private int numberOfCredits = 0; - private double gpa = 0.0; + private int numberOfCredits; + private double gpa; - // Drop your getters and setters below for the Student class. - // To instantiate the Student class, add your code to the main in the file, SchoolPractice. + // Constructor + public Student(String name, int studentId, int numberOfCredits, double gpa) { + this.name = name; + this.studentId = studentId; + this.numberOfCredits = numberOfCredits; + this.gpa = gpa; + } + // Getters + public String getName() { + return name; + } + + public int getStudentId() { + return studentId; + } + + public int getNumberOfCredits() { // Ensure this method exists + return numberOfCredits; + } + + public double getGpa() { + return gpa; + } + + // Setters + public void setName(String name) { + this.name = name; + } + + public void setStudentId(int studentId) { + this.studentId = studentId; + } + + public void setGpa(double gpa) { + this.gpa = gpa; + } + + // Optional: Consider making this setter package-private if you want restricted access + private void setNumberOfCredits(int numberOfCredits) { + this.numberOfCredits = numberOfCredits; + } } + + diff --git a/classes-part-one/exercises/src/main/java/StudentPractice.java b/classes-part-one/exercises/src/main/java/StudentPractice.java index bb0c0eb7e..9316d818b 100644 --- a/classes-part-one/exercises/src/main/java/StudentPractice.java +++ b/classes-part-one/exercises/src/main/java/StudentPractice.java @@ -1,5 +1,9 @@ public class StudentPractice { - public static void main(String[] args){ - //insantiate your Student class below + public static void main(String[] args) { + Student student = new Student("Sara Bohannon", 12345, 1, 4.0); + System.out.println("Student Name: " + student.getName()); + System.out.println("Student ID: " + student.getStudentId()) + System.out.println("Credits: " + student.getNumberOfCredits()); + System.out.println("GPA: " + student.getGpa()); } -} +} \ No newline at end of file diff --git a/classes-part-one/exercises/src/main/java/Teacher.java b/classes-part-one/exercises/src/main/java/Teacher.java new file mode 100644 index 000000000..cad307a66 --- /dev/null +++ b/classes-part-one/exercises/src/main/java/Teacher.java @@ -0,0 +1,30 @@ +public class Teacher { + private String firstName; + private String lastName; + private String subject; + private int yearsTeaching; + + public Teacher(String firstName, String lastName, String subject, int yearsTeaching) { + this.firstName = firstName; + this.lastName = lastName; + this.subject = subject; + this.yearsTeaching = yearsTeaching; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public void setYearsTeaching(int yearsTeaching) { + this.yearsTeaching = yearsTeaching; + } + +} diff --git a/classes-part-one/exercises/untitled b/classes-part-one/exercises/untitled new file mode 160000 index 000000000..150d52496 --- /dev/null +++ b/classes-part-one/exercises/untitled @@ -0,0 +1 @@ +Subproject commit 150d524960a09f147f7649b83c061fc786d1f35f diff --git a/classes-part-one/exercises/untitled1 b/classes-part-one/exercises/untitled1 new file mode 160000 index 000000000..65ab09797 --- /dev/null +++ b/classes-part-one/exercises/untitled1 @@ -0,0 +1 @@ +Subproject commit 65ab09797d51cef8f68c87fcde56ff09fef2d29b diff --git a/classes-part-one/exercises/untitled2 b/classes-part-one/exercises/untitled2 new file mode 160000 index 000000000..13da732c7 --- /dev/null +++ b/classes-part-one/exercises/untitled2 @@ -0,0 +1 @@ +Subproject commit 13da732c7ea3ead2835a7e3975874ca7246dade8 diff --git a/codingevents/.gitattributes b/codingevents/.gitattributes new file mode 100644 index 000000000..8af972cde --- /dev/null +++ b/codingevents/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/codingevents/.gitignore b/codingevents/.gitignore new file mode 100644 index 000000000..c2065bc26 --- /dev/null +++ b/codingevents/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/codingevents/CodingEventsJava b/codingevents/CodingEventsJava new file mode 160000 index 000000000..8219deae7 --- /dev/null +++ b/codingevents/CodingEventsJava @@ -0,0 +1 @@ +Subproject commit 8219deae727855fb6df918a05718c6e808bc82fa diff --git a/codingevents/Java17-SpaDay b/codingevents/Java17-SpaDay new file mode 160000 index 000000000..dfc573c49 --- /dev/null +++ b/codingevents/Java17-SpaDay @@ -0,0 +1 @@ +Subproject commit dfc573c499889bdbb963bc0c7889711f29405869 diff --git a/codingevents/build.gradle b/codingevents/build.gradle new file mode 100644 index 000000000..17ea650f9 --- /dev/null +++ b/codingevents/build.gradle @@ -0,0 +1,31 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.4.0' + id 'io.spring.dependency-management' version '1.1.6' +} + +group = 'org.launchcode' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-web' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/codingevents/gradle/wrapper/gradle-wrapper.jar b/codingevents/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..a4b76b953 Binary files /dev/null and b/codingevents/gradle/wrapper/gradle-wrapper.jar differ diff --git a/codingevents/gradle/wrapper/gradle-wrapper.properties b/codingevents/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..e2847c820 --- /dev/null +++ b/codingevents/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/codingevents/gradlew b/codingevents/gradlew new file mode 100644 index 000000000..f5feea6d6 --- /dev/null +++ b/codingevents/gradlew @@ -0,0 +1,252 @@ +#!/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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# 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/platforms/jvm/plugins-application/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##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# 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 + if ! command -v java >/dev/null 2>&1 + then + 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 +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=SC2039,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=SC2039,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 + + +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +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/codingevents/gradlew.bat b/codingevents/gradlew.bat new file mode 100644 index 000000000..9d21a2183 --- /dev/null +++ b/codingevents/gradlew.bat @@ -0,0 +1,94 @@ +@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 +@rem SPDX-License-Identifier: Apache-2.0 +@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. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +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/codingevents/settings.gradle b/codingevents/settings.gradle new file mode 100644 index 000000000..71d3279e8 --- /dev/null +++ b/codingevents/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'codingevents' diff --git a/codingevents/src/main/java/org/launchcode/codingevents/CodingeventsApplication.java b/codingevents/src/main/java/org/launchcode/codingevents/CodingeventsApplication.java new file mode 100644 index 000000000..d4ce2b933 --- /dev/null +++ b/codingevents/src/main/java/org/launchcode/codingevents/CodingeventsApplication.java @@ -0,0 +1,13 @@ +package org.launchcode.codingevents; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CodingeventsApplication { + + public static void main(String[] args) { + SpringApplication.run(CodingeventsApplication.class, args); + } + +} diff --git a/codingevents/src/main/java/org/launchcode/codingevents/controllers/EventController.java b/codingevents/src/main/java/org/launchcode/codingevents/controllers/EventController.java new file mode 100644 index 000000000..c8a5ed49d --- /dev/null +++ b/codingevents/src/main/java/org/launchcode/codingevents/controllers/EventController.java @@ -0,0 +1,64 @@ +package org.launchcode.codingevents.controllers; + +import jakarta.validation.Valid; +import org.launchcode.codingevents.data.EventData; +import org.launchcode.codingevents.models.Event; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +@Controller +@RequestMapping("events") +public class EventController { + + + @GetMapping + public String displayAllEvents(Model model) { + model.addAttribute("title", "All Events"); + model.addAttribute("events", EventData.getAll()); + return "events/index"; + } + + @GetMapping("create") + public String displayCreateEventForm(Model model) { + model.addAttribute("title", "Create Event"); + model.addAttribute(new Event()); + return "events/create"; + } + + @PostMapping("create") + public String processCreateEventForm(@ModelAttribute @Valid Event newEvent, + Errors errors, Model model) { + if(errors.hasErrors()) { + model.addAttribute("title", "Create Event"); + return "events/create"; + } + + + EventData.add(newEvent); + return "redirect:/events"; + } + + @GetMapping("delete") + public String displayDeleteEventForm(Model model) { + model.addAttribute("title", "Delete Event"); + model.addAttribute("events", EventData.getAll()); + return "events/delete"; + } + + @PostMapping("delete") + public String processDeleteEventsForm(@RequestParam(required = false) int[] eventIds) { + + if (eventIds != null) { + for (int id : eventIds) { + EventData.remove(id); + } + } + + return "redirect:/events"; + } +} \ No newline at end of file diff --git a/codingevents/src/main/java/org/launchcode/codingevents/controllers/HomeController.java b/codingevents/src/main/java/org/launchcode/codingevents/controllers/HomeController.java new file mode 100644 index 000000000..1e7f13532 --- /dev/null +++ b/codingevents/src/main/java/org/launchcode/codingevents/controllers/HomeController.java @@ -0,0 +1,15 @@ +package org.launchcode.codingevents.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller + +public class HomeController { + + @GetMapping + public String index() { + return "index"; + } + +} diff --git a/codingevents/src/main/java/org/launchcode/codingevents/data/EventData.java b/codingevents/src/main/java/org/launchcode/codingevents/data/EventData.java new file mode 100644 index 000000000..e888bed26 --- /dev/null +++ b/codingevents/src/main/java/org/launchcode/codingevents/data/EventData.java @@ -0,0 +1,29 @@ +package org.launchcode.codingevents.data; + +import org.launchcode.codingevents.models.Event; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class EventData { + + private static final Map events = new HashMap<>(); + + public static Collection getAll() { + return events.values(); + } + + public static Event getById(int id) { + return events.get(id); + } + + public static void add(Event event) { + events.put(event.getId(), event); + } + + public static void remove (int id) { + events.remove(id); + } + +} diff --git a/codingevents/src/main/java/org/launchcode/codingevents/models/Event.java b/codingevents/src/main/java/org/launchcode/codingevents/models/Event.java new file mode 100644 index 000000000..bc332d6f0 --- /dev/null +++ b/codingevents/src/main/java/org/launchcode/codingevents/models/Event.java @@ -0,0 +1,80 @@ +package org.launchcode.codingevents.models; + +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +import java.util.Objects; + +public class Event { + + private int id; + private static int nextId = 1; + + @NotBlank(message = "Name is required.") + @Size(min = 3, max = 50, message = "Name must be between 3 and 50 characters." ) + private String name; + + @Size(max = 500, message = "Description too long!") + private String description; + + @NotBlank(message = "Email is required") + @Email(message = "Invalid email, Try again.") + private String contactEmail; + + public Event(String name, String description, String contactEmail) { + this.name = name; + this.description = description; + this.contactEmail = contactEmail; + this.id = nextId; + nextId++; + } + + public Event() {} + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public @Email String getContactEmail() { + return contactEmail; + } + + public void setContactEmail(@Email String contactEmail) { + this.contactEmail = contactEmail; + } + + public int getId() { + return id; + } + + @Override + public String toString() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Event event = (Event) o; + return id == event.id; + } + + @Override + public int hashCode() { + return Objects.hash(id); + } +} \ No newline at end of file diff --git a/codingevents/src/main/resources/application.properties b/codingevents/src/main/resources/application.properties new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/codingevents/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/codingevents/src/main/resources/static/script.js b/codingevents/src/main/resources/static/script.js new file mode 100644 index 000000000..b6d1b3451 --- /dev/null +++ b/codingevents/src/main/resources/static/script.js @@ -0,0 +1 @@ +let appName = "Coding Events"; \ No newline at end of file diff --git a/codingevents/src/main/resources/static/styles.css b/codingevents/src/main/resources/static/styles.css new file mode 100644 index 000000000..a18d0a165 --- /dev/null +++ b/codingevents/src/main/resources/static/styles.css @@ -0,0 +1,6 @@ +body { + font-size: 14px; +} +.error { +color: red; +} \ No newline at end of file diff --git a/codingevents/src/main/resources/templates/events/create.html b/codingevents/src/main/resources/templates/events/create.html new file mode 100644 index 000000000..91182d597 --- /dev/null +++ b/codingevents/src/main/resources/templates/events/create.html @@ -0,0 +1,34 @@ + + + + + +
    + + +
    +
    + +

    +
    +
    + +
    +
    + +

    +
    +
    + +
    +
    + + + \ No newline at end of file diff --git a/codingevents/src/main/resources/templates/events/delete.html b/codingevents/src/main/resources/templates/events/delete.html new file mode 100644 index 000000000..e3353f907 --- /dev/null +++ b/codingevents/src/main/resources/templates/events/delete.html @@ -0,0 +1,23 @@ + + + + + +
    + +
    + + +
    + +
    +
    + + +
    + + + \ No newline at end of file diff --git a/codingevents/src/main/resources/templates/events/index.html b/codingevents/src/main/resources/templates/events/index.html new file mode 100644 index 000000000..af2e9071d --- /dev/null +++ b/codingevents/src/main/resources/templates/events/index.html @@ -0,0 +1,26 @@ + + + + + +
    + + + + + + + + + + + + + + + + +
    IDNameDescriptionContact Email
    + + + \ No newline at end of file diff --git a/codingevents/src/main/resources/templates/fragments.html b/codingevents/src/main/resources/templates/fragments.html new file mode 100644 index 000000000..204230b96 --- /dev/null +++ b/codingevents/src/main/resources/templates/fragments.html @@ -0,0 +1,21 @@ + + + + + Coding Events + + + + + + + + + \ No newline at end of file diff --git a/codingevents/src/main/resources/templates/index.html b/codingevents/src/main/resources/templates/index.html new file mode 100644 index 000000000..8315be5dc --- /dev/null +++ b/codingevents/src/main/resources/templates/index.html @@ -0,0 +1,11 @@ + + + + + +

    Coding Events

    + +
    + + + \ No newline at end of file diff --git a/codingevents/src/test/java/org/launchcode/codingevents/CodingeventsApplicationTests.java b/codingevents/src/test/java/org/launchcode/codingevents/CodingeventsApplicationTests.java new file mode 100644 index 000000000..7f683b024 --- /dev/null +++ b/codingevents/src/test/java/org/launchcode/codingevents/CodingeventsApplicationTests.java @@ -0,0 +1,13 @@ +package org.launchcode.codingevents; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class CodingeventsApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/codingevents/untitled b/codingevents/untitled new file mode 160000 index 000000000..bd1662c6b --- /dev/null +++ b/codingevents/untitled @@ -0,0 +1 @@ +Subproject commit bd1662c6be26b8130ca4454b954883c32419a375 diff --git a/control-flow-and-collections/Studio b/control-flow-and-collections/Studio new file mode 160000 index 000000000..58c19efc9 --- /dev/null +++ b/control-flow-and-collections/Studio @@ -0,0 +1 @@ +Subproject commit 58c19efc9a710969088913181b849bc6d3f7cfcf 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 index 2cc722bbc..8768bc78c 100644 --- 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 @@ -43,7 +43,7 @@ public String helloPost(@RequestParam String name, @RequestParam String language name = "World"; } - return createMessage(name, language); + 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. diff --git a/datatypes/datatypes-exercises/src/main/java/launchcode/Area.java b/datatypes/datatypes-exercises/src/main/java/launchcode/Area.java new file mode 100644 index 000000000..2f9e44da7 --- /dev/null +++ b/datatypes/datatypes-exercises/src/main/java/launchcode/Area.java @@ -0,0 +1,22 @@ +package launchcode; + +import java.util.Scanner; + +public class Area { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Enter the length of the rectangle: "); + double length = scanner.nextDouble(); + + System.out.print("Enter the width of the rectangle: "); + double width = scanner.nextDouble(); + + double area = length * width; + + System.out.println("The area of the rectangle is: " + area); + + scanner.close(); + } +} + diff --git a/datatypes/datatypes-exercises/src/main/java/launchcode/Hello.java b/datatypes/datatypes-exercises/src/main/java/launchcode/Hello.java new file mode 100644 index 000000000..1d75d3c37 --- /dev/null +++ b/datatypes/datatypes-exercises/src/main/java/launchcode/Hello.java @@ -0,0 +1,13 @@ +package launchcode; + +import java.util.Scanner; + +public class Hello { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.println("Hello, what is your name:"); + + String name = input.nextLine(); + System.out.println("Hello " + name); + } +} \ No newline at end of file diff --git a/datatypes/datatypes-exercises/src/main/java/launchcode/MilesPerGallon.java b/datatypes/datatypes-exercises/src/main/java/launchcode/MilesPerGallon.java new file mode 100644 index 000000000..245bbdc02 --- /dev/null +++ b/datatypes/datatypes-exercises/src/main/java/launchcode/MilesPerGallon.java @@ -0,0 +1,18 @@ +package launchcode; + +import java.util.Scanner; + +public class MilesPerGallon { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + + System.out.println("How many miles have you driven?"); + Double numMiles = input.nextDouble(); + + System.out.println("How much gas did you use? In gallons."); + Double numGallons = input.nextDouble(); + + Double mpg = numMiles / numGallons; + System.out.println("You are running on " + mpg + " mpg."); + } +} diff --git a/hello-spring/.gitattributes b/hello-spring/.gitattributes new file mode 100644 index 000000000..8af972cde --- /dev/null +++ b/hello-spring/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/hello-spring/.gitignore b/hello-spring/.gitignore new file mode 100644 index 000000000..c2065bc26 --- /dev/null +++ b/hello-spring/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/hello-spring/build.gradle b/hello-spring/build.gradle new file mode 100644 index 000000000..1d3bbeed0 --- /dev/null +++ b/hello-spring/build.gradle @@ -0,0 +1,30 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.5' + id 'io.spring.dependency-management' version '1.1.6' +} + +group = 'org.launchcode' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/hello-spring/gradle/wrapper/gradle-wrapper.jar b/hello-spring/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..a4b76b953 Binary files /dev/null and b/hello-spring/gradle/wrapper/gradle-wrapper.jar differ diff --git a/hello-spring/gradle/wrapper/gradle-wrapper.properties b/hello-spring/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..df97d72b8 --- /dev/null +++ b/hello-spring/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/hello-spring/gradlew b/hello-spring/gradlew new file mode 100644 index 000000000..f5feea6d6 --- /dev/null +++ b/hello-spring/gradlew @@ -0,0 +1,252 @@ +#!/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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# 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/platforms/jvm/plugins-application/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##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# 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 + if ! command -v java >/dev/null 2>&1 + then + 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 +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=SC2039,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=SC2039,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 + + +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +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/hello-spring/gradlew.bat b/hello-spring/gradlew.bat new file mode 100644 index 000000000..9d21a2183 --- /dev/null +++ b/hello-spring/gradlew.bat @@ -0,0 +1,94 @@ +@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 +@rem SPDX-License-Identifier: Apache-2.0 +@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. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +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/hello-spring/settings.gradle b/hello-spring/settings.gradle new file mode 100644 index 000000000..69a39da7e --- /dev/null +++ b/hello-spring/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'hello-spring' diff --git a/hello-spring/src/main/java/org/launchcode/hello_spring/HelloSpringApplication.java b/hello-spring/src/main/java/org/launchcode/hello_spring/HelloSpringApplication.java new file mode 100644 index 000000000..9b2c24bf1 --- /dev/null +++ b/hello-spring/src/main/java/org/launchcode/hello_spring/HelloSpringApplication.java @@ -0,0 +1,13 @@ +package org.launchcode.hello_spring; + +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/hello-spring/src/main/java/org/launchcode/hello_spring/controllers/HelloController.java b/hello-spring/src/main/java/org/launchcode/hello_spring/controllers/HelloController.java new file mode 100644 index 000000000..f37a943de --- /dev/null +++ b/hello-spring/src/main/java/org/launchcode/hello_spring/controllers/HelloController.java @@ -0,0 +1,55 @@ +package org.launchcode.hello_spring.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Chris Bay + */ +@Controller +public class HelloController { + + @GetMapping("goodbye") + @ResponseBody + public String goodbye() { + return "Goodbye, Spring!"; + } + + // Handles requests of the form /hello?name=LaunchCode + @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "hello") + public String helloWithQueryParam(@RequestParam String name, Model model) { + String greeting = "Hello, " + name + "!"; + model.addAttribute("greeting", greeting); + return "hello"; + } + + // Handles requests of the form /hello/LaunchCode + @GetMapping("hello/{name}") + public String helloWithPathParam(@PathVariable String name, Model model) { + model.addAttribute("greeting", "Hello, " + name + "!"); + return "hello"; + } + + // /hello/form + @GetMapping("form") + public String helloForm() { + return "form"; + } + @GetMapping("hello-names") + public String helloNames(Model model) { + List names = new ArrayList<>(); + names.add("LaunchCode"); + names.add("Java"); + names.add("JavaScript"); + model.addAttribute("names", names); + return "hello-list"; + } +} + + + + diff --git a/hello-spring/src/main/resources/application.properties b/hello-spring/src/main/resources/application.properties new file mode 100644 index 000000000..839dc0a97 --- /dev/null +++ b/hello-spring/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=hello-spring diff --git a/hello-spring/src/main/resources/templates/form.html b/hello-spring/src/main/resources/templates/form.html new file mode 100644 index 000000000..fa816cf55 --- /dev/null +++ b/hello-spring/src/main/resources/templates/form.html @@ -0,0 +1,14 @@ + + + + + + + + +
    + + + +
    + + \ No newline at end of file diff --git a/hello-spring/src/main/resources/templates/hello-list.html b/hello-spring/src/main/resources/templates/hello-list.html new file mode 100644 index 000000000..22cc5cdd2 --- /dev/null +++ b/hello-spring/src/main/resources/templates/hello-list.html @@ -0,0 +1,16 @@ + + + + + + + + +
      + +
    • +
      +
    + + + \ No newline at end of file diff --git a/hello-spring/src/main/resources/templates/hello.html b/hello-spring/src/main/resources/templates/hello.html new file mode 100644 index 000000000..553502e85 --- /dev/null +++ b/hello-spring/src/main/resources/templates/hello.html @@ -0,0 +1,10 @@ + + + + + + + +

    Hello, Spring!

    + + \ No newline at end of file diff --git a/hello-spring/src/test/java/org/launchcode/hello_spring/HelloSpringApplicationTests.java b/hello-spring/src/test/java/org/launchcode/hello_spring/HelloSpringApplicationTests.java new file mode 100644 index 000000000..e95f58dc4 --- /dev/null +++ b/hello-spring/src/test/java/org/launchcode/hello_spring/HelloSpringApplicationTests.java @@ -0,0 +1,13 @@ +package org.launchcode.hello_spring; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class HelloSpringApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/inheritance/Studio/.gitignore b/inheritance/Studio/.gitignore new file mode 100644 index 000000000..b63da4551 --- /dev/null +++ b/inheritance/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/inheritance/Studio/build.gradle.kts b/inheritance/Studio/build.gradle.kts new file mode 100644 index 000000000..18561f2b0 --- /dev/null +++ b/inheritance/Studio/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.10.0")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/inheritance/Studio/gradle/wrapper/gradle-wrapper.jar b/inheritance/Studio/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/inheritance/Studio/gradle/wrapper/gradle-wrapper.jar differ diff --git a/inheritance/Studio/gradle/wrapper/gradle-wrapper.properties b/inheritance/Studio/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..7f5ce3694 --- /dev/null +++ b/inheritance/Studio/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Oct 28 13:40:27 CDT 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/inheritance/Studio/gradlew b/inheritance/Studio/gradlew new file mode 100644 index 000000000..1b6c78733 --- /dev/null +++ b/inheritance/Studio/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/inheritance/Studio/gradlew.bat b/inheritance/Studio/gradlew.bat new file mode 100644 index 000000000..107acd32c --- /dev/null +++ b/inheritance/Studio/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/inheritance/Studio/main/java/org/launchcode/Checkbox.java b/inheritance/Studio/main/java/org/launchcode/Checkbox.java new file mode 100644 index 000000000..50be1bfb8 --- /dev/null +++ b/inheritance/Studio/main/java/org/launchcode/Checkbox.java @@ -0,0 +1,53 @@ +package org.launchcode; +import java.util.Scanner; +import java.util.ArrayList; + +public class Checkbox extends Question{ + + private ArrayList possibleAnswers; + private ArrayList correctAnswers; + + public Checkbox(int pointValue, String text, ArrayList possibleAnswers, ArrayList correctAnswers) { + super(pointValue, text); + this.possibleAnswers = possibleAnswers; + this.correctAnswers = correctAnswers; + setPointValue(this.correctAnswers.size()); + } + + @Override + public void displayAnswers() { + for (int i = 0; i < possibleAnswers.size(); i++) { + System.out.println(possibleAnswers.get(i)); + } + } + + public int checkAnswers(ArrayList check) { + int answersCorrect = 0; + for (int i = 0; i < check.size(); i++) { + if (correctAnswers.contains(check.get(i))) { + answersCorrect++; + } + } + return answersCorrect; + } + + @Override + public int getAnswers() { + ArrayList usersAnswers = new ArrayList<>(); + System.out.println("For this question, there are multiple correct answers. To begin answering the question, enter 'y'."); + Scanner userContinue = new Scanner(System.in); + String goingToContinue = userContinue.nextLine(); + while (goingToContinue.indexOf('y') >= 0 && usersAnswers.size() <= possibleAnswers.size()) { + System.out.println("What will your answer be? Enter the number of the option you believe is correct. For example, to select the first option, enter 1"); + Scanner userAnswer = new Scanner(System.in); + String answer = userAnswer.nextLine(); + int option = Integer.parseInt(answer); + usersAnswers.add(option); + + System.out.println("For this question, there are multiple correct answers. To continue answering the question, enter ''y. To stop, enter 'n'"); + goingToContinue = userContinue.nextLine(); + } + + return checkAnswers(usersAnswers); + } +} \ No newline at end of file diff --git a/inheritance/Studio/main/java/org/launchcode/MultipleChoice.java b/inheritance/Studio/main/java/org/launchcode/MultipleChoice.java new file mode 100644 index 000000000..7e5464d8d --- /dev/null +++ b/inheritance/Studio/main/java/org/launchcode/MultipleChoice.java @@ -0,0 +1,48 @@ +package org.launchcode; + +import java.util.ArrayList; +import java.util.Scanner; + +public class MultipleChoice extends Question { + + private ArrayList possibleAnswers; + private int correctAnswer; + + public MultipleChoice(int pointValue, String text, int correctAnswer, ArrayList possibleAnswers) { + super(pointValue, text); + this.correctAnswer = correctAnswer; + this.possibleAnswers = possibleAnswers; + setPointValue(1); + } + + @Override + public void displayAnswers () { + for (int i = 0; i < possibleAnswers.size(); i++) { + System.out.println(possibleAnswers.get(i)); + } + } + + public boolean isCorrectAnswer (int possibleAnswer) { + if (possibleAnswer == correctAnswer) { + return true; + } + else { + return false; + } + } + + @Override + public int getAnswers() { + Scanner answer = new Scanner(System.in); + System.out.println("What will your answer be? Enter the number of the option you believe is correct. For example, to select the first option, enter 1"); + String userAnswer = answer.nextLine(); + int result = Integer.parseInt(userAnswer); + if (isCorrectAnswer(result)) { + return 1; + } + else { + return 0; + } + } + +} \ No newline at end of file diff --git a/inheritance/Studio/main/java/org/launchcode/Question.java b/inheritance/Studio/main/java/org/launchcode/Question.java new file mode 100644 index 000000000..8b1602c5d --- /dev/null +++ b/inheritance/Studio/main/java/org/launchcode/Question.java @@ -0,0 +1,22 @@ +package org.launchcode; +import java.util.Scanner; + +public abstract class Question { + private int pointValue; + private String text; + + public Question(int pointValue, String text) { + this.pointValue = pointValue; + this.text = text; + } + + public void displayQuestion () {System.out.println(text); } + + public void setPointValue(int x) {this.pointValue = x; } + + public int getPointValue() {return this.pointValue; } + + public abstract void displayAnswers (); + + public abstract int getAnswers(); + } \ No newline at end of file diff --git a/inheritance/Studio/main/java/org/launchcode/Quiz.java b/inheritance/Studio/main/java/org/launchcode/Quiz.java new file mode 100644 index 000000000..0ff705d7a --- /dev/null +++ b/inheritance/Studio/main/java/org/launchcode/Quiz.java @@ -0,0 +1,42 @@ +package org.launchcode; + +import java.util.ArrayList; + +public class Quiz { + + private ArrayList questions; + private int score; + private int total; + + public Quiz(ArrayList questions) { + this.questions = questions; + this.score = 0; + this.total = 0; + for (int i = 0; i < questions.size(); i ++) { + this.total = this.total + questions.get(i).getPointValue(); + } + } + + public void addQuestion (Question newQuestion) { + this.questions.add(newQuestion); + this.total = this.total + newQuestion.getPointValue(); + } + + public void runQuiz () { + for (int i = 0; i < questions.size(); i ++) { + questions.get(i).displayQuestion(); + questions.get(i).displayAnswers(); + int pts = questions.get(i).getAnswers(); + updateScore(pts); + } + } + + public void updateScore (int x) { + this.score = this.score + x; + } + + public void gradeQuiz () { + System.out.println("You finished the quiz! Your score is: " + score + "/" + total); + } + +} \ No newline at end of file diff --git a/inheritance/Studio/main/java/org/launchcode/QuizRunner.java b/inheritance/Studio/main/java/org/launchcode/QuizRunner.java new file mode 100644 index 000000000..25691d8d8 --- /dev/null +++ b/inheritance/Studio/main/java/org/launchcode/QuizRunner.java @@ -0,0 +1,24 @@ +package org.launchcode; + +import java.util.ArrayList; +import java.util.Arrays; + +public class QuizRunner { + + public static void main(String[] args) { + Quiz myQuiz = new Quiz(new ArrayList<>()); + ArrayList possAns1 = new ArrayList<>(Arrays.asList("Garfield", "Salem", "Cheshire", "Tom")); + ArrayList correctAns1 = new ArrayList<>(Arrays.asList(2,3)); + Checkbox newQuestion1 = new Checkbox(2, "Who is the best cat in the world?", possAns1, correctAns1); + myQuiz.addQuestion(newQuestion1); + ArrayList possAns2 = new ArrayList<>(Arrays.asList("Doc", "Tillie", "Gizmo", "Benji", "Nala")); + MultipleChoice newQuestion2 = new MultipleChoice(1, "Who won the Halloween Costume Contest?", 3, possAns2); + myQuiz.addQuestion(newQuestion2); + TrueOrFalse newQuestion3 = new TrueOrFalse(1, "Are all dogs the best?", true); + myQuiz.addQuestion(newQuestion3); + + myQuiz.runQuiz(); + + myQuiz.gradeQuiz(); + } +} \ No newline at end of file diff --git a/inheritance/Studio/main/java/org/launchcode/TrueOrFalse.java b/inheritance/Studio/main/java/org/launchcode/TrueOrFalse.java new file mode 100644 index 000000000..81110c903 --- /dev/null +++ b/inheritance/Studio/main/java/org/launchcode/TrueOrFalse.java @@ -0,0 +1,47 @@ +package org.launchcode; + +import java.util.Scanner; + +public class TrueOrFalse extends Question { + + private boolean correctAnswer; + + public TrueOrFalse(int pointValue, String text, boolean correctAnswer) { + super(pointValue, text); + this.correctAnswer = correctAnswer; + } + + public boolean isCorrectAnswer(boolean possibleAnswer) { + if (possibleAnswer == correctAnswer) { + return true; + } else { + return false; + } + } + + @Override + public void displayAnswers() { + System.out.println("True or False:"); + } + + @Override + public int getAnswers() { + Scanner answer = new Scanner(System.in); + System.out.println("What will your answer be? Type 't' for True and 'f' for False"); + String userAnswer = answer.nextLine(); + if (userAnswer.indexOf('t') >= 0) { + if (isCorrectAnswer(true)) { + return 1; + } else { + return 0; + } + } else { + if (isCorrectAnswer(false)) { + return 1; + } else { + return 0; + } + } + } +} + diff --git a/inheritance/Studio/settings.gradle.kts b/inheritance/Studio/settings.gradle.kts new file mode 100644 index 000000000..787b8c0b1 --- /dev/null +++ b/inheritance/Studio/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "Studio" + diff --git a/inheritance/testing-inheritance/exercises/settings.gradle b/inheritance/testing-inheritance/exercises/settings.gradle index ee3830ab5..f067a5fc3 100644 --- a/inheritance/testing-inheritance/exercises/settings.gradle +++ b/inheritance/testing-inheritance/exercises/settings.gradle @@ -1,2 +1,4 @@ rootProject.name = 'tale-of-two-cats' +include 'technology' +include 'technology' diff --git a/inheritance/testing-inheritance/exercises/src/main/java/Cat.java b/inheritance/testing-inheritance/exercises/src/main/java/Cat.java index 8d4575957..a30478eae 100644 --- a/inheritance/testing-inheritance/exercises/src/main/java/Cat.java +++ b/inheritance/testing-inheritance/exercises/src/main/java/Cat.java @@ -10,6 +10,9 @@ public class Cat { public Cat (double aWeight) { weight = aWeight; } + public Cat() { + weight = 13; + } /**** Getters and Setters ****/ @@ -49,6 +52,14 @@ public void sleep() { hungry = true; } + public String purr() { + if (hungry) { + return "Purrrrrrrr!"; + } else { + return "I'm not hungry!"; + } + } + // Eating makes a cat not hungry public void eat() { diff --git a/inheritance/testing-inheritance/exercises/src/main/java/HouseCat.java b/inheritance/testing-inheritance/exercises/src/main/java/HouseCat.java index 25db60ab4..95905f58c 100644 --- a/inheritance/testing-inheritance/exercises/src/main/java/HouseCat.java +++ b/inheritance/testing-inheritance/exercises/src/main/java/HouseCat.java @@ -6,6 +6,9 @@ public HouseCat(String aName, double aWeight) { super(aWeight); name = aName; } + public HouseCat(String aName) { + name = aName; + } public boolean isSatisfied() { return !isHungry() && !isTired(); @@ -19,4 +22,4 @@ public String noise() { public String purr() { return "I'm a HouseCat"; } -} \ No newline at end of file +} diff --git a/inheritance/testing-inheritance/exercises/src/main/java/Main.java b/inheritance/testing-inheritance/exercises/src/main/java/Main.java new file mode 100644 index 000000000..148b94105 --- /dev/null +++ b/inheritance/testing-inheritance/exercises/src/main/java/Main.java @@ -0,0 +1,8 @@ +public class Main { + public static void main(String[] args) { + HouseCat garfield = new HouseCat("Garfield", 10.0); + garfield.eat(); + System.out.println(garfield.isTired()); + } + HouseCat spike = new HouseCat("Spike", 10.0); +} \ No newline at end of file diff --git a/inheritance/testing-inheritance/exercises/technology/build.gradle.kts b/inheritance/testing-inheritance/exercises/technology/build.gradle.kts new file mode 100644 index 000000000..18561f2b0 --- /dev/null +++ b/inheritance/testing-inheritance/exercises/technology/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.10.0")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Computer.java b/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Computer.java new file mode 100644 index 000000000..08dde9f54 --- /dev/null +++ b/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Computer.java @@ -0,0 +1,24 @@ +package org.launchcode; + +public class Computer { + private String brand; + private String model; + private boolean needsCharge; + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public Computer(String brand, String model, boolean needsCharge) { + super(); + this.brand = brand; + this.model = model; + this.needsCharge = needsCharge; + + } +} + diff --git a/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Laptop.java b/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Laptop.java new file mode 100644 index 000000000..4d4fcfdd6 --- /dev/null +++ b/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Laptop.java @@ -0,0 +1,16 @@ +package org.launchcode; + +public class Laptop extends Computer { + private boolean hasTouchScreen; + + public Laptop(String brand, String model, boolean needsCharge, boolean hasTouchScreen) { + super(brand, model, needsCharge); + this.hasTouchScreen = hasTouchScreen; + } + + public void openLid() { + System.out.println("Opening laptop lid."); + } + + // Getters and other methods can be added here +} \ No newline at end of file diff --git a/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Main.java b/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Main.java new file mode 100644 index 000000000..bc1c7a38c --- /dev/null +++ b/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/Main.java @@ -0,0 +1,13 @@ +package org.launchcode; + +public class Main { + public static void main(String[] args) { + technology.Laptop myLaptop = new Laptop("Dell", "XPS 13", true, true); + myLaptop.powerOn(); + myLaptop.openLid(); + + SmartPhone myPhone = new SmartPhone("Apple", "iPhone 13", false, true); + myPhone.powerOn(); + myPhone.makeCall("123-456-7890"); + } +} \ No newline at end of file diff --git a/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/SmartPhone.java b/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/SmartPhone.java new file mode 100644 index 000000000..bc904692f --- /dev/null +++ b/inheritance/testing-inheritance/exercises/technology/src/main/java/org/launchcode/SmartPhone.java @@ -0,0 +1,16 @@ +package org.launchcode; + +public class SmartPhone extends Computer { + private boolean has5G; + + public SmartPhone(String brand, String model, boolean needsCharge, boolean has5G) { + super(brand, model, needsCharge); + this.has5G = has5G; + } + + public void makeCall(String number) { + System.out.println("Calling " + number + " from smartphone."); + } + + // Getters and other methods can be added here +} \ No newline at end of file diff --git a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/ConeComparator.java b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/ConeComparator.java new file mode 100644 index 000000000..790b066db --- /dev/null +++ b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/ConeComparator.java @@ -0,0 +1,22 @@ +package org.launchcode; + +import java.util.Comparator; + + +import java.util.Comparator; + +public class ConeComparator implements Comparator { + @Override + public int compare(Cone cone1, Cone cone2) { + double cost1 = cone1.getCost(); + double cost2 = cone2.getCost(); + + if (cost1 < cost2) { + return -1; + } else if (cost1 > cost2) { + return 1; + } else { + return 0; + } + } +} \ No newline at end of file diff --git a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/FlavorComparator.java b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/FlavorComparator.java new file mode 100644 index 000000000..240b03f9f --- /dev/null +++ b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/FlavorComparator.java @@ -0,0 +1,10 @@ +package org.launchcode; + +import java.util.Comparator; + +public class FlavorComparator implements Comparator { + @Override + public int compare(Flavor flavor1, Flavor flavor2) { + return flavor1.getName().compareTo(flavor2.getName()); + } +} diff --git a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Main.java b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Main.java index 8787f2454..606b392ec 100644 --- a/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Main.java +++ b/interfaces/exercises/ice-cream-exercises/src/main/java/org/launchcode/Main.java @@ -1,6 +1,7 @@ package org.launchcode; import java.util.ArrayList; +import java.util.Comparator; public class Main { public static void main(String[] args) { @@ -8,10 +9,30 @@ public static void main(String[] args) { ArrayList flavors = menu.getFlavors(); ArrayList cones = menu.getCones(); - // TODO: Use a Comparator class to sort the 'flavors' array alphabetically by the 'name' field. - // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' field. + flavors.sort(new FlavorComparator()); - // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. + + System.out.println("Flavors:"); + for (Flavor flavor : flavors) { + System.out.println(flavor.getName()); + } + + cones.sort(new ConeComparator()); + + System.out.println("Cones:"); + for (Cone cone : cones) { + System.out.println(cone.getName() + ": $kkk" + cone.getCost()); + } } -} \ No newline at end of file +} + + + + +// TODO: Use a Comparator class to sort the 'flavors' array alphabetically by the 'name' field. + +// TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' field. + +// TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. + diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/BaseDisc.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/BaseDisc.java new file mode 100644 index 000000000..2ea35afa7 --- /dev/null +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/BaseDisc.java @@ -0,0 +1,66 @@ +package org.launchcode; + +public class BaseDisc { + private static int nextId = 1; + + private final int id; + private String name; + private String discType; + private int spinRate; + + public BaseDisc(String name, String discType, int spinRate) { + this.id = nextId; + this.name = name; + this.discType = discType; + this.spinRate = spinRate; + nextId++; + } + + public static int getNextId() { + return nextId; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDiscType() { + return discType; + } + + public void setDiscType(String discType) { + this.discType = discType; + } + + public int getSpinRate() { + return spinRate; + } + + public void setSpinRate(int spinRate) { + this.spinRate = spinRate; + } + + @Override + public String toString() { + String newline = System.lineSeparator(); + String asterisks = "*****"; + return newline + asterisks + " " + name + " " + asterisks + newline + + "ID: " + id + newline + + "Disc Type: " + discType + newline + + "Spin Rate: " + spinRate + "RPM" + newline; + } + + void spinDisc() { + String newline = System.lineSeparator(); + System.out.println(newline + "The " + discType + " " + name + + " is spinning at " + spinRate + " Rpm."); + } +} diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/CD.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/CD.java index 51781c249..9fea9a546 100644 --- a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/CD.java +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/CD.java @@ -1,8 +1,78 @@ package org.launchcode; -public class CD { - // TODO: Implement your custom interface. +public class CD extends Media implements OpticalDisc { - // TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones - // need to be declared separately. + private boolean isMusicCd; + + public CD(String name, boolean isMusicCd) { + super(name, "", 800, 700); + this.isMusicCd = isMusicCd; + setDiscType(isMusicCd ? "music CD" : "CD-RW"); + } + + public CD(String name) { + this(name, false); + } + + public boolean isMusicCD() { + return isMusicCd; + } + + public void setMusicCd(boolean musicCd) { + isMusicCd = musicCd; + } + + @Override + public String toString() { + String header = isMusicCd ? "Tracks" : "Files"; + return super.toString() + getFormattedFileList(header); + } + + @Override + public void writeFile(File file) { + spinDisc(); + String fileType = isMusicCd ? "track" : "file"; + if (getFiles().contains(file)) { + System.out.println("The " + fileType + " " + file.getName() + " has already been added."); + } else if (getSpaceUsed() + file.getSize() > getCapacity()) { + System.out.println("Warning: There is not enough space on the " + getDiscType() + " for " + file.getName() + "."); + } else { + getFiles().add(file); + System.out.println("The " + fileType + " " + file.getName() + " has been added to " + getName() + "."); + } + + } + + @Override + public void removeFile(File file) { + if (isMusicCd) { + System.out.println("Individual files cannot be removed from a music CD once written"); + } else { + spinDisc(); + if (fileIsPresent(file)) { + getFiles().remove(file); + System.out.println("The file " + file.getName() + " has been removed from the " + getDiscType()); + } + } + } + + @Override + public void reformatDisc() { + spinDisc(); + getFiles().clear(); + setMusicCd(false); + setDiscType("CD - RW"); + setName("Unnamed CD-RW"); + } + + @Override + public void runFile(File file) { + if (fileIsPresent(file)) { + spinDisc(); + String verb = isMusicCd ? "Playing " : "Opening file "; + System.out.println(verb + file.getName() + "..."); + } + + } } + diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/DVD.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/DVD.java index 7c2442568..069622026 100644 --- a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/DVD.java +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/DVD.java @@ -1,8 +1,53 @@ package org.launchcode; -public class DVD { - // TODO: Implement your custom interface. +public class DVD extends Media implements OpticalDisc { + public DVD(String name) { + super(name, "DVD", 1200, 4700); + } - // TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones - // need to be declared separately. + @Override + public String toString() { + return super.toString() + getFormattedFileList("Video Files"); + } + + @Override + public void writeFile(File file) { + spinDisc(); + if (getFiles().contains(file)) { + System.out.println("The video" + file.getName() + " has already been added."); + } else if (getSpaceUsed() + file.getSize() > getCapacity()) { + System.out.println("Warning: There is not enough space on the " + getDiscType() + " for " + file.getName() + "."); + } else { + getFiles().add(file); + System.out.println("The video " + file.getName() + " has been added to " + getName() + "."); + } + + + } + + @Override + public void removeFile(File file) { + spinDisc(); + if (fileIsPresent(file)) { + getFiles().remove(file); + System.out.println("The file " + file.getName() + " has been removed from the " + getDiscType()); + } + + } + + @Override + public void reformatDisc() { + spinDisc(); + getFiles().clear(); + } + + @Override + public void runFile(File file) { + if (fileIsPresent(file)) { + spinDisc(); + System.out.println("Watching" + file.getName() + "..."); + } + + } } + diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/File.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/File.java new file mode 100644 index 000000000..89c691979 --- /dev/null +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/File.java @@ -0,0 +1,25 @@ +package org.launchcode; + +public class File { + + private final String name; + private final double size; + + public File(String name, double size) { + this.name = name; + this.size = size; + } + + public String getName() { + return name; + } + + public double getSize() { + return size; + } + + @Override + public String toString() { + return name + " - " + size + " MB"; + } +} diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Main.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Main.java index 7d00acf4c..247556372 100644 --- a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Main.java +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Main.java @@ -2,9 +2,52 @@ public class Main { public static void main(String[] args) { + CD theNorthBorders = new CD("The North Borders", true); + CD graphicDesignProjects = new CD("Graphic Design Projects"); + DVD friendsSeason3 = new DVD("Friends: Season 3"); - // TODO: Declare and initialize a CD and a DVD object. - // TODO: Call each CD and DVD method to verify that they work as expected. + File firstFires = new File("First Fires", 50); + File Cirrus = new File("Cirrus", 61); + File transit = new File("Transit", 57); + theNorthBorders.writeFile(firstFires); + theNorthBorders.writeFile(Cirrus); + theNorthBorders.writeFile(transit); + + File festivalPoster = new File("festival-powder.psd", 240); + File companyLogo = new File("company-logo.ai", 52); + graphicDesignProjects.writeFile(festivalPoster); + graphicDesignProjects.writeFile(companyLogo); + + File s3e1 = new File("S3:E1 - The One with the princess Leia Fantasy", 420); + File s3e2 = new File("S3:E2 - The One Where No One's Ready", 420); + File s3e3 = new File("S3:E3 - The One with the Jam", 420); + File s3e4 = new File("S3:E4 - The One with the Metaphorical Tunnel", 420); + friendsSeason3.writeFile(s3e1); + friendsSeason3.writeFile(s3e2); + friendsSeason3.writeFile(s3e3); + friendsSeason3.writeFile(s3e4); + + System.out.println(theNorthBorders); + System.out.println(graphicDesignProjects); + System.out.println(friendsSeason3); + + + theNorthBorders.runFile(Cirrus); + graphicDesignProjects.runFile(companyLogo); + + friendsSeason3.writeFile(s3e2); + + + graphicDesignProjects.removeFile(festivalPoster); + theNorthBorders.runFile(festivalPoster); + + + theNorthBorders.reformatDisc(); + theNorthBorders.runFile(transit); + + + File tooBigFile = new File("too-big-file.mp4", 720); + theNorthBorders.writeFile(tooBigFile); } } \ No newline at end of file diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Media.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Media.java new file mode 100644 index 000000000..573824488 --- /dev/null +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/Media.java @@ -0,0 +1,70 @@ +package org.launchcode; + +import java.util.ArrayList; + +public abstract class Media extends BaseDisc { + + private double capacity; + private final ArrayList files = new ArrayList<>(); + + public Media(String name, String discType, int spinRate, double capacity) { + super(name, discType, spinRate); + this.capacity = capacity; + } + + public double getCapacity() { + return capacity; + } + + public void setCapacity(double capacity) { + this.capacity = capacity; + } + + public ArrayList getFiles() { + return files; + } + + @Override + public String toString() { + String newline = System.lineSeparator(); + return super.toString() + + "Capacity: " + capacity + "MB" + newline + + "Space Used: " + getSpaceUsed() + "MB" + newline + + "Available Space: " + getSpaceAvailable() + "MB" + newline; + + } + + public String getFormattedFileList(String header) { + StringBuilder fileList = new StringBuilder(); + String newline = System.lineSeparator(); + if (files.size() > 0) { + fileList.append(newline).append(header).append(":"); + for (File file : files) { + fileList.append(newline).append("\t").append(file); + } + } + return fileList.toString(); + } + + public boolean fileIsPresent(File file) { + if (getFiles().contains(file)) { + return true; + } else { + System.out.println("That file does not exist on this " + getDiscType() + "."); + return false; + } + } + + public double getSpaceUsed() { + int total = 0; + for (File file : files) { + total += file.getSize(); + } + return total; + } + + public double getSpaceAvailable() { + if (capacity == 0) return 0; + return capacity - getSpaceUsed(); + } +} diff --git a/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/OpticalDisc.java b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/OpticalDisc.java new file mode 100644 index 000000000..b98d30946 --- /dev/null +++ b/interfaces/studio/spinning-discs-studio/src/main/java/org/launchcode/OpticalDisc.java @@ -0,0 +1,12 @@ +package org.launchcode; + +public interface OpticalDisc { + + void writeFile(File file); + + void removeFile(File file); + + void reformatDisc(); + + void runFile(File file); +} diff --git a/technology/.gradle/8.0/checksums/checksums.lock b/technology/.gradle/8.0/checksums/checksums.lock new file mode 100644 index 000000000..274546210 Binary files /dev/null and b/technology/.gradle/8.0/checksums/checksums.lock differ diff --git a/technology/.gradle/8.0/checksums/md5-checksums.bin b/technology/.gradle/8.0/checksums/md5-checksums.bin new file mode 100644 index 000000000..a9a3652eb Binary files /dev/null and b/technology/.gradle/8.0/checksums/md5-checksums.bin differ diff --git a/technology/.gradle/8.0/checksums/sha1-checksums.bin b/technology/.gradle/8.0/checksums/sha1-checksums.bin new file mode 100644 index 000000000..0756b2435 Binary files /dev/null and b/technology/.gradle/8.0/checksums/sha1-checksums.bin differ diff --git a/technology/.gradle/8.0/dependencies-accessors/dependencies-accessors.lock b/technology/.gradle/8.0/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 000000000..9ae67233e Binary files /dev/null and b/technology/.gradle/8.0/dependencies-accessors/dependencies-accessors.lock differ diff --git a/technology/.gradle/8.0/dependencies-accessors/gc.properties b/technology/.gradle/8.0/dependencies-accessors/gc.properties new file mode 100644 index 000000000..e69de29bb diff --git a/technology/.gradle/8.0/executionHistory/executionHistory.lock b/technology/.gradle/8.0/executionHistory/executionHistory.lock new file mode 100644 index 000000000..59d97e3c9 Binary files /dev/null and b/technology/.gradle/8.0/executionHistory/executionHistory.lock differ diff --git a/technology/.gradle/8.0/fileChanges/last-build.bin b/technology/.gradle/8.0/fileChanges/last-build.bin new file mode 100644 index 000000000..f76dd238a Binary files /dev/null and b/technology/.gradle/8.0/fileChanges/last-build.bin differ diff --git a/technology/.gradle/8.0/fileHashes/fileHashes.lock b/technology/.gradle/8.0/fileHashes/fileHashes.lock new file mode 100644 index 000000000..b6416d2ef Binary files /dev/null and b/technology/.gradle/8.0/fileHashes/fileHashes.lock differ diff --git a/technology/.gradle/8.0/gc.properties b/technology/.gradle/8.0/gc.properties new file mode 100644 index 000000000..e69de29bb diff --git a/technology/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/technology/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 000000000..fdb1a3158 Binary files /dev/null and b/technology/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/technology/.gradle/buildOutputCleanup/cache.properties b/technology/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 000000000..58951409f --- /dev/null +++ b/technology/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Thu Oct 24 13:55:28 CDT 2024 +gradle.version=8.0 diff --git a/technology/.gradle/buildOutputCleanup/outputFiles.bin b/technology/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 000000000..3cc281488 Binary files /dev/null and b/technology/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/technology/.gradle/vcs-1/gc.properties b/technology/.gradle/vcs-1/gc.properties new file mode 100644 index 000000000..e69de29bb diff --git a/technology/build.gradle.kts b/technology/build.gradle.kts new file mode 100644 index 000000000..18561f2b0 --- /dev/null +++ b/technology/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.10.0")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/technology/gradle/wrapper/gradle-wrapper.jar b/technology/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/technology/gradle/wrapper/gradle-wrapper.jar differ diff --git a/technology/gradle/wrapper/gradle-wrapper.properties b/technology/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..8342eafaa --- /dev/null +++ b/technology/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Oct 24 13:55:22 CDT 2024 +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/technology/gradlew b/technology/gradlew new file mode 100644 index 000000000..1b6c78733 --- /dev/null +++ b/technology/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/technology/gradlew.bat b/technology/gradlew.bat new file mode 100644 index 000000000..107acd32c --- /dev/null +++ b/technology/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/technology/org/org/__init__.py b/technology/org/org/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/technology/settings.gradle.kts b/technology/settings.gradle.kts new file mode 100644 index 000000000..f4e6e5a3d --- /dev/null +++ b/technology/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "technology" + diff --git a/technology/src/main/java/org/launchcode/Computer.java b/technology/src/main/java/org/launchcode/Computer.java new file mode 100644 index 000000000..47801c09e --- /dev/null +++ b/technology/src/main/java/org/launchcode/Computer.java @@ -0,0 +1,4 @@ +package org.launchcode; + +public class Computer { +} diff --git a/technology/src/main/java/org/launchcode/Laptop.java b/technology/src/main/java/org/launchcode/Laptop.java new file mode 100644 index 000000000..066554987 --- /dev/null +++ b/technology/src/main/java/org/launchcode/Laptop.java @@ -0,0 +1,4 @@ +package org.launchcode; + +public class Laptop { +} diff --git a/technology/src/main/java/org/launchcode/Main.java b/technology/src/main/java/org/launchcode/Main.java new file mode 100644 index 000000000..2f85af545 --- /dev/null +++ b/technology/src/main/java/org/launchcode/Main.java @@ -0,0 +1,7 @@ +package org.launchcode; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/technology/src/main/java/org/launchcode/SmartPhone.java b/technology/src/main/java/org/launchcode/SmartPhone.java new file mode 100644 index 000000000..5209f2d73 --- /dev/null +++ b/technology/src/main/java/org/launchcode/SmartPhone.java @@ -0,0 +1,4 @@ +package org.launchcode; + +public class SmartPhone { +} diff --git a/technology/src/test/java/org/launchcode/ComputerTest.java b/technology/src/test/java/org/launchcode/ComputerTest.java new file mode 100644 index 000000000..2d6cb29cc --- /dev/null +++ b/technology/src/test/java/org/launchcode/ComputerTest.java @@ -0,0 +1,4 @@ +package org.launchcode; + +public class ComputerTest { +} 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 index f7b0c6f6e..eaa916024 100644 --- 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 @@ -1,10 +1,26 @@ package org.launchcode; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; +Car test_car; +@BeforeEach +public void createCarObject() { + test_car = new Car("Toyota", "Prius", 10, 50); +} class CarTest { //TODO: add emptyTest so we can configure our runtime environment (remove this test before pushing to your personal GitLab account) + @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 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 index d10c16f72..6db8fa0aa 100644 --- 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 @@ -46,6 +46,9 @@ public double getGasTankLevel() { } public void setGasTankLevel(double gasTankLevel) { + if (gasTankLevel > this.getGasTankSize()) { + throw new IllegalArgumentException("Can't exceed tank size"); + } this.gasTankLevel = gasTankLevel; } @@ -61,6 +64,10 @@ public double getOdometer() { return odometer; } + public void addGas(double gas) { + this.setGasTankLevel(gas + this.getGasTankLevel()); + } + /** * 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. 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 index 1a3f2a04a..6a8fcc71d 100644 --- 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 @@ -21,11 +21,24 @@ public void emptyTest() { //TODO: constructor sets gasTankLevel properly @Test - public void testInitialGasTank() { - assertEquals( 10, test_car.getGasTankLevel(),.001); - } + public void testInitialGasTank() { assertEquals( 10, test_car.getGasTankLevel(),.001);} //TODO: gasTankLevel is accurate after driving within tank range + @Test + public void testGasTankAfterDriving() { + test_car.drive(50); + assertEquals(9, test_car.getGasTankLevel(), .001);} //TODO: gasTankLevel is accurate after attempting to drive past tank range + @Test + public void testGasTankAfterExceedingTankRange(){ + test_car.drive(501); + assertEquals( test_car.getGasTankLevel(), 0, .001); + } //TODO: can't have more gas than tank size, expect an exception + @Test() + public void testGasOverfillException() { + assertThrows(IllegalArgumentException.class, () -> { + test_car.addGas(5); // Assuming tank size is less than current + 5 + }, "Shouldn't get here, car cannot have more gas in tank than the size of the tank"); + } } \ No newline at end of file