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_Segodnik #28
Open
AntonSegodnik
wants to merge
39
commits into
master
Choose a base branch
from
feature/AntonSegodnik
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_Segodnik #28
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
bba4c50
AS commit
39cd05f
AS commit git ignore
26433ce
05.07 Home Work 1
c21fa4e
06.07.21 Home Work 1.1 with Red Color
12b4c21
AS commit
5c04832
05.07 Home Work 1
95720c0
homework_1
83dd7ba
Merge branch 'master' into feature/AntonSegodnik
ed9c6b0
homework_1 with red "Alarm" + read.me: added link to main
4df4686
homework_1 with red "Alarm" + read.me: added link to main and Name ch…
0788e6c
homework_2 with BufferReaders methods
df79a67
homework_2 with BufferReaders methods + Read me
3968d87
homework_2 with BufferReaders methods + Read me again
85299bd
homework_2 with hierarchy and run()
6a71478
homework_2 with hierarchy and run() + read.me
2ce4e3e
homework_3
07dfad9
Merge branch 'master' into feature/AntonSegodnik
2e7c00c
homework_3 + tests
b4a2b84
homework_3 + tests finish version
c092c42
homework_3 + fixed version
7667c80
homework_4 without annotation tests
2d78839
homework_4 without annotation tests
a1aff4b
homework_4 whithout read me
10b9e62
homework_4 all
1b68701
homework_5 all
5f57dd9
homework_5 with read me and correct packaging
f1f5ecc
homework_5 with read me and correct packaging + private methods
4cff6d5
homework_2 fixed, Random Chars Table wasn't fixed (not enough details)
53086af
homework_2 fix tests for new messages
4d3a9cc
homework_6 start
97eca5e
homework_6 finished
90a99eb
homework_6 finished + read me
de1a0bd
Fix 2 from Kirill
c11b05a
Final project w/o tests
04aa763
Final project with some tests
ac78bf6
Homework_7 added
a43f2d5
Fix hm 3, and "txts"
75f3deb
Fix hm 3, and "txts"
4ee8e31
fix 3 just public
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,22 @@ | ||
| # Java Core June 2021 | ||
|
|
||
| ## *Nikolaev Artem* | ||
| ## *Anton Segodnik* | ||
|
|
||
| | 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 | | ||
| |HW1 | [Console printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_1) | The app that reads input arguments and prints them, until "error" argument | | ||
| |HW2 | [pyramid_printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_2/pyramid_printer) | The app that reads input arguments and prints pyramid | | ||
| |HW2 | [random_chars_table](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_2/random_chars_table) | The app that reads input arguments and creates random table | | ||
| |HW2 | [traffic_light](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_2/traffic_light) | The app that reads input arguments and prints traffic light | | ||
| |HW3 | [immutable class](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_3) | The app that reads input arguments and prints traffic light | | ||
| |HW4 | [customAnnotation](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_4/customAnnotation) | The app create object with default value from constructor using annotation | | ||
| |HW4 | [customFileReader](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_4/customFileReader) | The app that reads from file | | ||
| |HW4 | [singleton](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_4/singleton) | The singleton app | | ||
| |HW5 | [customRegexMatcher](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_5/customRegexMatcher) | The app | | ||
| |HW5 | [PowerOfNumber](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_5/PowerOfNumber) | The app | | ||
| |HW6 | [MapProblemsCollisionGenerator](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_6/MapProblemsCollisionGenerator) | The app | | ||
| |HW6 | [MapProblemsMutableGenerator](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_6/MapProblemsMutableGenerator) | The app | | ||
| |HW7 | [KittenToCatFunction](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/AntonSegodnik/src/main/java/homework_7) | The app | | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | | ||
| [Link to CodingBat](https://codingbat.com/done?user=segodnik@gmail.com&tag=8130222420) | ||
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
Empty file.
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,92 @@ | ||
| package SeaBattle; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class GenerateShips { | ||
|
|
||
| static int FIELD_SIZE = 10; | ||
|
|
||
| public char[][] createBoardWithShips() { | ||
| GenerateShips generateShips = new GenerateShips(); | ||
| int[][] field = new int[FIELD_SIZE][FIELD_SIZE]; | ||
| generateShips.fillField(field, 4); | ||
| generateShips.fillField(field, 3); | ||
| generateShips.fillField(field, 3); | ||
| generateShips.fillField(field, 2); | ||
| generateShips.fillField(field, 2); | ||
| generateShips.fillField(field, 2); | ||
| generateShips.fillField(field, 1); | ||
| generateShips.fillField(field, 1); | ||
| generateShips.fillField(field, 1); | ||
| generateShips.fillField(field, 1); | ||
|
|
||
| char map[][] = new char[FIELD_SIZE][FIELD_SIZE]; | ||
| for(int i = 0; i < FIELD_SIZE; i++) { | ||
| for(int j = 0; j < FIELD_SIZE; j++) { | ||
| map[i][j] = field[i][j] == 0 || field[i][j] == 9 ? '_' : '0'; | ||
| } | ||
| } | ||
| return map; | ||
| } | ||
|
|
||
| void fillField(int [][] fields, int shipLength) { | ||
|
|
||
| Random random = new Random(); | ||
| int[][] field = fields; | ||
| while(true) { | ||
| int x = random.nextInt(field.length); | ||
| int y = random.nextInt(field.length); | ||
| boolean vertical = random.nextBoolean(); | ||
|
|
||
| if(vertical) { | ||
| if(y + shipLength > FIELD_SIZE) { | ||
| y -= shipLength; | ||
| } | ||
| } else if(x + shipLength > FIELD_SIZE) { | ||
| x -= shipLength; | ||
| } | ||
| boolean isFree = true; | ||
| if(vertical) { | ||
| for(int m = y; m < y + shipLength; m++) { | ||
| if(field[m][x] != 0) { | ||
| isFree = false; | ||
| break; | ||
| } | ||
| } | ||
| } else { | ||
| for(int n = x; n < x + shipLength; n++) { | ||
| if(field[y][n] != 0) { | ||
| isFree = false; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| if(!isFree) { | ||
| continue; | ||
| } | ||
|
|
||
| if(vertical) { | ||
| for(int m = Math.max(0, x - 1); m < Math.min(FIELD_SIZE, x + 2); m++) { | ||
| for(int n = Math.max(0, y - 1); n < Math.min(FIELD_SIZE, y + shipLength + 1); n++) { | ||
| field[n][m] = 9; | ||
| } | ||
| } | ||
| } else { | ||
| for(int m = Math.max(0, y - 1); m < Math.min(FIELD_SIZE, y + 2); m++) { | ||
| for(int n = Math.max(0, x - 1); n < Math.min(FIELD_SIZE, x + shipLength + 1); n++) { | ||
| field[m][n] = 9; | ||
| } | ||
| } | ||
| } | ||
| for(int j = 0; j < shipLength; j++) { | ||
| field[y][x] = shipLength; | ||
| if(vertical) { | ||
| y++; | ||
| } else { | ||
| x++; | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } |
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,23 @@ | ||
| package SeaBattle; | ||
|
|
||
| public interface InputValidator { | ||
|
|
||
| static boolean isInvalidInputData(int col, int row, char[][] board) { | ||
| if(row < 0 || row > 9) { | ||
| System.out.println("Invalid input, allowed values like 'a5'"); | ||
| return true; | ||
| } else if(col == -1) { | ||
| System.out.println("Invalid input, please repeat input "); | ||
| return true; | ||
| } else if(board[row][col] == 'x' || board[row][col] == 'X') { | ||
| System.out.println("Already bombed, please repeat input "); | ||
| return true; | ||
| } else if(board[row][col] == '0') { | ||
| System.out.println("HIT!"); | ||
| board[row][col] = 'X'; | ||
| } else { | ||
| board[row][col] = 'x'; | ||
| } | ||
| return false; | ||
| } | ||
| } |
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,10 @@ | ||
| package SeaBattle; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| StartGame startGame = new StartGame(); | ||
|
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. Looks like a fresh view on the course project, fits the requirement, but doesn't look good, not from the interface and not from the code. You show knowledge in Java Core, I don't see much architecture or right abstractions in the app. Playing is nice though, but x for miss and X for hit looks awful... Approved! |
||
| startGame.startGame(); | ||
| } | ||
| } | ||
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 SeaBattle; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import static SeaBattle.StartGame.currentCountOfShots; | ||
|
|
||
| interface PrintArray { | ||
|
|
||
| static void printBoard(char[][] map) { | ||
| AtomicInteger i = new AtomicInteger(1); | ||
| System.out.println("Current board: x - miss, X - HIT!, Current Round = " + currentCountOfShots + "\n A B C D E F G H I J "); | ||
| Arrays.stream(map) | ||
| .forEach(m -> System.out.println( i.getAndIncrement() + " " + Arrays.toString(m).replace(",", "").replace("0", "_"))); | ||
| } | ||
| } |
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,44 @@ | ||
| package SeaBattle; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| import static SeaBattle.InputValidator.isInvalidInputData; | ||
| import static SeaBattle.WinnerChecker.isWinnerExist; | ||
|
|
||
| public class StartGame { | ||
|
|
||
| private static final String LETTERS = "ABCDEFGHIJ"; | ||
| static final int COUNT = 70; | ||
| static int currentCountOfShots = 0; | ||
|
|
||
| public void startGame() { | ||
| System.out.println("Game on! \n You should shoot all ships in " + COUNT + " rounds"); | ||
| GenerateShips test = new GenerateShips(); | ||
| char[][] board = test.createBoardWithShips(); | ||
|
|
||
| while(true) { | ||
| PrintArray.printBoard(board); | ||
|
|
||
| Scanner in = new Scanner(System.in); | ||
| try { | ||
| String playerChoice = in.next(); | ||
|
|
||
| int col = LETTERS.indexOf(playerChoice.toUpperCase().charAt(0)); | ||
| int row = Integer.parseInt(playerChoice.substring(1)) - 1; | ||
|
|
||
| if(isInvalidInputData(col, row, board)) { | ||
| continue; | ||
| } | ||
| currentCountOfShots++; | ||
|
|
||
| if(isWinnerExist(board, currentCountOfShots)) { | ||
| return; | ||
| } | ||
|
|
||
| } catch(NumberFormatException e) { | ||
| System.out.println("Invalid input, please enter in format e.g. 'A5'"); | ||
| in.next(); | ||
| } | ||
| } | ||
| } | ||
| } |
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,20 @@ | ||
| package SeaBattle; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import static SeaBattle.StartGame.COUNT; | ||
|
|
||
| public interface WinnerChecker { | ||
|
|
||
| static boolean isWinnerExist(char[][] board, int currentShot) { | ||
| if(Arrays.stream(board).flatMap((item)->new String(item).chars().mapToObj(a->(char)a)).noneMatch(e -> e == '0')){ | ||
| System.out.println("Game Over, you are winner !!!"); | ||
| return true; | ||
| } | ||
| if(COUNT <= currentShot){ | ||
| System.out.println("Your shells are out, try again"); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } |
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,18 @@ | ||
| package homework_1; | ||
|
|
||
| public class Main { | ||
| public static final String ANSI_RESET = "\u001B[0m"; | ||
| public static final String ANSI_RED = "\u001B[31m"; | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("Hello homework!"); | ||
|
|
||
| for (String i: args) { | ||
| if(i.equals("error")){ | ||
| System.out.println(ANSI_RED + "Alarm!" + ANSI_RESET); | ||
| break; | ||
| } | ||
| System.out.println(i + ": " + i.length()); | ||
| } | ||
| } | ||
|
|
||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/homework_2/pyramid_printer/InputPyramidReader.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,24 @@ | ||
| package homework_2.pyramid_printer; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class InputPyramidReader { | ||
|
|
||
| public int bufferReaderForPyramid() { | ||
| try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { | ||
| int i = Integer.parseInt(reader.readLine()); | ||
| if(i < 0) { | ||
| System.out.println("Error, negative numbers are not valid"); | ||
| } else { | ||
| return i; | ||
| } | ||
| } catch(NumberFormatException ex) { | ||
| System.out.println("Error, only numbers are allowed"); | ||
| } catch(IOException e) { | ||
| System.out.println("System Error"); | ||
| } | ||
| return 0; | ||
| } | ||
| } |
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,11 @@ | ||
| package homework_2.pyramid_printer; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| PyramidPrinter pyramidPrinter = new PyramidPrinter(); | ||
| pyramidPrinter.run(); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
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,16 @@ | ||
| package homework_2.pyramid_printer; | ||
|
|
||
| public class PyramidPrinter { | ||
|
|
||
| public void run() { | ||
| InputPyramidReader IOHelperForPyramid = new InputPyramidReader(); | ||
| int pyramidLength = IOHelperForPyramid.bufferReaderForPyramid(); | ||
|
|
||
| for(int i = 0; i < pyramidLength; i++) { | ||
| for(int j = 0; j <= i; j++) { | ||
| System.out.print("x"); | ||
| } | ||
| System.out.println(); | ||
| } | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/homework_2/random_chars_table/InputData.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,14 @@ | ||
| package homework_2.random_chars_table; | ||
|
|
||
| public class InputData { | ||
|
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. Looks good |
||
|
|
||
| public int row; | ||
| public int column; | ||
| public String type; | ||
|
|
||
| public InputData(int row, int column, String type) { | ||
| this.row = row; | ||
| this.column = column; | ||
| this.type = type; | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/main/java/homework_2/random_chars_table/InputRandomCharsReader.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,17 @@ | ||
| package homework_2.random_chars_table; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class InputRandomCharsReader { | ||
|
|
||
| public String bufferReaderConsoleForRandom() { | ||
| try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { | ||
| return reader.readLine(); | ||
| } catch(IOException ex) { | ||
| System.out.println("System Error"); | ||
| return ""; | ||
| } | ||
| } | ||
| } |
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,11 @@ | ||
| package homework_2.random_chars_table; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| RandomCharsTable randomCharsTable = new RandomCharsTable(); | ||
| randomCharsTable.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,9 @@ | ||
| package homework_2.random_chars_table; | ||
|
|
||
| public class ParserError extends Exception { | ||
|
|
||
| public ParserError(String errorMessage) { | ||
| super(errorMessage); | ||
| } | ||
| } | ||
|
|
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.
Nice description...