This repository was archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Zaytsev_Artem #39
Open
zarp86
wants to merge
16
commits into
master
Choose a base branch
from
feature/ZaytsevArtem
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Zaytsev_Artem #39
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
71f59ad
my first commit...again (after deleting my old branch, with the incor…
99d677e
renaming "homework_1" package to "Homework_1"
b92d100
added "Homework_2" and "Homework_2" -> "Traffic light" packages
cdedbba
added "Homework_2" and all subpackages (including created, but empty …
be446b2
editing of README.md (added link to my codingbat page)
9a21b4d
Homework_2 - 1st commit with resolved tasks. Also included style fixe…
ac4f643
Added "scanner.close();" - because of my forgetfulness :(.
15f4254
HW2 - names of packages have been changed (according to the task)
6a40a65
README.md updated
f6650a1
Merge remote-tracking branch 'origin/master' into Feature/ZaytsevArtem
c77cc53
HW_3 1st commit (+ some changes in HW_2 tasks)
a53a5cd
HW_4 1st commit (without Custom_Annotation task - it's in processing)
cbcc321
HW_4 2nd commit (added Custom_Annotation task)
b1f0d28
HW_4 3rd commit (added changes to README.md)
1021558
HW_5 1st commit
50d7637
HW_2. Commit was created after working on bugs.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,29 @@ | ||
| # Java Core June 2021 | ||
|
|
||
| ## *Nikolaev Artem* | ||
| ## *Zaytsev Artem* | ||
|
|
||
| | Number | Solution | Short description | ||
| | --- | --- | --- | | ||
| | HW1 | [Console printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/master/src/main/java/homework_1) | The app that reads input arguments and prints them, until "error" argument | | ||
| | HW_1 | [Console printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/homework_1) | The app that reads input arguments and prints them, until "error" argument | | ||
| | HW_2.1 | [Traffic Light](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/Homework_2/traffic_light) | The app that returns the color of the traffic light depending on the number of seconds from the beginning of the day | | ||
| | HW_2.2 | [Pyramid Printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/Homework_2/pyramid_printer) | The app that "builds" a pyramid with the given base | | ||
| | HW_2.3 | [Random Chars Table](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/Homework_2/random_chars_table) | The app that "builds" a table of chars, end print the letters which meet a given strategy (even/odd)| | ||
| | HW_3 | [ImmutableClass](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/homework_3) | ImmutableClass (MyImmutableElectricGuitarESP class)| | ||
| | HW_3.1 | [Traffic Light Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/test/java/homework_2/traffic_light) | Tests for "Traffic Light" Application| | ||
| | HW_3.2 | [Pyramid Printer Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/test/java/homework_2/pyramid_printer) | Tests for "Pyramid Printer" Application | | ||
| | HW_3.3 | [Random Chars Table Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/test/java/homework_2/random_chars_table) | Tests for "Random Chars Table" Application| | ||
| | HW_4.1 | [Custom_File_Reader](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/homework_4/custom_file_reader) | Custom_File_Reader task| | ||
| | HW_4.1_Tests | [Custom_File_Reader Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/test/java/homework_4/custom_file_reader) | Tests for Custom_File_Reader| | ||
| | HW_4.2 | [Singleton](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/homework_4/singleton) | Singleton task| | ||
| | HW_4.2_Tests | [Singleton Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/test/java/homework_4/singleton) | Tests for Singleton| | ||
| | HW_4.3 | [Custom_Annotation](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/homework_4/custom_annotation) | Custom_Annotation task| | ||
| | HW_4.3_Tests | [Custom_Annotation Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/test/java/homework_4/custom_annotation) | Tests for Custom_Annotation | | ||
| | HW_5.1 | [Power Of Number](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/homework_5/power_of_number) | Power Of Number task| | ||
| | HW_5.1_Tests | [Power Of Number Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/test/java/homework_5/power_of_number) | Tests for Power Of Number task| | ||
| | HW_5.2 | [Custom Regex Matcher](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/main/java/homework_5/custom_regex_matcher) | Custom Regex Matcher task| | ||
| | HW_5.2_Tests | [Custom Regex Matcher Tests](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/ZaytsevArtem/src/test/java/homework_5/custom_regex_matcher) | Tests for Custom Regex Matcher task| | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
|
|
||
| [Link to my codingbat result page](https://codingbat.com/done?user=zarp1986@gmail.com&tag=4480593357) | ||
|
|
||
| [Link to markdown guide](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,29 @@ | ||
| package homework_1; | ||
|
|
||
| public class Main { | ||
| protected static final String RED_COLOR = "\033[31m"; | ||
| protected static final String GREEN_COLOR = "\033[32m"; | ||
| protected static final String RESET_COLOR = "\033[0m"; | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("Hello homework!"); | ||
| } | ||
|
|
||
| } | ||
| int k = args.length; | ||
| if (k == 0) { | ||
| System.out.println(GREEN_COLOR + "Application has been called " + RED_COLOR + "without " + GREEN_COLOR + "the arguments!" + RESET_COLOR); | ||
| } else { | ||
| for (int i = 0; i < k; i++) { | ||
| if (args[i].equals("error")) { | ||
| //https://stackoverflow.com/questions/565252/how-to-set-a-strings-color | ||
| System.out.println(RED_COLOR + "Alarm!" + RESET_COLOR); | ||
| //exit from the loop | ||
| break; | ||
| } | ||
| else { | ||
| String s = "letter"; | ||
| if (args[i].length() > 1) {s = s + "s";} | ||
| System.out.println(args[i] + ": " + args[i].length() + " " + s); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package homework_2.pyramid_printer; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| new PyramidPrinter().run(); | ||
|
|
||
| } | ||
|
|
||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/homework_2/pyramid_printer/PyramidPrinter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package homework_2.pyramid_printer; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class PyramidPrinter { | ||
| protected final String ERROR_MSG = "Only 1 non-negative integer is allowed as passed parameter! Please, try again"; | ||
| int base; | ||
|
|
||
| public void run() { | ||
| System.out.println("Enter the base of the pyramid, valid value is integer:"); | ||
| readAndValidateInput(); | ||
| drawPyramid(base); | ||
|
|
||
| } | ||
|
|
||
| protected void readAndValidateInput() { | ||
| try (Scanner scanner = new Scanner(System.in)){ | ||
| String s = scanner.nextLine(); | ||
| if (s.matches("\\d+")) { | ||
| base = Integer.parseInt(s); | ||
| } else { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| catch (IllegalArgumentException e){ | ||
| System.out.println(ERROR_MSG); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| protected void drawPyramid(int base){ | ||
| for (int i = 0; i < base; i++){ | ||
| for (int j = 0; j <= i; j++){ | ||
| System.out.print("x"); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package homework_2.random_chars_table; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| new RandomCharsTable().run(); | ||
|
|
||
| } | ||
|
|
||
| } |
105 changes: 105 additions & 0 deletions
105
src/main/java/homework_2/random_chars_table/RandomCharsTable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package homework_2.random_chars_table; | ||
|
|
||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class RandomCharsTable { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix namings, declarations, whitespaces, cleanup and simplify your code
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope, that i've done it. |
||
| protected static final int MIN_ASCII_CODE = 65; | ||
| protected static final int MAX_ASCII_CODE = 90; | ||
| protected static final String ERR_MSG = "Passed parameters should match the format [positive integer] [positive integer] [even|odd]"; | ||
| int cols = 0; int rows = 0; | ||
| String strategy = ""; | ||
| boolean exceptionWasThrown; | ||
|
|
||
| public void run(){ | ||
| System.out.println("Enter the dimensions of matrix and required strategy : two integers and required strategy - even|odd, delimiter - space character))"); | ||
| readAndValidateInput(); | ||
| if (exceptionWasThrown) { | ||
| System.out.println(ERR_MSG); | ||
| } else { | ||
| int [][] matrix = createCharsTable(cols, rows); | ||
| printCharsTable(matrix, strategy); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| protected void readAndValidateInput (){ | ||
| try (Scanner scanner = new Scanner(System.in)) { | ||
| int paramCount = 0; | ||
| String tempStr = ""; | ||
| String inString = scanner.nextLine(); | ||
| if (inString.matches("\\d+\\s\\d+\\s[odevn]{3,4}")){ | ||
| for (int i = 0; i < inString.length(); i++) { | ||
| char c = inString.charAt(i); | ||
| if (c != ' ') { | ||
| tempStr = tempStr + c; | ||
| } | ||
| else { | ||
| if (paramCount == 0) { | ||
| cols = Integer.parseInt(tempStr); | ||
| paramCount++; | ||
| tempStr = ""; | ||
| continue; | ||
| } | ||
| if (paramCount == 1) { | ||
| rows = Integer.parseInt(tempStr); | ||
| paramCount++; | ||
| tempStr = ""; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| strategy = tempStr; | ||
| if ((!strategy.equals("even") && !strategy.equals("odd")) || cols <= 0 || rows <= 0) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } catch (RuntimeException e) { | ||
| exceptionWasThrown = true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public int[][] createCharsTable(int col, int row){ | ||
| int [][] matrix = new int[col][row]; | ||
| for (int i = 0; i < col; i++){ | ||
| for (int j = 0; j < row; j++){ | ||
| matrix [i][j] = rnd(MIN_ASCII_CODE, MAX_ASCII_CODE); | ||
| } | ||
| } | ||
| return matrix; | ||
|
|
||
| } | ||
|
|
||
| public void printCharsTable (int[][] matrix, String strategy){ | ||
| String tempStr; | ||
| boolean evStrat = strategy.equals("even"); | ||
| String stratHeader = (evStrat) ? "Even letters - " : "Odd letters - "; | ||
| String stratRes = ""; | ||
| for (int i = 0; i < matrix.length; i++ ) { | ||
| tempStr = ""; | ||
| for (int j = 0; j < matrix[0].length; j++){ | ||
| tempStr = tempStr + (char) matrix[i][j] + "|"; | ||
| if (evStrat && matrix[i][j] % 2 == 0) { | ||
| stratRes = (stratRes.equals("")) ? (char) matrix[i][j] + "," : stratRes + " " + (char) matrix[i][j] + ","; | ||
| } | ||
| if (!evStrat && matrix[i][j] % 2 == 1) { | ||
| stratRes = (stratRes.equals("")) ? (char) matrix[i][j] + "," : stratRes + " " + (char) matrix[i][j] + ","; | ||
| } | ||
| } | ||
| System.out.println("|" + tempStr); | ||
| } | ||
| stratRes = (stratRes.length() > 1) ? stratRes.substring(0, stratRes.length() - 1) : stratRes; | ||
| System.out.println(stratHeader + stratRes); | ||
|
|
||
| } | ||
|
|
||
| public static int rnd(int min, int max) { | ||
| max -= min; | ||
| return (int) (Math.random() * ++max) + min; | ||
|
|
||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package homework_2.traffic_light; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| new TrafficLight().run(); | ||
|
|
||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package homework_2.traffic_light; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
|
|
||
| public class TrafficLight { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hope, that i fixed it. |
||
| protected static final String RED_COLOUR = "\u001B[31m"; | ||
| protected static final String GREEN_COLOUR = "\u001B[32m"; | ||
| protected static final String YELLOW_COLOUR = "\u001B[33m"; | ||
| protected static final String RESET_COLOUR = "\u001B[0m"; | ||
| protected static final String ERR_MSG = "Only 1 non-negative integer is allowed as passed parameter! Please, try again"; | ||
| int seconds; | ||
| boolean exceptionWasThrown; | ||
|
|
||
| public void run(){ | ||
| System.out.println("Enter the time (valid range is from 0 to 86399 ):"); | ||
| readAndValidateInput(); | ||
| if (exceptionWasThrown) { | ||
| System.out.println(ERR_MSG); | ||
| } else { | ||
| showingTrafficLightColor(seconds); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| protected void readAndValidateInput () throws RuntimeException { | ||
| try (Scanner scanner = new Scanner(System.in)) { | ||
| String s = scanner.nextLine(); | ||
| if (!s.matches("\\d+")) { | ||
| throw new RuntimeException(); | ||
| } | ||
| else seconds = Integer.parseInt(s); | ||
| } | ||
| catch (RuntimeException e){ | ||
| exceptionWasThrown = true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| protected void showingTrafficLightColor(int sec){ | ||
| if (sec > 86399){ | ||
| System.out.println("The day is over"); | ||
| return; | ||
| } | ||
| sec = sec % 60; | ||
| String res = "unknown error("; | ||
| //YELLOW color | ||
| if ((sec >= 35 && sec < 40) || (sec >= 55 && sec < 60)) { | ||
| res = YELLOW_COLOUR + "YELLOW" + RESET_COLOUR; | ||
| } | ||
| //GREEN color | ||
| if (sec >= 0 && sec < 35) { | ||
| res = GREEN_COLOUR + "GREEN" + RESET_COLOUR; | ||
| } | ||
| //RED color | ||
| if (sec >= 40 && sec < 55) { | ||
| res = RED_COLOUR + "RED" + RESET_COLOUR; | ||
| } | ||
| System.out.println(res); | ||
|
|
||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure these are needed. You allowed junit in source code