Compare commits
9 Commits
da35e1df3d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 873f4e7929 | |||
| e67cd5a385 | |||
| 1df8ec14a8 | |||
| 05f4c98fbe | |||
| c884acd6e2 | |||
| 5073cfb137 | |||
|
|
2b3da4d6fa | ||
|
|
705dfb6fec | ||
|
|
d352168fd8 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -152,3 +152,4 @@ $RECYCLE.BIN/
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
data/
|
||||
|
||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="18" />
|
||||
</component>
|
||||
</project>
|
||||
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/misc.xml
generated
Normal file
10
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="temurin-18" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/CPS121SkillsAssessment.main.iml" filepath="$PROJECT_DIR$/.idea/modules/CPS121SkillsAssessment.main.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
13
.idea/modules/CPS121SkillsAssessment.main.iml
generated
Normal file
13
.idea/modules/CPS121SkillsAssessment.main.iml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../../src/main">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="temurin-18" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Gradle: com.google.code.gson:gson:2.10.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.miglayout:miglayout:3.7.4" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
24
build.gradle
Normal file
24
build.gradle
Normal file
@@ -0,0 +1,24 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'com.github.johnrengelman.shadow' version '5.2.0'
|
||||
}
|
||||
|
||||
group 'tech.nevets'
|
||||
version '1.0'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.10.1'
|
||||
implementation 'com.miglayout:miglayout:3.7.4'
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Main-Class': 'tech.nevets.STEmployeeHours'
|
||||
)
|
||||
}
|
||||
}
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
240
gradlew
vendored
Normal file
240
gradlew
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
#!/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 \
|
||||
"$@"
|
||||
|
||||
# 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" "$@"
|
||||
91
gradlew.bat
vendored
Normal file
91
gradlew.bat
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
@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% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
1
secret.txt
Normal file
1
secret.txt
Normal file
@@ -0,0 +1 @@
|
||||
January is the first month and december is the last. Violet is a purple color as are lilac and plum.
|
||||
2
settings.gradle
Normal file
2
settings.gradle
Normal file
@@ -0,0 +1,2 @@
|
||||
rootProject.name = 'CPS121SkillsAssessment'
|
||||
|
||||
25
src/main/java/org/example/ChargeVerifier.java
Normal file
25
src/main/java/org/example/ChargeVerifier.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package org.example;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChargeVerifier {
|
||||
private static final ArrayList<Integer> VALID_CHARGES = new ArrayList<>(List.of(5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 8080152, 4562555, 5552012, 5050552, 7825877, 1250255, 1005231, 6545231, 3852085, 7576651, 7881200, 4581002));
|
||||
|
||||
public static boolean isValidCharge1(int accountNumber) {
|
||||
return VALID_CHARGES.contains(accountNumber);
|
||||
}
|
||||
|
||||
public static boolean isValidCharge2(int accountNumber) {
|
||||
for (int chargeNum : VALID_CHARGES) {
|
||||
if (accountNumber == chargeNum) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isValidCharge3(int accountNumber) {
|
||||
return VALID_CHARGES.stream().anyMatch(i -> accountNumber == i);
|
||||
}
|
||||
}
|
||||
165
src/main/java/org/example/Main.java
Normal file
165
src/main/java/org/example/Main.java
Normal file
@@ -0,0 +1,165 @@
|
||||
package org.example;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
helloWorld();
|
||||
|
||||
System.out.println("This will appear in console!");
|
||||
|
||||
int integerVar = 12345;
|
||||
char aSingleLetter = 'A';
|
||||
boolean trueOrFalse = true;
|
||||
String wordVar = "A bunch of text";
|
||||
|
||||
int a = 1 + 2;
|
||||
int b = a - 1;
|
||||
int c = b * a;
|
||||
int d = c / 3;
|
||||
|
||||
System.out.println(a + " : " + b + " : " + c + " : " + d);
|
||||
|
||||
float mpg = milesPerGallon(65, 1.96F);
|
||||
System.out.println(mpg);
|
||||
|
||||
boolean condition = true;
|
||||
|
||||
if (condition) {
|
||||
System.out.println("condition is true");
|
||||
}
|
||||
|
||||
if (condition) {
|
||||
System.out.println("condition is true");
|
||||
} else {
|
||||
System.out.println("condition is false");
|
||||
}
|
||||
|
||||
int intCondition = 1;
|
||||
|
||||
if (intCondition == 0) {
|
||||
System.out.println("The condition matches this first case");
|
||||
} else if (intCondition == 1) {
|
||||
System.out.println("The condition matches a different case");
|
||||
} else {
|
||||
System.out.println("The condition did not match any previous case");
|
||||
}
|
||||
|
||||
int time = secondsCompressor(2837);
|
||||
System.out.println(time);
|
||||
|
||||
int whileI = 0;
|
||||
boolean whileBool = true;
|
||||
while (whileBool) {
|
||||
System.out.println("This is looping!");
|
||||
whileI++;
|
||||
if (whileI > 5) {
|
||||
whileBool = false;
|
||||
}
|
||||
}
|
||||
|
||||
doublePennies(30);
|
||||
|
||||
float retailPrice = calculateRetail(5.00F, 100);
|
||||
System.out.println(retailPrice);
|
||||
|
||||
Person me = new Person("Steven", "123 Main Street", 17, 7175558700L);
|
||||
System.out.println(me);
|
||||
|
||||
Person friend = new Person("Bob", "123 Center Street", 18, 7175559900L);
|
||||
System.out.println(friend);
|
||||
|
||||
Person family = new Person("John", "123 Main Street", 15, 7175558600L);
|
||||
System.out.println(family);
|
||||
|
||||
Person[] people = new Person[3];
|
||||
people[0] = me;
|
||||
people[1] = friend;
|
||||
people[2] = family;
|
||||
|
||||
for (Person person : people) {
|
||||
System.out.println(person);
|
||||
}
|
||||
//for (int i = 0; i < people.length; i++) {
|
||||
// System.out.println(people.get(i));
|
||||
//}
|
||||
|
||||
System.out.println(averageAges(people));
|
||||
|
||||
TestChargeVerifier.main(new String[0]);
|
||||
}
|
||||
|
||||
public static void helloWorld() {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
|
||||
/**
|
||||
* returns value formatted to 1 decimal place
|
||||
*/
|
||||
public static float milesPerGallon(int miles, float fuelUsed) {
|
||||
String value = new DecimalFormat("0.0").format(miles / fuelUsed);
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes seconds and converts them to minutes hours and days if the value is greater than 1
|
||||
*/
|
||||
public static int secondsCompressor(int seconds) {
|
||||
if (seconds < 60) {
|
||||
return seconds;
|
||||
} else if (seconds < 3600) {
|
||||
return Math.round(seconds / 60F);
|
||||
} else if (seconds < 86400) {
|
||||
return Math.round(seconds / 3600F);
|
||||
} else {
|
||||
return Math.round(seconds / 86400F);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't pass anything higher than 64 days, java can't store longs greater than (insert large number) (i couldnt be bothered to look it up)
|
||||
*/
|
||||
public static void doublePennies(int days) {
|
||||
if (days < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (days > 64) {
|
||||
return;
|
||||
}
|
||||
|
||||
long pennies = 1L;
|
||||
|
||||
for (int i = 0; i < days; i++) {
|
||||
pennies *= 2;
|
||||
System.out.println("Day " + (i + 1) + ": " + (pennies / 100D));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the wholesale and markup and returns retail
|
||||
* @param wholeSale wholesale cost in dollar amount
|
||||
* @param markup markup as a percentage
|
||||
* @return float dollar amount rounded as X.XX
|
||||
*/
|
||||
public static float calculateRetail(float wholeSale, int markup) {
|
||||
float preRounded = wholeSale * (markup / 100F);
|
||||
String roundedString = new DecimalFormat("0.00").format(preRounded);
|
||||
return Float.parseFloat(roundedString);
|
||||
}
|
||||
|
||||
public static float averageAges(Person[] people) {
|
||||
float ageTotal = 0;
|
||||
float numOfPeople = 0;
|
||||
|
||||
for (Person person : people) {
|
||||
ageTotal += person.getAge();
|
||||
numOfPeople++;
|
||||
}
|
||||
|
||||
return ageTotal / numOfPeople;
|
||||
}
|
||||
}
|
||||
52
src/main/java/org/example/Person.java
Normal file
52
src/main/java/org/example/Person.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package org.example;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private String address;
|
||||
private int age;
|
||||
private long phoneNumber;
|
||||
|
||||
public Person(String name, String address, int age, long phoneNumber) {
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.age = age;
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public long getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public void setPhoneNumber(long phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[ Name: " + name+ ", Address: " + address + ", Age: " + age + ", Phone Number: " + phoneNumber + " ]";
|
||||
}
|
||||
}
|
||||
13
src/main/java/org/example/TestChargeVerifier.java
Normal file
13
src/main/java/org/example/TestChargeVerifier.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package org.example;
|
||||
|
||||
public class TestChargeVerifier {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(ChargeVerifier.isValidCharge1(1234567)); // False
|
||||
System.out.println(ChargeVerifier.isValidCharge1(8080152)); // True
|
||||
System.out.println(ChargeVerifier.isValidCharge2(1234567)); // False
|
||||
System.out.println(ChargeVerifier.isValidCharge2(8080152)); // True
|
||||
System.out.println(ChargeVerifier.isValidCharge3(1234567)); // False
|
||||
System.out.println(ChargeVerifier.isValidCharge3(8080152)); // True
|
||||
}
|
||||
}
|
||||
14
src/main/java/tech/nevets/Debug.java
Normal file
14
src/main/java/tech/nevets/Debug.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package tech.nevets;
|
||||
|
||||
import tech.nevets.util.DataUtils;
|
||||
import tech.nevets.util.Employee;
|
||||
|
||||
public class Debug {
|
||||
static Employee e = new Employee(100, "Steven", "Tracey");
|
||||
static Employee[] arr = new Employee[]{e};
|
||||
|
||||
public static void main(String[] args) {
|
||||
new DataUtils<>(Employee.class).saveToDataArray(arr, "EmployeeData", Employee[].class);
|
||||
|
||||
}
|
||||
}
|
||||
21
src/main/java/tech/nevets/STDieArguments.java
Normal file
21
src/main/java/tech/nevets/STDieArguments.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package tech.nevets;
|
||||
|
||||
import tech.nevets.util.Die;
|
||||
|
||||
public class STDieArguments {
|
||||
public static void main(String[] args) {
|
||||
final int SIX_SIDES = 6;
|
||||
final int TWENTY_SIDES = 20;
|
||||
|
||||
Die sixDie = new Die(SIX_SIDES);
|
||||
Die twentyDie = new Die(TWENTY_SIDES);
|
||||
|
||||
rollDie(sixDie);
|
||||
rollDie(twentyDie);
|
||||
}
|
||||
|
||||
public static void rollDie(Die d) {
|
||||
System.out.println("Rolling a " + d.getSides() + " sided die.");
|
||||
System.out.println("The die's value: " + d.roll());
|
||||
}
|
||||
}
|
||||
214
src/main/java/tech/nevets/STEmployeeHours.java
Normal file
214
src/main/java/tech/nevets/STEmployeeHours.java
Normal file
@@ -0,0 +1,214 @@
|
||||
package tech.nevets;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import tech.nevets.util.CastUtils;
|
||||
import tech.nevets.util.DataUtils;
|
||||
import tech.nevets.util.Employee;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class STEmployeeHours extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
private static final ArrayList<Employee> employeeList = new ArrayList<>();
|
||||
private static final DataUtils<Employee> EMPLOYEE_DATA_UTILS = new DataUtils<>(Employee.class);
|
||||
private static final CastUtils<Employee> EMPLOYEE_CAST_UTILS = new CastUtils<>(Employee.class);
|
||||
|
||||
JLabel idLabel;
|
||||
JTextField idField;
|
||||
JButton submitEmpId;
|
||||
JLabel empFirstName;
|
||||
JLabel empLastName;
|
||||
JLabel empHours;
|
||||
|
||||
JLabel addHoursLabel;
|
||||
JTextField addHoursField;
|
||||
JButton addHoursButton;
|
||||
|
||||
public STEmployeeHours() {
|
||||
contentPane = new JPanel();
|
||||
employeeList.clear();
|
||||
employeeList.addAll(List.of(EMPLOYEE_CAST_UTILS.castArray(EMPLOYEE_DATA_UTILS.getArrayFromData("EmployeeData"))));
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
EMPLOYEE_DATA_UTILS.saveToDataArray(EMPLOYEE_CAST_UTILS.castArray(employeeList.toArray()), "EmployeeData", Employee[].class);
|
||||
}
|
||||
});
|
||||
setContentPane(contentPane);
|
||||
contentPane.setBorder(new EmptyBorder(1, 1, 1, 1));
|
||||
MigLayout layout = new MigLayout(
|
||||
"",
|
||||
"[][fill][]",
|
||||
"[][][][][][]"
|
||||
);
|
||||
contentPane.setLayout(layout);
|
||||
|
||||
idLabel = new JLabel("Employee Id:");
|
||||
contentPane.add(idLabel, "cell 0 0");
|
||||
idField = new JTextField();
|
||||
contentPane.add(idField, "cell 1 0,w 150");
|
||||
|
||||
AtomicInteger empIdCache = new AtomicInteger();
|
||||
submitEmpId = new JButton("Submit");
|
||||
submitEmpId.addActionListener(al -> {
|
||||
empIdCache.set(Integer.parseInt(idField.getText()));
|
||||
boolean isFound = false;
|
||||
for (Employee e : employeeList) {
|
||||
if (idField.getText().equals(String.valueOf(e.getEmployeeId()))) {
|
||||
isFound = true;
|
||||
idLabel.setText("Employee Id:");
|
||||
updateUI(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isFound) {
|
||||
idLabel.setText("User Not Found");
|
||||
}
|
||||
});
|
||||
contentPane.add(submitEmpId, "cell 2 0");
|
||||
|
||||
empFirstName = new JLabel("First Name: ");
|
||||
contentPane.add(empFirstName, "cell 1 1");
|
||||
empLastName = new JLabel("Last Name: ");
|
||||
contentPane.add(empLastName, "cell 1 2");
|
||||
empHours = new JLabel("Total Hours: ");
|
||||
contentPane.add(empHours, "cell 1 3");
|
||||
|
||||
addHoursLabel = new JLabel("Hours To Add:");
|
||||
contentPane.add(addHoursLabel, "cell 0 4");
|
||||
addHoursField = new JTextField();
|
||||
contentPane.add(addHoursField, "cell 1 4");
|
||||
addHoursButton = new JButton("Add");
|
||||
addHoursButton.addActionListener(al -> {
|
||||
if (addHoursField.getText().equals("")) {
|
||||
return;
|
||||
}
|
||||
updateEmpHours(empIdCache.get(), Integer.parseInt(addHoursField.getText()));
|
||||
updateUI(empIdCache.get());
|
||||
addHoursField.setText("");
|
||||
});
|
||||
contentPane.add(addHoursButton, "cell 2 4,grow");
|
||||
|
||||
JButton newUserBtn = new JButton("New User");
|
||||
newUserBtn.addActionListener(al -> {
|
||||
AddUserFrame newUserFrame = new AddUserFrame();
|
||||
newUserFrame.setLocationRelativeTo(null);
|
||||
newUserFrame.pack();
|
||||
newUserFrame.setVisible(true);
|
||||
});
|
||||
contentPane.add(newUserBtn, "cell 1 5,grow");
|
||||
}
|
||||
|
||||
private void updateUI(Employee e) {
|
||||
empFirstName.setText("First Name: " + e.getEmployeeFirstName());
|
||||
empLastName.setText("Last Name: " + e.getEmployeeLastName());
|
||||
empHours.setText("Total Hours: " + e.getEmployeeHours());
|
||||
}
|
||||
|
||||
private void updateUI(int empId) {
|
||||
for (Employee e : employeeList) {
|
||||
if (e.getEmployeeId() == empId) {
|
||||
empFirstName.setText("First Name: " + e.getEmployeeFirstName());
|
||||
empLastName.setText("Last Name: " + e.getEmployeeLastName());
|
||||
empHours.setText("Total Hours: " + e.getEmployeeHours());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEmpHours(int id, int hoursToAdd) {
|
||||
for (Employee e : employeeList) {
|
||||
if (e.getEmployeeId() == id) {
|
||||
e.addHours(hoursToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
STEmployeeHours frame = new STEmployeeHours();
|
||||
frame.setBounds(0, 0, 860, 480);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
private static class AddUserFrame extends JFrame {
|
||||
public AddUserFrame() {
|
||||
setResizable(false);
|
||||
JPanel auContentPane = new JPanel();
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setContentPane(auContentPane);
|
||||
auContentPane.setBorder(new EmptyBorder(1, 1, 1, 1));
|
||||
MigLayout layout = new MigLayout(
|
||||
"",
|
||||
"[][fill][]",
|
||||
"[][][][][][]"
|
||||
);
|
||||
auContentPane.setLayout(layout);
|
||||
|
||||
JLabel errorLabel = new JLabel("");
|
||||
auContentPane.add(errorLabel, "cell 0 5");
|
||||
|
||||
JLabel idLabel = new JLabel("User Id:");
|
||||
auContentPane.add(idLabel, "cell 0 1");
|
||||
JTextField idField = new JTextField();
|
||||
auContentPane.add(idField, "cell 1 1");
|
||||
JLabel firstNameLabel = new JLabel("First Name:");
|
||||
auContentPane.add(firstNameLabel, "cell 0 2");
|
||||
JTextField firstNameField = new JTextField();
|
||||
auContentPane.add(firstNameField, "cell 1 2");
|
||||
JLabel lastNameLabel = new JLabel("Last Name:");
|
||||
auContentPane.add(lastNameLabel, "cell 0 3");
|
||||
JTextField lastNameField = new JTextField();
|
||||
auContentPane.add(lastNameField, "cell 1 3");
|
||||
JButton submitButton = new JButton("Create");
|
||||
submitButton.addActionListener(al -> {
|
||||
boolean idExists = false;
|
||||
for (Employee e : employeeList) {
|
||||
if (e.getEmployeeId() == Integer.parseInt(idField.getText())) {
|
||||
errorLabel.setText("User with that id already exists");
|
||||
idExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!idExists) {
|
||||
Employee e = new Employee(Integer.parseInt(idField.getText()), firstNameField.getText(), lastNameField.getText());
|
||||
employeeList.add(e);
|
||||
this.dispose();
|
||||
}
|
||||
});
|
||||
auContentPane.add(submitButton, "cell 1 4");
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.addActionListener(al -> {
|
||||
this.dispose();
|
||||
});
|
||||
auContentPane.add(cancelButton, "cell 2 4");
|
||||
}
|
||||
}
|
||||
|
||||
private static class GrossPayFrame extends JFrame {
|
||||
public GrossPayFrame() {
|
||||
setResizable(false);
|
||||
JPanel gpContentPane = new JPanel();
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setContentPane(gpContentPane);
|
||||
gpContentPane.setBorder(new EmptyBorder(1, 1, 1, 1));
|
||||
MigLayout layout = new MigLayout(
|
||||
"",
|
||||
"[][fill][]",
|
||||
"[][][][][][]"
|
||||
);
|
||||
gpContentPane.setLayout(layout);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/main/java/tech/nevets/STFileWriter.java
Normal file
22
src/main/java/tech/nevets/STFileWriter.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package tech.nevets;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class STFileWriter {
|
||||
public static void main(String[] args) {
|
||||
String user = "stracey.intern";
|
||||
String fileLocation1 = "C:\\Users\\" + user + "\\Desktop\\back-slash.txt";
|
||||
String fileLocation2 = "C:/Users/" + user + "/Desktop/forward-slash.txt";
|
||||
|
||||
File file1 = new File(fileLocation1);
|
||||
File file2 = new File(fileLocation2);
|
||||
|
||||
try {
|
||||
file1.createNewFile();
|
||||
file2.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/main/java/tech/nevets/STMethods.java
Normal file
18
src/main/java/tech/nevets/STMethods.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package tech.nevets;
|
||||
|
||||
public class STMethods {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello from the main method.");
|
||||
|
||||
displayMessage();
|
||||
|
||||
System.out.println("Back in the main method");
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link STMethods#displayMessage()} method displays a greeting.
|
||||
*/
|
||||
public static void displayMessage() {
|
||||
System.out.println("Hello from the displayMessage method.");
|
||||
}
|
||||
}
|
||||
15
src/main/java/tech/nevets/STMileageD.java
Normal file
15
src/main/java/tech/nevets/STMileageD.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package tech.nevets;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class STMileageD {
|
||||
public static void main(String[] args) {
|
||||
JOptionPane.showMessageDialog(null, "This program will calculate mileage");
|
||||
int miles = Integer.parseInt(JOptionPane.showInputDialog("Enter the miles driven"));
|
||||
int gallons = Integer.parseInt(JOptionPane.showInputDialog("Enter the gallons used"));
|
||||
float mpg = (float) miles / (float) gallons;
|
||||
JOptionPane.showMessageDialog(null, mpg + " miles per gallon");
|
||||
String mpgFormatted = String.format("%.2f miles per gallon", mpg);
|
||||
JOptionPane.showMessageDialog(null, mpgFormatted);
|
||||
}
|
||||
}
|
||||
18
src/main/java/tech/nevets/STMileageS.java
Normal file
18
src/main/java/tech/nevets/STMileageS.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package tech.nevets;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class STMileageS {
|
||||
private static Scanner sc = new Scanner(System.in);
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("This program will calculate mileage");
|
||||
System.out.print("Enter the miles driven: ");
|
||||
int miles = sc.nextInt();
|
||||
System.out.print("Enter the gallons used: ");
|
||||
int gallons = sc.nextInt();
|
||||
float mpg = (float) miles / (float) gallons;
|
||||
System.out.println(mpg + " miles per gallon");
|
||||
System.out.printf("%.2f miles per gallon", mpg);
|
||||
}
|
||||
}
|
||||
47
src/main/java/tech/nevets/STNumericTypes.java
Normal file
47
src/main/java/tech/nevets/STNumericTypes.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package tech.nevets;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class STNumericTypes {
|
||||
static final int NUMBER = 2;
|
||||
static final int SCORE1 = 100;
|
||||
static final int SCORE2 = 95;
|
||||
static final int BOILING_IN_F = 212;
|
||||
|
||||
public static void main(String[] args) {
|
||||
int fToC;
|
||||
double average;
|
||||
String output;
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
average = (double) (SCORE1 + SCORE2) / NUMBER;
|
||||
output = SCORE1 + " and " + SCORE2 + " have an average of " + average;
|
||||
System.out.println(output);
|
||||
|
||||
fToC = Math.round((5 / 9F) * (BOILING_IN_F - 32));
|
||||
output = BOILING_IN_F + " in Fahrenheit is " + fToC + " in Celsius.";
|
||||
System.out.println(output);
|
||||
System.out.println();
|
||||
|
||||
System.out.print("Enter First Name: ");
|
||||
String firstName = sc.nextLine();
|
||||
System.out.print("Enter Last Name: ");
|
||||
String lastName = sc.nextLine();
|
||||
System.out.println(firstName + " " + lastName);
|
||||
System.out.println();
|
||||
|
||||
char firstInitial = firstName.charAt(0);
|
||||
System.out.println(firstInitial);
|
||||
String nameUpper = firstName.toUpperCase();
|
||||
System.out.println(nameUpper);
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Enter Sphere Diameter: ");
|
||||
int sphereDiameter = sc.nextInt();
|
||||
float sphereRadius = sphereDiameter / 2.0F;
|
||||
float sphereVolume = (float) ((4 / 3F) * Math.PI * (sphereRadius * sphereRadius * sphereRadius));
|
||||
System.out.println(sphereVolume);
|
||||
}
|
||||
|
||||
}
|
||||
41
src/main/java/tech/nevets/STNumericTypesAlgorithm.txt
Normal file
41
src/main/java/tech/nevets/STNumericTypesAlgorithm.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
// This program will demonstrate the function of numeric operators
|
||||
|
||||
// Class declarator
|
||||
// Main method head
|
||||
|
||||
Create Scanner Object
|
||||
|
||||
Create constant ints for NUMBER = 2, SCORE1 = 100, SCORE2 = 95, and BOILING_IN_F = 212
|
||||
Create int named fToC
|
||||
Create double named average
|
||||
Create String named output
|
||||
|
||||
Set average to SCORE1 plus SCORE2, all divided by NUMBER
|
||||
Set output to SCORE1 appending " and " appending average appending " have an average of " appending average
|
||||
Print output to the console
|
||||
|
||||
// This converts Fahrenheit to Celsius
|
||||
Set fToC to 5 divided by 9 all times (BOILING_IN_F minus 32)
|
||||
Set output to BOILING_IN_F appending " in Fahrenheit is " appending fToC appending " in Celsius."
|
||||
Print output to the console
|
||||
Print a newline to the console
|
||||
|
||||
// Reads user's first and last name, then appends them
|
||||
Print "Enter First Name: " to console
|
||||
Use previously created scanner object to read the String, setting it to variable firstName
|
||||
Print "Enter Last Name: " to console
|
||||
Use scanner object to read the String, setting it to variable lastName
|
||||
Print firstName appending lastName to the console
|
||||
Print newline to the console
|
||||
|
||||
Use the String method charAt passing in 0 to get the first char in the first name, setting that to a new char variable named firstInitial
|
||||
Print firstInitial to the console
|
||||
Use the String method toUpperCase, setting that to a new String variable named nameUpper
|
||||
Print nameUpper to the console
|
||||
Print newline to the console
|
||||
|
||||
Print "Enter Sphere Diameter: " to console
|
||||
Use scanner object to get the entered int, setting it to a new variable named sphereDiameter
|
||||
Create new float named sphereRadius, setting it to shpereDiameter divided by 2.0F
|
||||
Create a new float named sphereVolume, setting it to (4 / 3F) * Math.PI * (sphereRadius * sphereRadius * sphereRadius)
|
||||
Print sphereVolume to the console
|
||||
11
src/main/java/tech/nevets/STRandomizer.java
Normal file
11
src/main/java/tech/nevets/STRandomizer.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package tech.nevets;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class STRandomizer {
|
||||
public static void main(String[] args) {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
rand.nextInt();
|
||||
}
|
||||
}
|
||||
72
src/main/java/tech/nevets/STSearchArray.java
Normal file
72
src/main/java/tech/nevets/STSearchArray.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package tech.nevets;
|
||||
|
||||
/**
|
||||
* This class tells you which grades you achieved 100%'s on
|
||||
*/
|
||||
public class STSearchArray {
|
||||
private static final int[] GRADES = {94, 96, 100, 97, 94, 100, 93};
|
||||
|
||||
public static void main(String[] args) {
|
||||
// boolean stores flag in case no 100's were found
|
||||
boolean atLeastOne = false;
|
||||
// loops through grades, checking if each one is equal to 100
|
||||
for (int i = 0; i < GRADES.length; i++) {
|
||||
// if the grade equals 100, it displays which grade it is (using the getPlace method)
|
||||
// then it displays which subscript it's in
|
||||
// finally it sets the atLeastOne flag to true so the sorry messages does not get displayed
|
||||
if (GRADES[i] == 100) {
|
||||
System.out.println("Your " + getPlace(i + 1) + " grade (subscript " + i + ") is a 100%, good job!");
|
||||
atLeastOne = true;
|
||||
}
|
||||
}
|
||||
// if the atLeastOne flag is false, the sorry message will be displayed
|
||||
if (!atLeastOne) {
|
||||
System.out.println("Sorry, but you did not score 100% on anything :(");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* I bashed my head against my keyboard until this method worked properly...
|
||||
*
|
||||
* This method takes a number and determines if it gets suffixed with 'st', 'nd', 'rd', or 'th'
|
||||
* @param index number you want suffixed with 'st', 'nd', 'rd', or 'th'
|
||||
* @return String value of # and 'st', 'nd', 'rd', or 'th'
|
||||
*/
|
||||
private static String getPlace(int index) {
|
||||
// Separate number into individual digits (chars)
|
||||
char[] digits = String.valueOf(index).toCharArray();
|
||||
// Quick 'th' suffix for non-edge cases
|
||||
String nonSpecial = Integer.parseInt(String.valueOf(digits)) + "th";
|
||||
// Catches stupid 11th 12th and 13th cases
|
||||
// Ensures number is > 9
|
||||
if (digits.length > 1) {
|
||||
// Ensures the tens place is 1
|
||||
if (digits[digits.length - 2] == '1') {
|
||||
return nonSpecial;
|
||||
}
|
||||
}
|
||||
// Quick ternary operation to quickly deal with single digits
|
||||
// This String will have 1st, 2nd, or 3rd appended if necessary
|
||||
// Otherwise the switch case will return the precalculated value
|
||||
final String podiumCasesPrefix = digits.length > 1 ?
|
||||
String.valueOf(digits).substring(0, digits.length - 1) :
|
||||
"";
|
||||
// Switch case for adding the special 'st', 'nd', and 'rd' suffixes
|
||||
// Or returning the initial 'th' ending
|
||||
switch (digits[digits.length - 1]) {
|
||||
case '1' -> {
|
||||
return podiumCasesPrefix + "1st";
|
||||
}
|
||||
case '2' -> {
|
||||
return podiumCasesPrefix + "2nd";
|
||||
}
|
||||
case '3' -> {
|
||||
return podiumCasesPrefix + "3rd";
|
||||
}
|
||||
default -> {
|
||||
return nonSpecial;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
src/main/java/tech/nevets/STSecretMessage.java
Normal file
49
src/main/java/tech/nevets/STSecretMessage.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package tech.nevets;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* This class will extract a secret word from the string in the <a href="./secret.txt">secret.txt</a> file.
|
||||
* Ensure you have created a secret.txt file, with text, in the same directory as the program.
|
||||
*/
|
||||
public class STSecretMessage {
|
||||
/**
|
||||
* Main method where everything takes place
|
||||
* @param args default args variable
|
||||
* @throws FileNotFoundException FileReader will error out if the <a href="./secret.txt">secret.txt</a> file does not exist.
|
||||
*/
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
// The following 4 lines opens a buffered reader from a file reader
|
||||
// Then it creates the string by appending all the lines into a single StringBuilder
|
||||
// To achieve this, I used Java's built-in Streams API
|
||||
BufferedReader reader = new BufferedReader(new FileReader("./secret.txt"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
reader.lines().forEach(sb::append);
|
||||
String secretTextRaw = sb.toString();
|
||||
|
||||
// Below loops through the StringTokenizer object while counting each fifth interval
|
||||
StringTokenizer tokenizer = new StringTokenizer(secretTextRaw, " ", false);
|
||||
StringBuilder secret = new StringBuilder();
|
||||
// Here we set the counter to 4 to start with the first word in the secret text.
|
||||
int count = 4;
|
||||
// I initialize the String variable with the first token
|
||||
// For the boolean check I make sure there are still tokens left in the buffer, preventing an exception.
|
||||
// Finally, I update the String variable with the next token.
|
||||
for (String s = tokenizer.nextToken(); tokenizer.countTokens() > 0; s = tokenizer.nextToken()) {
|
||||
// On the fifth interval it will append the first char of the token to the secret StringBuilder
|
||||
// Then reset the counter
|
||||
if (count == 4) {
|
||||
secret.append(s.charAt(0));
|
||||
count = 0;
|
||||
// On the off intervals, it increments the counter and loops again.
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// This line converts the StringBuilder to a string, then turns it to all caps and writes it to the console.
|
||||
System.out.println(secret.toString().toUpperCase());
|
||||
}
|
||||
}
|
||||
26
src/main/java/tech/nevets/STValueReturn.java
Normal file
26
src/main/java/tech/nevets/STValueReturn.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package tech.nevets;
|
||||
|
||||
public class STValueReturn {
|
||||
public static void main(String[] args) {
|
||||
int total;
|
||||
int value1 = 20;
|
||||
int value2 = 40;
|
||||
|
||||
total = sum(value1, value2);
|
||||
|
||||
System.out.println("The sum of " + value1 + " and " + value2 + " is " + total);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sum of the 2 passed parameters
|
||||
* @param num1 the first number to add
|
||||
* @param num2 the second number to add
|
||||
* @return the sum of the 2 passed numbers
|
||||
*/
|
||||
public static int sum(int num1, int num2) {
|
||||
int result;
|
||||
result = num1 + num2;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
18
src/main/java/tech/nevets/STWelcome.java
Normal file
18
src/main/java/tech/nevets/STWelcome.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package tech.nevets;
|
||||
|
||||
/**
|
||||
* @author Steven Tracey
|
||||
*/
|
||||
|
||||
public class STWelcome {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Welcome to Java Programming.");
|
||||
System.out.print("I think this class ");
|
||||
System.out.println("will be awesome!");
|
||||
System.out.println("I promise not to cheat in this class");
|
||||
System.out.println("If caught, I will be withdrawn with an F grade");
|
||||
System.out.println("Como estas hoy"); // Lang: Spanish
|
||||
System.out.println("J'espere que tu aimes ce cours"); // Lang: French
|
||||
System.out.println("Byona gironata"); // Lang: Italian
|
||||
}
|
||||
}
|
||||
22
src/main/java/tech/nevets/STWelcomeAlgorithm.txt
Normal file
22
src/main/java/tech/nevets/STWelcomeAlgorithm.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
// This program prints text to console
|
||||
// Steven Tracey
|
||||
|
||||
//class declarator
|
||||
//main method
|
||||
|
||||
Display "Welcome to Java Programming."
|
||||
Go to next line
|
||||
Display "I think this class "
|
||||
Display "will be awesome!"
|
||||
Go to next line
|
||||
Display "I promise not to cheat in this class"
|
||||
Go to next line
|
||||
Display "If caught, I will be withdrawn with an F grade"
|
||||
Go to next line
|
||||
Display "Como estas hoy"
|
||||
Go to next line
|
||||
Display "J'espere que tu aimes ce cours"
|
||||
Go to next line
|
||||
Display "Byona gironata"
|
||||
|
||||
End of program
|
||||
12
src/main/java/tech/nevets/StevenTraceyMyFirstProgram.java
Normal file
12
src/main/java/tech/nevets/StevenTraceyMyFirstProgram.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package tech.nevets;
|
||||
|
||||
/**
|
||||
* @author Steven Tracey
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class StevenTraceyMyFirstProgram {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
System.out.println("This is my project!");
|
||||
}
|
||||
}
|
||||
12
src/main/java/tech/nevets/Test.java
Normal file
12
src/main/java/tech/nevets/Test.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package tech.nevets;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
int i = 5;
|
||||
System.out.println("i is 5, next int is prefixed");
|
||||
System.out.println(++i);
|
||||
i = 5;
|
||||
System.out.println("i is 5, next int is postfixed");
|
||||
System.out.println(i++);
|
||||
}
|
||||
}
|
||||
7
src/main/java/tech/nevets/c5t9/Main.java
Normal file
7
src/main/java/tech/nevets/c5t9/Main.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package tech.nevets.c5t9;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
}
|
||||
}
|
||||
24
src/main/java/tech/nevets/util/CastUtils.java
Normal file
24
src/main/java/tech/nevets/util/CastUtils.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package tech.nevets.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class CastUtils<T> {
|
||||
private Class<T> clazz;
|
||||
|
||||
public CastUtils(Class<T> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public T[] castArray(Object[] array) {
|
||||
T[] newArray = (T[]) Array.newInstance(clazz, array.length);
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
newArray[i] = (T) array[i];
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
public T castObject(Object obj) {
|
||||
return (T) obj;
|
||||
}
|
||||
}
|
||||
78
src/main/java/tech/nevets/util/DataUtils.java
Normal file
78
src/main/java/tech/nevets/util/DataUtils.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package tech.nevets.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class DataUtils<T> {
|
||||
private Class<T> clazz;
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
public DataUtils(Class<T> clazz) {
|
||||
this.clazz = clazz;
|
||||
File dataDir = new File("./data/");
|
||||
if (!dataDir.exists()) {
|
||||
dataDir.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveToDataArray(T[] array, String fileName, Class<T[]> clazzLocal) {
|
||||
String json = gson.toJson(array, clazzLocal);
|
||||
writeJsonToFile(json, fileName);
|
||||
}
|
||||
|
||||
public void saveToDataObject(T data, String fileName) {
|
||||
String json = gson.toJson(data, clazz);
|
||||
writeJsonToFile(json, fileName);
|
||||
}
|
||||
|
||||
private void writeJsonToFile(String json, String fileName) {
|
||||
try {
|
||||
FileWriter fw = new FileWriter("./data/" + fileName + ".json");
|
||||
fw.write(json);
|
||||
fw.flush();
|
||||
fw.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public T[] getArrayFromData(String fileName) {
|
||||
File file = new File("./data/" + fileName + ".json");
|
||||
JsonArray ja;
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
ja = gson.fromJson(br, JsonArray.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ja == null) {
|
||||
ja = new JsonArray();
|
||||
}
|
||||
|
||||
Object[] dataArray = new Object[ja.size()];
|
||||
|
||||
for (int i = 0; i < ja.size(); i++) {
|
||||
dataArray[i] = gson.fromJson(ja.get(i).getAsJsonObject(), clazz);
|
||||
}
|
||||
|
||||
return new CastUtils<>(clazz).castArray(dataArray);
|
||||
}
|
||||
|
||||
public T getObjectFromData(String fileName) {
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader("./data/" + fileName + ".json"));
|
||||
return gson.fromJson(br, clazz);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/main/java/tech/nevets/util/Die.java
Normal file
22
src/main/java/tech/nevets/util/Die.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package tech.nevets.util;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class Die {
|
||||
private final int sides;
|
||||
private final Random r;
|
||||
|
||||
public Die(int sides) {
|
||||
this.sides = sides;
|
||||
r = ThreadLocalRandom.current();
|
||||
}
|
||||
|
||||
public int roll() {
|
||||
return (r.nextInt(sides - 1) + 1);
|
||||
}
|
||||
|
||||
public int getSides() {
|
||||
return sides;
|
||||
}
|
||||
}
|
||||
40
src/main/java/tech/nevets/util/Employee.java
Normal file
40
src/main/java/tech/nevets/util/Employee.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package tech.nevets.util;
|
||||
|
||||
public class Employee {
|
||||
private final int employeeId;
|
||||
private final String employeeFirstName;
|
||||
private final String employeeLastName;
|
||||
private int employeeHours;
|
||||
|
||||
public Employee(int employeeId, String employeeFirstName, String employeeLastName) {
|
||||
this.employeeId = employeeId;
|
||||
this.employeeFirstName = employeeFirstName;
|
||||
this.employeeLastName = employeeLastName;
|
||||
employeeHours = 0;
|
||||
}
|
||||
|
||||
public int getEmployeeId() {
|
||||
return employeeId;
|
||||
}
|
||||
|
||||
public String getEmployeeFirstName() {
|
||||
return employeeFirstName;
|
||||
}
|
||||
|
||||
public String getEmployeeLastName() {
|
||||
return employeeLastName;
|
||||
}
|
||||
|
||||
public int getEmployeeHours() {
|
||||
return employeeHours;
|
||||
}
|
||||
|
||||
public void addHours(int hours) {
|
||||
employeeHours += hours;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{ \"employeeId\":" + employeeId + ", \"employeeFirstName\":\"" + employeeFirstName + "\", \"employeeLastName\":\"" + employeeLastName + "\", \"employeeHours\":" + employeeHours + " }";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user