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
Anton_Miazin #52
Open
AntonIOC777
wants to merge
13
commits into
master
Choose a base branch
from
feature/AntonMiazin
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
Anton_Miazin #52
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
23353b2
Initial commit new directory
AntonIOC777 45d25ba
Homework 1
AntonIOC777 1a14530
Create README.md
AntonIOC777 c957aa7
Homework 1_red color supporting
AntonIOC777 fd358e6
Merge remote-tracking branch 'origin/master' into feature/AntonMiazin
AntonIOC777 5814647
merged
AntonIOC777 f0a5544
HW2 first iteration
AntonIOC777 ad63b34
README update
AntonIOC777 e63862f
HW1 renaming & optional fixes
AntonIOC777 9ca240a
Merge branch 'master' into feature/AntonMiazin
AntonIOC777 29a06c4
HW2 reworking
AntonIOC777 f1f7a2b
HW2 reworking
AntonIOC777 228f368
HW3 tests except RandomCharTable
AntonIOC777 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,10 @@ | ||
| # Java Core June 2021 | ||
| # Java_Core_June_2021 | ||
|
|
||
| ## *Nikolaev Artem* | ||
| ## *Anton Miazin* | ||
|
|
||
| | 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 | | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
| | HW1 | [Console printer]( https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonMiazin/src/main/java/Homework_1 ) | The app that reads input arguments and prints them, until "error" argument | | ||
| | HW2 | [Traffic Light]( https://github.com/NikolaevArtem/Java_Core_June_2021/blob/feature/AntonMiazin/src/main/java/Homework_2/TrafficLight.java ) | The looped app that reads console input and return a color of a traffic light | | ||
| | HW2 | [Pyramid Printer]( https://github.com/NikolaevArtem/Java_Core_June_2021/blob/feature/AntonMiazin/src/main/java/Homework_2/PyramidPrinter.java ) | The app that build a triangle pyramid with a custom high | | ||
| | HW2 | [Random Chars Table]( https://github.com/NikolaevArtem/Java_Core_June_2021/blob/feature/AntonMiazin/src/main/java/Homework_2/RandomCharsTable.java ) | The looped app that create & print a custom array of the capital letters | |
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,16 @@ | ||
| package Homework_1; | ||
|
|
||
| public class ConsolePrinter { | ||
| public static void main(String[] args) { | ||
| final String ANSI_RED = "\u001B[31m"; | ||
| final String ANSI_RESET = "\u001B[0m\n"; | ||
| for (String arg : args) { | ||
| if (arg.equals("error")) { | ||
| System.out.println(ANSI_RED + "Alarm!" + ANSI_RESET); | ||
| break; | ||
| } else { | ||
| System.out.println(arg + " : " + arg.length() + " letters"); | ||
| } | ||
| } | ||
| } | ||
| } |
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,8 @@ | ||
| package Homework_2.PyramidPrinter; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| new PyramidPrinter().run(); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/main/java/Homework_2/PyramidPrinter/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,58 @@ | ||
| package Homework_2.PyramidPrinter; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class PyramidPrinter { | ||
|
|
||
| public void run () { | ||
| String inputData = consoleReading(); | ||
| String result = processing(inputData); | ||
| output(result); | ||
| } | ||
|
|
||
|
|
||
| private String consoleReading() { | ||
| System.out.print("Enter the pyramid height as a single integer: "); | ||
| try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { | ||
| String input = reader.readLine(); | ||
| return input; | ||
| } | ||
| catch (IOException e) { | ||
| return "This should never happen..."; | ||
| } | ||
| } | ||
|
|
||
| private String processing(String input) { | ||
| try { | ||
| int blocks = Integer.parseInt(input); | ||
| if (blocks < 0) { | ||
| throw new NumberFormatException(); | ||
| } | ||
| return pyramid(blocks); | ||
| } catch (NumberFormatException e) { | ||
| return "Only 1 non-negative integer is allowed as passed parameter"; | ||
| } | ||
| } | ||
|
|
||
| private String pyramid (int blocks) { | ||
| StringBuilder build = new StringBuilder(); | ||
| try{ | ||
| for (int i = 0; i < blocks; i++) { | ||
| for (int j = 0; j <= i; j++) { | ||
| build.append('x'); | ||
| } | ||
| build.append('\n'); | ||
| } | ||
| return build.toString(); | ||
| } | ||
| catch (OutOfMemoryError e) { | ||
| return "Heap space is out of memory, please input a smaller integer"; | ||
| } | ||
| } | ||
|
|
||
| private void output (String result){ | ||
| System.out.print(result); | ||
| } | ||
| } | ||
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,8 @@ | ||
| package Homework_2.RandomCharsTable; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| new RandomCharsTable().run(); | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
src/main/java/Homework_2/RandomCharsTable/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,77 @@ | ||
| package Homework_2.RandomCharsTable; | ||
|
|
||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.Random; | ||
|
|
||
| public class RandomCharsTable { | ||
|
|
||
| public void run () { | ||
| String inputData = consoleReading(); | ||
| String result = processing(inputData); | ||
| output(result); | ||
| } | ||
|
|
||
| private static String consoleReading() { | ||
| System.out.print("Enter the sizes of a table and a strategy: "); | ||
| try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { | ||
| String input = reader.readLine(); | ||
| return input; | ||
| } | ||
| catch (IOException e) { | ||
| return "This should never happen..."; | ||
| } | ||
| } | ||
|
|
||
| private String processing(String input) { | ||
| try { | ||
| String[] input_parts = input.split(" "); | ||
| int length = Integer.parseInt(input_parts[0]); | ||
| int width = Integer.parseInt(input_parts[1]); | ||
| String strategy = input_parts[2]; | ||
| if (length < 0 || width < 0) { | ||
| throw new NumberFormatException(); | ||
| } | ||
| if (!strategy.equalsIgnoreCase("even") && !strategy.equalsIgnoreCase("odd")) { | ||
| throw new NumberFormatException(); | ||
| } | ||
| return elementsOf(length, width, strategy); | ||
| } | ||
| catch (NumberFormatException e) { | ||
| return "Passed parameters should match the format [positive integer] [positive integer] [even|odd]"; | ||
| } | ||
| } | ||
|
|
||
| private String elementsOf(int length, int width, String strategy) { | ||
| StringBuilder table = new StringBuilder(); | ||
| StringBuilder evens = new StringBuilder(); | ||
| StringBuilder odds = new StringBuilder(); | ||
| evens.append("Even letters - "); | ||
| odds.append("Odd letters - "); | ||
| for (int i = 0; i < length; i++){ | ||
| table.append('|'); | ||
| for(int j = 0; j < width; j++) { | ||
| Random ran = new Random(); | ||
| int number = 65 + ran.nextInt(26); | ||
| table.append((char) number) | ||
| .append('|'); | ||
| if (number % 2 == 0){ | ||
| evens = evens.length() == 15 ? evens.append((char) number) : evens.append(", " + (char) number); | ||
| } | ||
| else { | ||
| odds = odds.length() == 14 ? odds.append((char) number) : odds.append(", " + (char) number); | ||
| } | ||
| } | ||
| table.append("\n"); | ||
| } | ||
| table = strategy.equalsIgnoreCase("even") ? table.append(evens) : table.append(odds); | ||
| return table.toString(); | ||
| } | ||
|
|
||
| private void output (String result){ | ||
| System.out.print(result); | ||
| } | ||
| } | ||
|
|
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,8 @@ | ||
| package Homework_2.TrafficLight; | ||
|
|
||
|
|
||
| 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,60 @@ | ||
| package Homework_2.TrafficLight; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class TrafficLight { | ||
|
|
||
| public void run () { | ||
| String inputData = consoleReading(); | ||
| String result = processing(inputData); | ||
| output(result); | ||
| } | ||
|
|
||
|
|
||
| private static String consoleReading() { | ||
| System.out.print("Please enter the amount of seconds as integer within 0 - 86399 range: "); | ||
| try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { | ||
| String input = reader.readLine(); | ||
| return input; | ||
| } | ||
| catch (IOException e) { | ||
| return "This should never happen..."; | ||
| } | ||
| } | ||
|
|
||
| private String processing(String input) { | ||
| try { | ||
| int time = Integer.parseInt(input); | ||
| if (time < 0){ | ||
| throw new NumberFormatException(); | ||
| } | ||
| else if (time > 86399){ | ||
| throw new NumberFormatException(); | ||
| } | ||
| return color(time); | ||
| } | ||
| catch (NumberFormatException e) { | ||
| return "Only 1 non-negative integer is allowed as passed parameter"; | ||
| } | ||
| } | ||
|
|
||
| private String color(int time) { | ||
| StringBuilder light = new StringBuilder(); | ||
| int timeSec = time % 60; | ||
| if (timeSec >= 0 && timeSec < 35) { | ||
| light.append("GREEN"); | ||
| } else if ((timeSec >= 35 && timeSec < 40) || (timeSec >= 55 && timeSec < 60)) { | ||
| light.append("YELLOW"); | ||
| } else if (timeSec >= 40 && timeSec < 54) { | ||
| light.append("RED"); | ||
| } | ||
| return light.toString(); | ||
| } | ||
|
|
||
| private void output (String result){ | ||
| System.out.print(result); | ||
| } | ||
| } | ||
|
|
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,7 @@ | ||
| package homework_1; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("Hello homework!"); | ||
| System.out.println("Hello, username!"); | ||
| } | ||
|
|
||
| } |
85 changes: 85 additions & 0 deletions
85
src/test/java/Homework_2/PyramidPrinterTest/PyramidPrinterTest.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,85 @@ | ||
| package Homework_2.PyramidPrinterTest; | ||
|
|
||
| import Homework_2.PyramidPrinter.PyramidPrinter; | ||
| import base.UnitBase; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class PyramidPrinterTest extends UnitBase { | ||
|
|
||
| @Test | ||
| void CaseSymbol_error() { | ||
| setInput("Hello!"); | ||
|
|
||
| new PyramidPrinter().run(); | ||
|
|
||
| removeFromOutput("Enter the pyramid height as a single integer: "); | ||
| assertEquals("Only 1 non-negative integer is allowed as passed parameter", getOutput()); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| void CaseDouble_error() { | ||
| setInput("0.1"); | ||
|
|
||
| new PyramidPrinter().run(); | ||
|
|
||
| removeFromOutput("Enter the pyramid height as a single integer: "); | ||
| assertEquals("Only 1 non-negative integer is allowed as passed parameter", getOutput()); | ||
| } | ||
|
|
||
| @Test | ||
| void CaseStandard_pass() { | ||
| setInput("4"); | ||
|
|
||
| new PyramidPrinter().run(); | ||
|
|
||
| printOut(); | ||
| removeFromOutput("Enter the pyramid height as a single integer: "); | ||
| assertEquals("x", getOutputLines()[0]); | ||
| assertEquals("xx", getOutputLines()[1]); | ||
| assertEquals("xxx", getOutputLines()[2]); | ||
| assertEquals("xxxx", getOutputLines()[3]); | ||
| } | ||
|
|
||
| @Test | ||
| void CaseZero_pass() { | ||
| setInput("0"); | ||
|
|
||
| new PyramidPrinter().run(); | ||
|
|
||
| removeFromOutput("Enter the pyramid height as a single integer: "); | ||
| assertEquals("", getOutput()); | ||
| } | ||
|
|
||
| @Test | ||
| void CaseNegative_error() { | ||
| setInput("-5"); | ||
|
|
||
| new PyramidPrinter().run(); | ||
|
|
||
| removeFromOutput("Enter the pyramid height as a single integer: "); | ||
| assertEquals("Only 1 non-negative integer is allowed as passed parameter", getOutput()); | ||
| } | ||
|
|
||
| @Test | ||
| void CaseLong_error() { | ||
| setInput("2147483648"); | ||
|
|
||
| new PyramidPrinter().run(); | ||
|
|
||
| removeFromOutput("Enter the pyramid height as a single integer: "); | ||
| assertEquals("Only 1 non-negative integer is allowed as passed parameter", getOutput()); | ||
| } | ||
|
|
||
| @Test | ||
| void CaseOutOfMemory_error() { | ||
| setInput("100500"); | ||
|
|
||
| new PyramidPrinter().run(); | ||
|
|
||
| removeFromOutput("Enter the pyramid height as a single integer: "); | ||
| assertEquals("Heap space is out of memory, please input a smaller integer", getOutput()); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/test/java/Homework_2/RandomCharsTest/RandomCharsTest.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,29 @@ | ||
| package Homework_2.RandomCharsTest; | ||
|
|
||
| import Homework_2.RandomCharsTable.RandomCharsTable; | ||
| import base.UnitBase; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| public class RandomCharsTest extends UnitBase { | ||
|
|
||
| @Test | ||
| void CaseStandard1_pass() { | ||
| setInput("2 2 even"); | ||
|
|
||
| new RandomCharsTable().run(); | ||
|
|
||
| printOut(); | ||
| removeFromOutput("Enter the sizes of a table and a strategy: "); | ||
| assertEquals("x", getOutputLines()[0]); | ||
| assertEquals("xx", getOutputLines()[1]); | ||
| assertEquals("Even Letters -", getOutputLines()[2]); | ||
|
|
||
| } | ||
|
|
||
| // |L|O| | ||
| // |Y|Z| | ||
|
|
||
|
|
||
| } |
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.
fix package names