-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/margarita skorodnikova #53
base: master
Are you sure you want to change the base?
Changes from all commits
98fb73d
5ca1c5e
e8dd4be
1cca363
a5ef4bc
c3f0fa2
6216411
961574f
673a19b
9564874
10c934c
28620f4
1fab958
bf4876b
0b97364
28f56f9
2283883
743d12e
9c283dc
f1449cc
73b3210
005a25b
be2976e
65a147b
06950fa
0391edb
d1f8468
57a2ea9
704c5b8
10d4d1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| # Java Core June 2021 | ||
|
|
||
| ## *Nikolaev Artem* | ||
| ## *Skorodnikova Margarita* | ||
|
|
||
| | 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/MargaritaSkorodnikova/src/main/java/Homework1) | The app that reads input arguments and prints them, until "error" argument | | ||
| | HW2 | [Traffic Light](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/MargaritaSkorodnikova/src/main/java/Homework2/Traffic_Light) | The app that reads input lines, checks them for digits, and calculates cycle of a traffic light and its color | | ||
| | HW2 | [Pyramid printer](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/MargaritaSkorodnikova/src/main/java/Homework2/Pyramid_Printer) | The app that reads input lines, turns them into numbers and prints a two-dimentional array of chars looking like a pyramid | | ||
| | HW2 | [Random Characters Table and Counter](https://github.com/NikolaevArtem/Java_Core_June_2021/tree/feature/MargaritaSkorodnikova/src/main/java/Homework2/Random_Chars_Table) | The app that reads input lines, defines the strategy, prints a table of random chars and calculates odd and even ones | | ||
|
|
||
| [Link to markdown giude](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) | ||
|
|
||
| [My CodingBat Page](https://codingbat.com/done?user=la.reine.m@gmail.com&tag=831576932) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package Homework1; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| final String RED_COLOR = "\u001b[31m"; | ||
| final String CLOSE_COLOR = "\u001B[0m"; | ||
|
|
||
| for (String s : args) { | ||
| if (s.equals("error")) { | ||
| System.out.println(RED_COLOR + "ALARM" + CLOSE_COLOR); | ||
| break; | ||
|
|
||
| } else { | ||
| System.out.println(s + ": " + s.length() + " letters."); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package Homework2.Pyramid_Printer; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| new PyramidPrinter().run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package Homework2.Pyramid_Printer; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class PyramidPrinter { | ||
| public static final char X = 'x'; | ||
| public static final char SPACE = ' '; | ||
|
|
||
| public char[][] getPyramidArray(int size) { | ||
| char pyramid[][] = new char[size][size]; | ||
|
|
||
| for (int i = 0; i < size; i++) { | ||
| for (int j = 0; j < size; j++) { | ||
| if (i < j) { | ||
| pyramid[i][j] = SPACE; | ||
| } else { | ||
| pyramid[i][j] = X; | ||
| } | ||
| } | ||
| } | ||
| return pyramid; | ||
| } | ||
|
|
||
| public void run (){ | ||
| int size = 0; | ||
| BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
| try(reader){ | ||
| size = Integer.parseInt(reader.readLine()); | ||
| } catch (IOException e) { | ||
| System.out.println("Some problem with input stream: " + e.getMessage()); | ||
| return; | ||
| } catch (NumberFormatException e){ | ||
| System.out.println("The line you entered is not valid"); | ||
| return; | ||
| } | ||
|
|
||
| char[][] pyramidArray = getPyramidArray(size); | ||
|
|
||
| for (char[] c : pyramidArray) { | ||
| System.out.println(c); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package Homework2.Random_Chars_Table; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
|
|
||
| new RandomCharsTable().run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package Homework2.Random_Chars_Table; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class RandomCharsTable { | ||
| int length = 0; | ||
| int height = 0; | ||
| String input = ""; | ||
|
|
||
| static char getRandomChar(int min, int max) { | ||
| max -= min; | ||
| char randomCh = (char) ((int) (Math.random() * ++max) + min); | ||
| return randomCh; | ||
| } | ||
|
|
||
| public static char[][] getRandomCharsTable(int length, int height) { | ||
| char[][] randomCharTable = new char[length][height]; | ||
| for (int i = 0; i < length; i++) { | ||
| for (int j = 0; j < height; j++) { | ||
| char ch = getRandomChar(65, 90); | ||
| randomCharTable[i][j] = ch; | ||
| } | ||
| } | ||
| return randomCharTable; | ||
| } | ||
|
|
||
| private boolean isValid(String input) { | ||
| return (input.matches("\\d+\\s\\d+\\sodd") || input.matches("\\d+\\s\\d+\\seven") | ||
| && height >= 0 && length >= 0); | ||
|
Collaborator
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. && height >= 0 && length >= 0 ?????? verification is not correct. |
||
| } | ||
|
|
||
| public String getResult(String strategy, char[][] rCT) { | ||
| StringBuilder buildResult = new StringBuilder(); | ||
| buildResult.append(strategy) | ||
| .append(" letters -"); | ||
|
|
||
| boolean strategyOdd = strategy.equals("odd"); | ||
|
|
||
| for (int i = 0; i < length; i++) { | ||
| for (int j = 0; j < height; j++) { | ||
| boolean isOdd = rCT[i][j] % 2 == 1; | ||
|
|
||
| if ((!strategyOdd && !isOdd) || (strategyOdd && isOdd)) { | ||
| buildResult.append(' ') | ||
| .append(rCT[i][j]); | ||
| } | ||
| } | ||
| } | ||
| return buildResult.toString(); | ||
| } | ||
|
|
||
| public void run() { | ||
| String strategy; | ||
| Scanner scanner = new Scanner(System.in); | ||
| input = scanner.nextLine(); | ||
|
|
||
| if (!isValid(input)) { | ||
| throw new IllegalArgumentException("The line you entered does not fit the pattern"); | ||
| } else { | ||
| String[] split = input.split("\\s"); | ||
| length = Integer.parseInt(split[0]); | ||
| height = Integer.parseInt(split[1]); | ||
| strategy = split[2]; | ||
| } | ||
|
|
||
| StringBuilder buildTable = new StringBuilder(); | ||
| char[][] rCT = getRandomCharsTable(length, height); | ||
|
|
||
| for (char[] ch : rCT) { | ||
| buildTable.append("| "); | ||
| for (char c : ch) { | ||
| buildTable.append(c).append(" | "); | ||
|
Collaborator
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. Error! Space at the end of the line! |
||
| } | ||
| buildTable.append("\n"); | ||
| } | ||
| System.out.println(buildTable); | ||
|
|
||
| System.out.println(getResult(strategy, rCT)); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package Homework2.Traffic_Light; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| new TrafficLight().run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package Homework2.Traffic_Light; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class TrafficLight { | ||
| final int END_OF_THE_DAY = 86399; | ||
|
|
||
| String getTrafficLight(int input) { | ||
| if (input < 0) { | ||
| throw new IllegalArgumentException("Error. You can't enter negative numbers"); | ||
|
|
||
| } else if (input > END_OF_THE_DAY) { | ||
| throw new IllegalArgumentException("Error. The day has come to an end"); | ||
|
Collaborator
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. output - Only 1 non-negative integer is allowed as passed parameter |
||
| } | ||
| int lightInterval = input % 60; | ||
| String light = ""; | ||
| if (lightInterval >= 0 && lightInterval < 35) { | ||
| light = "Green"; | ||
| } else if (lightInterval >= 35 && lightInterval < 40) { | ||
| light = "Yellow"; | ||
| } else if (lightInterval >= 40 && lightInterval < 55) { | ||
| light = "Red"; | ||
| } else if (lightInterval >= 55 && lightInterval < 60) { | ||
| light = "Yellow"; | ||
| } | ||
| return light; | ||
| } | ||
|
|
||
| public void run() { | ||
| int input = 0; | ||
| try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { | ||
| input = Integer.parseInt(reader.readLine()); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("Input does not contain numbers"); | ||
|
Collaborator
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. output - Only 1 non-negative integer is allowed as passed parameter! |
||
| } | ||
| System.out.println(getTrafficLight(input)); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package Homework3.Immutable_Class_Task; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public final class Employee { | ||
| private final String name; | ||
| private final int regNo; | ||
| private final Map<String, String> metadata; | ||
|
|
||
| public Employee(String name, int regNo, | ||
| Map<String, String> metadata) | ||
| { | ||
| this.name = name; | ||
| this.regNo = regNo; | ||
| Map<String, String> tempMap = new HashMap<>(); | ||
| for (Map.Entry<String, String> entry : | ||
| metadata.entrySet()) { | ||
| tempMap.put(entry.getKey(), entry.getValue()); | ||
| } | ||
| this.metadata = tempMap; | ||
| } | ||
|
|
||
| public String getName() { return new String(this.name); } | ||
|
|
||
| public int getRegNo() { return regNo; } | ||
|
|
||
| public Map<String, String> getMetadata() | ||
| { | ||
| Map<String, String> tempMap = new HashMap<>(); | ||
| for (Map.Entry<String, String> entry : | ||
| this.metadata.entrySet()) { | ||
| tempMap.put(entry.getKey(), entry.getValue()); | ||
| } | ||
| return tempMap; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class Main { | ||
| public static void main(String[] args) | ||
| { | ||
| Map<String, String> map = new HashMap<>(); | ||
| map.put("1", "first"); | ||
| map.put("2", "second"); | ||
| Employee s = new Employee("ABC", 101, map); | ||
| System.out.println(s.getName()); | ||
| System.out.println(s.getRegNo()); | ||
| System.out.println(s.getMetadata()); | ||
|
|
||
|
|
||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package Homework4.CustomFileReader; | ||
| /* | ||
| реализовать приложение, которое считывает данные из файла, и печатает в консоль, но уже без запятых и точек. | ||
| Файл положить в main/resources/custom_file_reader | ||
|
|
||
| в классе должно быть реализовано минимум три рабочих способа (один с помощью NIO) считывания данных из файла. | ||
| Соответственно публичные методы run1(), run2(), run3(), ... | ||
| */ | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.util.Scanner; | ||
|
|
||
| public class CustomFileReader { | ||
| String separator = File.separator; | ||
| String path = "C:"+ separator + "Users" + separator + "Daisy" + separator + "Documents" + separator + | ||
| "Epam training"+ separator + "Java_Core_June_2021" + separator +"src" + separator + "main" + separator | ||
| + "resources" + separator + "custom_file_reader" + separator + "text.txt"; | ||
| String text = ""; | ||
|
|
||
| File file = new File(path); | ||
|
|
||
| public void run1() throws FileNotFoundException { | ||
| Scanner scanner = new Scanner(file); | ||
| while (scanner.hasNextLine()) { | ||
|
|
||
| String text = scanner.nextLine(); | ||
| } | ||
| scanner.close(); | ||
| System.out.println(text); | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package Homework4.CustomFileReader; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) throws FileNotFoundException { | ||
| CustomFileReader reader = new CustomFileReader(); | ||
| reader.run1(); | ||
|
|
||
| } | ||
| } |
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.
this method is too confusing and not correct.