diff --git a/atom.iml b/atom.iml new file mode 100644 index 0000000000..1d5353f1cd --- /dev/null +++ b/atom.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/homeworks/HW1/out/production/classes/ru/atom/Util.class b/homeworks/HW1/out/production/classes/ru/atom/Util.class new file mode 100644 index 0000000000..e2fff5f015 Binary files /dev/null and b/homeworks/HW1/out/production/classes/ru/atom/Util.class differ diff --git a/homeworks/HW1/out/test/classes/ru/atom/UtilTest.class b/homeworks/HW1/out/test/classes/ru/atom/UtilTest.class new file mode 100644 index 0000000000..591d84885d Binary files /dev/null and b/homeworks/HW1/out/test/classes/ru/atom/UtilTest.class differ diff --git a/homeworks/HW2/build.gradle b/homeworks/HW2/build.gradle new file mode 100644 index 0000000000..d412a50ab9 --- /dev/null +++ b/homeworks/HW2/build.gradle @@ -0,0 +1,28 @@ +plugins { + id 'java' + id 'checkstyle' +} + +group 'ru.example' +version '1.0-SNAPSHOT' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' + // https://mvnrepository.com/artifact/org.slf4j/slf4j-api + compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26' + + // https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl + compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.2' +} + +checkstyle { + ignoreFailures = false + toolVersion = '7.5' + configFile = new File('../../config/checkstyle/checkstyle.xml') +} diff --git a/homeworks/HW2/gradle/wrapper/gradle-wrapper.jar b/homeworks/HW2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..28861d273a Binary files /dev/null and b/homeworks/HW2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/homeworks/HW2/gradle/wrapper/gradle-wrapper.properties b/homeworks/HW2/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..7a165db90f --- /dev/null +++ b/homeworks/HW2/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Mar 07 15:06:40 MSK 2019 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip diff --git a/homeworks/HW2/gradlew b/homeworks/HW2/gradlew new file mode 100644 index 0000000000..cccdd3d517 --- /dev/null +++ b/homeworks/HW2/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$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="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# 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 + ;; + 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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/homeworks/HW2/gradlew.bat b/homeworks/HW2/gradlew.bat new file mode 100644 index 0000000000..f9553162f1 --- /dev/null +++ b/homeworks/HW2/gradlew.bat @@ -0,0 +1,84 @@ +@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 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= + +@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 init + +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 init + +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 + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +: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 %CMD_LINE_ARGS% + +: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/homeworks/HW2/logs/app.log b/homeworks/HW2/logs/app.log new file mode 100644 index 0000000000..4bcabfeb02 --- /dev/null +++ b/homeworks/HW2/logs/app.log @@ -0,0 +1,2 @@ +2019-03-07 15:33:26.793 INFO [main] [ru.example.Game] [main] [ru.example.Game.main(Game.java:16)] - Логгер живой +2019-03-07 15:34:44.846 INFO [main] [ru.example.Game] [main] [ru.example.Game.main(Game.java:15)] - Логгер живой diff --git a/homeworks/HW2/settings.gradle b/homeworks/HW2/settings.gradle new file mode 100644 index 0000000000..5de57eaf8e --- /dev/null +++ b/homeworks/HW2/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'BullsAndCows' + diff --git a/homeworks/HW2/src/main/java/ru/example/Game.java b/homeworks/HW2/src/main/java/ru/example/Game.java new file mode 100644 index 0000000000..d417d9aad8 --- /dev/null +++ b/homeworks/HW2/src/main/java/ru/example/Game.java @@ -0,0 +1,98 @@ +package ru.example; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +import java.util.Random; + +import org.slf4j.LoggerFactory; + +public class Game { + private static final org.slf4j.Logger log = LoggerFactory.getLogger(Game.class); + + public static void main(String[] args) { + + log.info("Логгер живой"); + play("dictionary.txt"); + + } + + public static boolean play(String filename) { + + String word = getWord(filename); //System.out.println(word); + char[] myword = word.toCharArray(); + int count = myword.length; + System.out.println("Welcome to Bulls and Cows game!"); + System.out.println("I offered a " + count + "-letter word, your guess?"); + Scanner scan = new Scanner(System.in); + for (int i = 0; i < 10; i++) { //10 попыток + + String mm = scan.nextLine(); + char[] inword = mm.toCharArray(); + if (word.equals(mm)) { //Сравнение 2х строк + System.out.println("You Won!!!"); + return true; + + } + + int bul = bulls(inword, myword); + int cow = cows(inword, word); + System.out.println("Bulls: " + bul); + System.out.println("Cows: " + (cow - bul)); + + } + + System.out.println("You Lose: " + word); + return false; + + } //Игра Быки и Коровы + + public static int bulls(char[] inword, char[] myword) { + + int count = Math.min(myword.length, inword.length);//Берем длинну более короткого слова + int bul = 0; + for (int j = 0; j < count; j++) //Считаем "Быков" + if (myword[j] == inword[j]) + bul++; + return bul; + + } //Вычисление "быков" + + public static int cows(char[] inword, String word) { + + int cow = 0; + for (int j = 0; j < inword.length; j++) //Счтаем"Коров" + if (word.indexOf(inword[j]) > -1) + cow++; + return cow; + } //Вычисление "коров" + + public static String getWord(String filename) { + + try { + + Scanner scan = new Scanner(new File(filename)); + int count = 0; + while (scan.hasNext()) { //Считаем количество строк(слов) в файле + scan.nextLine(); + count++; + + } + + Random rnd = new Random(System.currentTimeMillis()); + int number = rnd.nextInt(count);//Выбираем случайное слово + scan = new Scanner(new File(filename)); + for (int i = 0; i < number - 1; i++) + scan.nextLine(); + return (scan.nextLine());//Выводим полученное слово + + } catch (FileNotFoundException ex) { //Если файл не найден выводит ошибку + + System.err.println("File not found: " + ex.getMessage()); + return null; + + } + + } // Выбор случайного слова из файла + +} \ No newline at end of file diff --git a/homeworks/HW2/src/main/resources/log4j2.properties b/homeworks/HW2/src/main/resources/log4j2.properties new file mode 100644 index 0000000000..f55a9b361f --- /dev/null +++ b/homeworks/HW2/src/main/resources/log4j2.properties @@ -0,0 +1,49 @@ +status = warn +name= properties_configuration + +# Give directory path where log files should get stored +property.basePath = ./logs/ + +# ConsoleAppender will print logs on console +appender.console.type = Console +appender.console.name = consoleLogger +appender.console.target = SYSTEM_OUT +appender.console.layout.type = PatternLayout + +# Specify the pattern of the logs +appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%c] [%M] [%l] - %msg%n + + +# RollingFileAppender will print logs in file which can be rotated based on time or size +appender.rolling.type = RollingFile +appender.rolling.name = fileLogger +appender.rolling.fileName= ${basePath}app.log +appender.rolling.filePattern= ${basePath}app_%d{yyyyMMdd}.log.gz +appender.rolling.layout.type = PatternLayout +appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%c] [%M] [%l] - %msg%n +appender.rolling.policies.type = Policies + +# Rotate log file each day and keep 30 days worth +appender.rolling.policies.time.type = TimeBasedTriggeringPolicy +appender.rolling.policies.time.interval = 1 +appender.rolling.policies.time.modulate = true +appender.rolling.strategy.type = DefaultRolloverStrategy +appender.rolling.strategy.delete.type = Delete +appender.rolling.strategy.delete.basePath = ${basePath} +appender.rolling.strategy.delete.maxDepth = 1 +appender.rolling.strategy.delete.ifLastModified.type = IfLastModified +# Delete files older than 30 days +appender.rolling.strategy.delete.ifLastModified.age = 30d + +# Mention package name here in place of example. Classes in this package or subpackages will use ConsoleAppender and RollingFileAppender for logging +logger.example.name = example +logger.example.level = debug +logger.example.additivity = false +logger.example.appenderRef.rolling.ref = fileLogger +logger.example.appenderRef.console.ref = consoleLogger + +# Configure root logger for logging error logs in classes which are in package other than above specified package +rootLogger.level = debug +rootLogger.additivity = false +rootLogger.appenderRef.rolling.ref = fileLogger +rootLogger.appenderRef.console.ref = consoleLogger \ No newline at end of file diff --git a/homeworks/HW2/src/test/java/ru/example/GameTest.java b/homeworks/HW2/src/test/java/ru/example/GameTest.java new file mode 100644 index 0000000000..d8f88251bf --- /dev/null +++ b/homeworks/HW2/src/test/java/ru/example/GameTest.java @@ -0,0 +1,32 @@ +package ru.example; + +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + +public class GameTest { + + @Test + public void getWurg0() throws Exception { + assertEquals(null, Game.getWord("nodictionary.txt")); + } + + @Test + public void getWurg1() throws Exception { + assertEquals("hallow", Game.getWord("testWord.txt")); + } + + @Test + public void cows0() throws Exception { + String str = "halo"; + assertEquals(4, Game.cows(str.toCharArray(), "hallow")); + } + + @Test + public void bulls0() throws Exception { + String str = "halo"; + String str1 = "hallow"; + assertEquals(3, Game.bulls(str.toCharArray(), str1.toCharArray())); + } + +} \ No newline at end of file diff --git a/homeworks/HW2/testWord.txt b/homeworks/HW2/testWord.txt new file mode 100644 index 0000000000..e5da08e251 --- /dev/null +++ b/homeworks/HW2/testWord.txt @@ -0,0 +1 @@ +hallow \ No newline at end of file