File tree Expand file tree Collapse file tree
main/java/ru/frechman/exercises/stepickAlt
test/java/ru/frechman/exercises/stepickAlt Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package ru .frechman .exercises .stepickAlt ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
6+ public class MainDepartment {
7+
8+ public static long calcNumberOfEmployees (List <Department > departments , long threshold ) {
9+ return departments .stream ()
10+ .filter (department -> department .getCode ().startsWith ("111-" ))
11+ .flatMap (department -> department .getList ().stream ())
12+ .filter (employee -> employee .salary >= threshold ).count ();
13+ }
14+
15+ class Employee {
16+
17+ String name ;
18+ long salary ;
19+
20+ public String getName () {
21+ return name ;
22+ }
23+
24+ public long getSalary () {
25+ return salary ;
26+ }
27+ }
28+
29+ class Department {
30+
31+ String code ;
32+ String name ;
33+ List <Employee > list = new ArrayList <>();
34+
35+ public String getCode () {
36+ return code ;
37+ }
38+
39+ public String getName () {
40+ return name ;
41+ }
42+
43+ public List <Employee > getList () {
44+ return list ;
45+ }
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ package ru .frechman .exercises .stepickAlt ;
2+
3+ import java .util .Scanner ;
4+
5+ public class Mkad {
6+
7+ public static void main (String [] args ) {
8+
9+ Scanner scanner = new Scanner (System .in );
10+ int v = scanner .nextInt ();
11+ int time = scanner .nextInt ();
12+
13+ System .out .println (Mkad .getDistance (v , time ));
14+ }
15+
16+ public static int getDistance (int v , int time ) {
17+ return v >= 0 ? Math .abs (v * time ) % 109 : Math .abs (109 - Math .abs (v * time ) % 109 ) % 109 ;
18+ }
19+
20+ }
Original file line number Diff line number Diff line change 1+ package ru .frechman .exercises .stepickAlt ;
2+
3+ import java .util .stream .LongStream ;
4+
5+ public class SumOddNumber {
6+
7+ public static long sumOfOddNumbersInRange (long start , long end ) {
8+ return LongStream .rangeClosed (start , end ).filter (x -> x % 2 != 0 ).sum ();
9+ }
10+
11+ }
Original file line number Diff line number Diff line change 1+ package ru .frechman .exercises .stepickAlt ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .junit .Assert .assertEquals ;
6+
7+ public class MkadTest {
8+
9+ @ Test
10+ public void one () {
11+ assertEquals (11 , Mkad .getDistance (60 , 2 ));
12+ }
13+
14+ @ Test
15+ public void two () {
16+ assertEquals (108 , Mkad .getDistance (-1 , 1 ));
17+ }
18+
19+ @ Test
20+ public void getS () {
21+ assertEquals (0 , Mkad .getDistance (109 , 1 ));
22+ }
23+
24+ @ Test
25+ public void test2 () {
26+ assertEquals (0 , Mkad .getDistance (109 , 1 ));
27+
28+ }
29+
30+ @ Test
31+ public void test3 () {
32+ assertEquals (0 , Mkad .getDistance (109 , 10 ));
33+
34+ }
35+
36+ @ Test
37+ public void test4 () {
38+ assertEquals (0 , Mkad .getDistance (-109 , 10 ));
39+ }
40+
41+ @ Test
42+ public void test5 () {
43+ assertEquals (47 , Mkad .getDistance (-990 , 1000 ));
44+ }
45+
46+ @ Test
47+ public void test6 () {
48+ assertEquals (0 , Mkad .getDistance (108 , 109 ));
49+ }
50+
51+ @ Test
52+ public void test11 () {
53+ assertEquals (0 , Mkad .getDistance (-108 , 109 ));
54+ }
55+
56+ @ Test
57+ public void test7 () {
58+ assertEquals (2 , Mkad .getDistance (107 , 108 ));
59+ }
60+
61+ @ Test
62+ public void test8 () {
63+ assertEquals (0 , Mkad .getDistance (109 , 108 ));
64+ }
65+ }
Original file line number Diff line number Diff line change 1+ package ru .frechman .exercises .stepickAlt ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .junit .Assert .*;
6+
7+ public class SumOddNumberTest {
8+
9+ @ Test
10+ public void sumOfOddNumbersInRange () {
11+ assertEquals (3 + 5 + 7 + 9 + 11 + 13 , SumOddNumber .sumOfOddNumbersInRange (3 , 13 ));
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments