Skip to content
This repository was archived by the owner on Oct 25, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
98fb73d
Update homework1
Margareeta Jul 12, 2021
5ca1c5e
Update README.md
Margareeta Jul 12, 2021
e8dd4be
Homework 1 corrected
Margareeta Jul 14, 2021
1cca363
Merge remote-tracking branch 'origin/feature/MargaritaSkorodnikova' i…
Margareeta Jul 14, 2021
a5ef4bc
Homework 1 corrected once more
Margareeta Jul 16, 2021
c3f0fa2
Homework 1 corrected and configurations changed
Margareeta Jul 16, 2021
6216411
Added closing color string
Margareeta Jul 17, 2021
961574f
Homework2 Traffic Light
Margareeta Jul 17, 2021
673a19b
Homework2 Pyramid Printer
Margareeta Jul 18, 2021
9564874
Update README.md
Margareeta Jul 18, 2021
10c934c
Cnanged the project structure
Margareeta Jul 20, 2021
28620f4
Merge remote-tracking branch 'origin/feature/MargaritaSkorodnikova' i…
Margareeta Jul 20, 2021
1fab958
Update README.md
Margareeta Jul 25, 2021
bf4876b
Changed the project structure, divided the projects into classes.
Margareeta Jul 25, 2021
0b97364
Makes and prints the table
Margareeta Jul 25, 2021
28f56f9
Makes and prints the table, calculates odds and evens. Misprints yet
Margareeta Jul 26, 2021
2283883
Merge branch 'master' into feature/MargaritaSkorodnikova
Margareeta Jul 30, 2021
743d12e
Added the run() method to each class, finished the Random Chars Table
Margareeta Aug 2, 2021
9c283dc
Merge remote-tracking branch 'origin/feature/MargaritaSkorodnikova' i…
Margareeta Aug 2, 2021
f1449cc
Update README.md
Margareeta Aug 2, 2021
73b3210
Added the run() method to each class, finished the Random Chars Table
Margareeta Aug 14, 2021
005a25b
Added Tests for all apps
Margareeta Aug 29, 2021
be2976e
Merge remote-tracking branch 'origin/feature/MargaritaSkorodnikova' i…
Margareeta Aug 30, 2021
65a147b
Update README.md
Margareeta Sep 6, 2021
06950fa
Update README.md
Margareeta Sep 6, 2021
0391edb
Update README.md
Margareeta Sep 6, 2021
d1f8468
Update README.md
Margareeta Sep 6, 2021
57a2ea9
Finished jUnitTests for RandomCharTable
Margareeta Sep 9, 2021
704c5b8
Merge remote-tracking branch 'origin/feature/MargaritaSkorodnikova' i…
Margareeta Sep 9, 2021
10d4d1b
Finished Immutable class
Margareeta Sep 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
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)
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ repositories {
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
// https://mvnrepository.com/artifact/org.projectlombok/lombok
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'

}

test {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/Homework1/Main.java
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.");
}
}
}
}

7 changes: 7 additions & 0 deletions src/main/java/Homework2/Pyramid_Printer/Main.java
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();
}
}
49 changes: 49 additions & 0 deletions src/main/java/Homework2/Pyramid_Printer/PyramidPrinter.java
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);
}
}

}



11 changes: 11 additions & 0 deletions src/main/java/Homework2/Random_Chars_Table/Main.java
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();
}
}
84 changes: 84 additions & 0 deletions src/main/java/Homework2/Random_Chars_Table/RandomCharsTable.java
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;
Copy link
Collaborator

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.

  1. max - min = delta (not max!!!)
  2. (Math.random() * ++max - Why the incrimination?

}

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& height >= 0 && length >= 0 ??????

verification is not correct.
height and length - set after verification. What is checked before?
height and length cannot be 0. (replace - \d+ ->>> [1-9]\d* or [1-9][0-9]*)

}

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(" | ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error! Space at the end of the line!
this will return:
|\\sA\\s|\\s

}
buildTable.append("\n");
}
System.out.println(buildTable);

System.out.println(getResult(strategy, rCT));
}

}



8 changes: 8 additions & 0 deletions src/main/java/Homework2/Traffic_Light/Main.java
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();
}
}
50 changes: 50 additions & 0 deletions src/main/java/Homework2/Traffic_Light/TrafficLight.java
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");
Copy link
Collaborator

Choose a reason for hiding this comment

The 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");
Copy link
Collaborator

Choose a reason for hiding this comment

The 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));
}
}








53 changes: 53 additions & 0 deletions src/main/java/Homework3/Immutable_Class_Task/Employee.java
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());


}
}

34 changes: 34 additions & 0 deletions src/main/java/Homework4/CustomFileReader/CustomFileReader.java
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);
}


}
11 changes: 11 additions & 0 deletions src/main/java/Homework4/CustomFileReader/Main.java
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();

}
}
Loading