From f093756c8e5ea4e7ed44209ae3d1f99255c93b85 Mon Sep 17 00:00:00 2001 From: Militaryus Date: Tue, 29 Dec 2020 03:20:55 +0200 Subject: [PATCH 1/5] hw_6 --- lesson_6/.idea/.gitignore | 2 + lesson_6/.idea/misc.xml | 6 + lesson_6/.idea/modules.xml | 8 + lesson_6/.idea/vcs.xml | 6 + lesson_6/lesson_6.iml | 11 ++ .../lesson_6/META-INF/lesson_6.kotlin_module | Bin 0 -> 16 bytes lesson_6/out/production/lesson_6/Main.class | Bin 0 -> 4288 bytes lesson_6/src/Main.java | 155 ++++++++++++++++++ 8 files changed, 188 insertions(+) create mode 100644 lesson_6/.idea/.gitignore create mode 100644 lesson_6/.idea/misc.xml create mode 100644 lesson_6/.idea/modules.xml create mode 100644 lesson_6/.idea/vcs.xml create mode 100644 lesson_6/lesson_6.iml create mode 100644 lesson_6/out/production/lesson_6/META-INF/lesson_6.kotlin_module create mode 100644 lesson_6/out/production/lesson_6/Main.class create mode 100644 lesson_6/src/Main.java diff --git a/lesson_6/.idea/.gitignore b/lesson_6/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/lesson_6/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/lesson_6/.idea/misc.xml b/lesson_6/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/lesson_6/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lesson_6/.idea/modules.xml b/lesson_6/.idea/modules.xml new file mode 100644 index 0000000..e60485c --- /dev/null +++ b/lesson_6/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/lesson_6/.idea/vcs.xml b/lesson_6/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/lesson_6/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lesson_6/lesson_6.iml b/lesson_6/lesson_6.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/lesson_6/lesson_6.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/lesson_6/out/production/lesson_6/META-INF/lesson_6.kotlin_module b/lesson_6/out/production/lesson_6/META-INF/lesson_6.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..a49347afef10a9b5f95305e1058ba36adec7d6dd GIT binary patch literal 16 RcmZQzU|?ooU|@t|0RRA102TlM literal 0 HcmV?d00001 diff --git a/lesson_6/out/production/lesson_6/Main.class b/lesson_6/out/production/lesson_6/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..45fb38a68de1ff4642e2ad2bd55cd56d137074de GIT binary patch literal 4288 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 literal 0 HcmV?d00001 diff --git a/lesson_6/src/Main.java b/lesson_6/src/Main.java new file mode 100644 index 0000000..6c10414 --- /dev/null +++ b/lesson_6/src/Main.java @@ -0,0 +1,155 @@ +public class Main { + public static void main(String[] args) { + // 1) Создайте программу, выводящую на экран все четырёхзначные + // числа последовательности 1000 1003 1006 1009 1012 1015 …. + taskOne(); + // 2) Создайте программу, выводящую на экран первые 55 элементов + // последовательности 1 3 5 7 9 11 13 15 17 …. + taskTwo(); + // 3) Создайте программу, выводящую на экран все неотрицательные элементы + // последовательности 90 85 80 75 70 65 60 …. + taskThree(); + // 4) Создайте программу, выводящую на экран первые 20 элементов + // последовательности 2 4 8 16 32 64 128 …. + taskFour(); + // 5) Найти сумму первых n элементов массива + int n = 5; + int[] arr = new int[]{200, 100, -3, 400, 2, 600, 1, 100, 150, -9, 10, 23, 40, 56, 100}; + taskFive(arr, n); + // 6) Найти минимальный и максимальный элемент массива + taskSix(arr); + // 7) Найти сумму всех четных и сумму всех нечетных элементов массива + taskSeven(arr); + // 8) Найти все счастливые билеты от 100000 до 999999 : + // билет счастливый если сумма первых трех цифр равна сумме трех последних + // например, 123312: 1+2+3==3+1+2 + taskEight(); + // 9) Создайте программу которая устанавливает введеный номер бита в 1 у введенного числа, + // выведите на экран полученое число в двоичной и десятеричной системе счисления + taskNine(8, 10); + // 10) Вывести первые 5 минимальных элементов массива + taskTen(arr); + } + + public static void taskOne() { + System.out.println("TASK 1"); + for (int i = 1000; i < 10000; i += 3) { + System.out.println(i); + } + } + + public static void taskTwo() { + System.out.println("TASK 2"); + int counter = 0; + for (int i = 1; ; i += 2) { + System.out.println(i); + counter++; + if (counter == 55) { + break; + } + } + } + + public static void taskThree() { + System.out.println("TASK 3"); + for (int i = 90; i >= 0; i -= 5) { + System.out.println(i); + } + } + + public static void taskFour() { + System.out.println("TASK 4"); + int startNumber = 2; + int counter = 0; + for (int i = 0; ; i++) { + System.out.println(startNumber << i); + counter++; + if (counter == 20) { + break; + } + } + } + + public static void taskFive(int array[], int n) { + System.out.println("TASK 5"); + int sumElements = 0; + for (int i = 0; i < n; i++) { + sumElements += array[i]; + } + System.out.println(sumElements); + } + + public static void taskSix(int array[]) { + System.out.println("TASK 6"); + int minElement = array[0]; + int maxElement = array[0]; + for (int i = 1; i < array.length; i++) { + if (array[i] <= minElement) { + minElement = array[i]; + } + if (array[i] >= maxElement) { + maxElement = array[i]; + } + } + System.out.println("Minimal element of array: " + minElement); + System.out.println("Maximal element of array: " + maxElement); + } + + public static void taskSeven(int array[]) { + System.out.println("TASK 7"); + int sumEvenElements = 0; + int sumOddElements = 0; + for (int element : array) { + if (element % 2 == 0) { + sumEvenElements += element; + } else { + sumOddElements += element; + } + } + System.out.format("Even elements sum: %d\n", sumEvenElements); + System.out.format("Odd elements sum: %d\n", sumOddElements); + } + + public static void taskEight() { + System.out.println("TASK 8"); + int luckyTicketCounter = 0; + for (int ticketNumber = 100_000; ticketNumber <= 999_999; ticketNumber++) { + int leftPartSum = ticketNumber / 100_000 + (ticketNumber / 10_000) % 10 + (ticketNumber / 1_000) % 10; + int rightPartSum = (ticketNumber / 100) % 10 + (ticketNumber / 10) % 10 + ticketNumber % 10; + if (leftPartSum == rightPartSum) { + luckyTicketCounter++; + } + } + System.out.println("The number of lucky tickets: " + luckyTicketCounter); + } + + public static void taskNine(int bitNumber, int number) { + System.out.println("TASK 9"); + int binaryBitNumber = (int) Math.pow(2, (bitNumber - 1)); + int result = number | binaryBitNumber; + System.out.println("Entered bit number: " + bitNumber); + System.out.println("Entered number: " + Integer.toBinaryString(number)); + System.out.println("Switched bit number: " + Integer.toBinaryString(result)); + System.out.println("Decimal result: " + result); + } + + public static void taskTen(int array[]) { + System.out.println("TASK 10"); + boolean sorted = false; + int temp; + while (!sorted) { + sorted = true; + for (int i = 0; i < array.length - 1; i++) { + if (array[i] > array[i + 1]) { + sorted = false; + temp = array[i]; + array[i] = array[i + 1]; + array[i + 1] = temp; + } + } + } + for (int i = 0; i < 5; i++) { + System.out.println(array[i]); + } + } +} From 10275e0af441d5860451200653a1df64d3845c31 Mon Sep 17 00:00:00 2001 From: Militaryus Date: Tue, 29 Dec 2020 04:25:54 +0200 Subject: [PATCH 2/5] lesson_7 --- AlexSubbotin/lesson_7/.idea/.gitignore | 2 + AlexSubbotin/lesson_7/.idea/misc.xml | 6 + AlexSubbotin/lesson_7/.idea/modules.xml | 8 + AlexSubbotin/lesson_7/.idea/vcs.xml | 6 + AlexSubbotin/lesson_7/Flashlights.jar | Bin 0 -> 8796 bytes AlexSubbotin/lesson_7/lesson_7.iml | 11 ++ .../out/production/lesson_7/Flashlights.class | Bin 0 -> 1942 bytes .../lesson_7/FlashlightsProperties.class | Bin 0 -> 2442 bytes .../out/production/lesson_7/Gearboxes.class | Bin 0 -> 2571 bytes .../lesson_7/GearboxesOperation.class | Bin 0 -> 1948 bytes .../lesson_7/GearboxesProperties.class | Bin 0 -> 1558 bytes .../out/production/lesson_7/Phones.class | Bin 0 -> 838 bytes .../lesson_7/PhonesProperties.class | Bin 0 -> 4127 bytes AlexSubbotin/lesson_7/src/Flashlights.java | 23 +++ .../lesson_7/src/FlashlightsProperties.java | 65 ++++++++ AlexSubbotin/lesson_7/src/Gearboxes.java | 42 +++++ .../lesson_7/src/GearboxesOperation.java | 51 ++++++ .../lesson_7/src/GearboxesProperties.java | 46 ++++++ AlexSubbotin/lesson_7/src/Phones.java | 16 ++ .../lesson_7/src/PhonesProperties.java | 147 ++++++++++++++++++ 20 files changed, 423 insertions(+) create mode 100644 AlexSubbotin/lesson_7/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_7/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_7/.idea/modules.xml create mode 100644 AlexSubbotin/lesson_7/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_7/Flashlights.jar create mode 100644 AlexSubbotin/lesson_7/lesson_7.iml create mode 100644 AlexSubbotin/lesson_7/out/production/lesson_7/Flashlights.class create mode 100644 AlexSubbotin/lesson_7/out/production/lesson_7/FlashlightsProperties.class create mode 100644 AlexSubbotin/lesson_7/out/production/lesson_7/Gearboxes.class create mode 100644 AlexSubbotin/lesson_7/out/production/lesson_7/GearboxesOperation.class create mode 100644 AlexSubbotin/lesson_7/out/production/lesson_7/GearboxesProperties.class create mode 100644 AlexSubbotin/lesson_7/out/production/lesson_7/Phones.class create mode 100644 AlexSubbotin/lesson_7/out/production/lesson_7/PhonesProperties.class create mode 100644 AlexSubbotin/lesson_7/src/Flashlights.java create mode 100644 AlexSubbotin/lesson_7/src/FlashlightsProperties.java create mode 100644 AlexSubbotin/lesson_7/src/Gearboxes.java create mode 100644 AlexSubbotin/lesson_7/src/GearboxesOperation.java create mode 100644 AlexSubbotin/lesson_7/src/GearboxesProperties.java create mode 100644 AlexSubbotin/lesson_7/src/Phones.java create mode 100644 AlexSubbotin/lesson_7/src/PhonesProperties.java diff --git a/AlexSubbotin/lesson_7/.idea/.gitignore b/AlexSubbotin/lesson_7/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_7/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/AlexSubbotin/lesson_7/.idea/misc.xml b/AlexSubbotin/lesson_7/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/AlexSubbotin/lesson_7/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_7/.idea/modules.xml b/AlexSubbotin/lesson_7/.idea/modules.xml new file mode 100644 index 0000000..d2a0eb2 --- /dev/null +++ b/AlexSubbotin/lesson_7/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_7/.idea/vcs.xml b/AlexSubbotin/lesson_7/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_7/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_7/Flashlights.jar b/AlexSubbotin/lesson_7/Flashlights.jar new file mode 100644 index 0000000000000000000000000000000000000000..8a38d2b66aa5414c1fd49c895cb90084ee0d25a7 GIT binary patch literal 8796 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 literal 0 HcmV?d00001 diff --git a/AlexSubbotin/lesson_7/lesson_7.iml b/AlexSubbotin/lesson_7/lesson_7.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/AlexSubbotin/lesson_7/lesson_7.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_7/out/production/lesson_7/Flashlights.class b/AlexSubbotin/lesson_7/out/production/lesson_7/Flashlights.class new file mode 100644 index 0000000000000000000000000000000000000000..80a5d46069947e86edbb31e5d11acac8def63e2c GIT binary patch literal 1942 zcmaJ>e^(nt6up}SHc6KP;YSs1r7f)iDo9mon-(q6Ks5Z&Ahp(CLl}~U&2HSCK+*5u z-+m2yH0`11_yPP-9`9^YvN@n9=ghqK_RW3w-Fcb6|2g>!z#aUO#$_y+xSd7}3n}#B zJrnPzxi2K~fetPvaYyeTCUIBq_Yx1E0@})@aUTz~wWJSxl)}e&sNLlZu?uOeU{$-t z3=HkY@Og$yXsu-s$A*q=n)t#%y5V~b=_^|X1}>EfjtFXwU9G8L^YlZ`K>vN)wbhb= zcy@Z*KqBw$N&|x>+m-9h`i}Is#E!#ArsP$Gvn_mE`<-Ay)oh{(fa!msk!$T^=`de8O))uqcwgC~0;L)o5+8Z*6j+8~{>*Yqp0 zU~A?>U94bE^RY0As|Lm*@vbBmuHY>L7a||2&2n+Y!j~vhud?kNO5ehk_EO7sbu#by zjX4Wnp=@Crk4$`R;W56k@C4slxP^C2d}rZ%{9xfn2ohTMJQXNkG}ff5dAq@2KX#I+ zSlER$v1g&Gp=uCG*cSHneqg~tJqcGQc@`SFgQ2dv8$0{5q70aURO_P7w#TyPi=Sdf z-g77rm8HEV+~%IBsHQI&NiwqO+Z6&NvIQ;daJNX&Rk9jpHH05Xy8lt8Xy9U_sW#kY zp_KH)5lm!@8ZN@Qd>klQr@CHK1GVYe-aPBOisK?hox@~SUv)H^oj%)A8b5)&Gu``| zblLyCNrO{g7Y8!$xfP)v*{Vh>P{LIly_@HWa~7O48g}1Hik!lUbU5RKWY??UM1)B_ zqHV}1#q?L=k46$J;e~`LNv3pefPcw?foLA^7}4n})=SB1Ol z$Y82{Fn3nONTlcB)^S6glOBB(+Ebm2_Su2R3&$zjO6E-bY~aS3{?6lO;L88!;VK{9 z%Y11K{`d^giqqn2!Sx!wrO*e4W}d^Cd5PHL=ZOD_#P9qT!*#Cu{nh6a+^1++w3&|^ zxXC?*w~_5&{YosIyYv!$gy}EM{((fsY#|vMsTR_qaiIk(GzMC@sEwKU?H3qqVQBUR zhP#!oAxX48uKgH>i3wWQS@9M*-6f9)7zi1Sx2s|rGt5t75wqmRH&eemJnBUojL4U9!} p+r(U`TO9Muj^SM#a!-?+!c#O^E>C}gYJbAmr{VfpxR%0o{a^P|*JJZBye^6n+AwNlT%ST|k$0jlv=nq%N$o(sftpQmB@f;9!} zVofV}Ce{rhGBP&Bx}_i+!DskfrQ>cCd)OE1=R)L#I1u6s8HW=3pKm;qpytl>mwM9D z?P4u1SOMO%Wq|OHYJ2?z08xyvF>?>YZ_Gv zQkLqXfz2xs0V(OO{zIdDT7FsTi(DEKFgzQuB80 z^)|ZDY*t(|YWuNwPdknx7bUY$+VqhR~1a0inT#(G{5!(HLGy5o4-h2x%+m5W-&aW#_C^%gYtR a!NQV8<+9cy zA&)FWuNsRoj$-%{Ur88QcO0+kxq4;W@Jh}}H6F&-3SPwU4ZfA}T@2r2F@`qDnHR-QzQ(;9XJWFRPwWCVib655^jeHk~A^X?q+cLocVI_yIa8+|E)H1G1_~ zX}|l>qVqnKESJYN{}l8fo01$7D=8;m~JOx+Ap1RBN+9@ z?HP`w<6g=raVT?+b6%@(ShKcmxM{Y(DrWn~PDnwFMm@K5`@}M;(+$Veb(kHRD~<=3 z6{Cmwiw^rn)l;2A6og3YmX$X>BPGL>aQ|9%~8Rf6!7}r7ia(*bMxZ9?`#C0O^7o>#RS4V$B z4b?G_P{Vb|zx$5Ulqy1${8-W3n<@NrPic59~UP`iPo2;}h%Kvu~E(V7%38g1@ujrwa>Yo7K1 c(vMGkt0yqHMj57nB2GBWIqntixB2Y+2X)=l@Bjb+ literal 0 HcmV?d00001 diff --git a/AlexSubbotin/lesson_7/out/production/lesson_7/Gearboxes.class b/AlexSubbotin/lesson_7/out/production/lesson_7/Gearboxes.class new file mode 100644 index 0000000000000000000000000000000000000000..e51851c05e5ea9c2ebc5391b00aa90def93fd3ce GIT binary patch literal 2571 zcmaJ@3s)0Y5dJnqHpJy&0HOF=6*W96T3fB6R-uB}AZVymw2vjZz)G?kcQ+Q=+Sb0` z?}vTCdCLc2@=H#DbB?(uVX>l*>UW_4M`TI=bR*YNgN%nhIqkq z3&IO*;cIA5jS9<~b(e%cS=k=c&>&T;z;+!CZB?C#)m^I8pR^r2IIW>B*>gohblA-b z4b3Ur5f_X3S>a7tvpMc0Qf|h|U9mh{%H_>yuwe80%~jX*7|mNY@7tQZmbzixvIcUN zGe3|HJlmNcR99HuJdIj6IM!gy*`6Piv(eD#i;U}JtMYu9=Vjp+bAg7YWX;vmxn5Qv z=VvU(5gu;}<0uApZXg|QGR(Nt3{%vg4G}EAAVfADhyoAOZqdt#5nHC-RK8yL2W3JA z4q|{_E4x+54fLXqSXGWHNE_(Kqr9VXqG8hot6(_>3b?6+AmbYFq)>n1@S!8e#|-$m zX&^w+z%9INU`dieoMdvN!pmFEGD|-*VvcyW$a;2W!C$cEgkzo^(!@!%kqvI_DZ_8WX!R;8{HSnHX-#739 zJ~Z$ViW-hhxn@=b41hgi1`EQ>TT6Dnm^T%G{ibkus1D`{vFWHbI$>(qqWYn>4hBBP zClb(44Sa^r4SXR}{8DmX;cEt4?VyR-8zRG!xB6nWKZHN*7M;M8FeEo_w$57Zamy*r zS(%{d$+l>zJ-TS+S!ua7wOkNqi-DWx++^6z$r;&K@+54Qi8)zAHgGgKBu@;Uq^q4% z6LEUk4@91m7RdR5*ixp&;IXTJI2-hOmu^J6qu>!1$ zs4|oFf(D;0aXo!W^@tvHDA2oDWJJEJ-xr?Iwq=nFr zu&Z2eS;x;bO}Xx3k&lQmCf}dooaOuSk-l47kFt+&1kYPeHYfb<&~R{ljcRt*7)r!8 zP_KPi!?78xZK<-0VJnwQ+kqI=@r#Ci>+;(uHVr%fUk|(a0qo(&F2X-PhNO^BA88%G zd3-rZ4^bLdGO(@p0kqzSh+KVuy8DQd-9)zjKJ?$H7QtcCCMrt@QU03w34Dx_K}R&l z5j@Vd0Z-s)+4aA)lKOWZB1TsYslMM4O~gystQez&M#VIh&@7p{5?Z+GdI?+P+R{}* zqVEs1mhH#;rF|Ri71K_8#cZX$WTLd^s_f<3vX}P#w67*Gf-MXv#$N-uIJ&SIdznHX z8ks;7PND^8kidDg;u6|0gLY)F6^rQLN1&50cNg1myGq;)ljHv`Pb#0wI8F#O+8)OV zauNFHN1_bI-wHI~_C0j;GT0J2SMUf>LRV#H+X`K;+1aszooYv#gl4-+Flmw4P0NSa zbM+qfK0tS>uY`T4sG)B!VZU5UIB;6YJ1Ta`Di8;mIIxSUn&@V;9OeHvPZNq1rD^QL zb?iqL2arRON%yFPdzk_gz$sPfX=gU+3QQiq0yU{SO$OgCqa| literal 0 HcmV?d00001 diff --git a/AlexSubbotin/lesson_7/out/production/lesson_7/GearboxesOperation.class b/AlexSubbotin/lesson_7/out/production/lesson_7/GearboxesOperation.class new file mode 100644 index 0000000000000000000000000000000000000000..9be6fccd2c7d546242f0c4f25f244887bca19403 GIT binary patch literal 1948 zcmaKsU2hvj6o%hP9Ix%Hn>49YARl!~8XQCI7Mk+mG=NRh2An$JDu{A5afW0Yd)L~X zRLRfa4t@a=;s!*iRHWX+k3zgNYaBOmx!9SVGiT0u-ZN+S?|+`Z0PsGV8Dvp%P|jck zr8HdJNaH5no#O883>`j5;X`Bo$P5)TtU0*jU|k^74TG)YMs;cjrOqV2x9 zB9QfuI=d=td}p@lC#nMJsH@aoQ>!k6?9=|h`UoV~Jm1p{Jz7}V5lGa6JtZ(v_k0z* zJe0d_TBhnjOSX4p=$UoTn9v6v6I?n4X^>88FYw86p(Br*CT+tvB+ON)Rv(!xW0r*o!8TsHRYJ@fq$q*l=+V_XXze`dWo~nQsMQs9HL| z&&2t-1SJ=fxaeZa4AZ#C3+w0YV=QKo}C4)_TE^uW_9($dmPTt;R-t+S!#u53$PWhn3vUKF3ss(;a>aRV0z_&aovQQvC&8gA$Dw12 z4cXE`c;etoc49pU4v+XPxSPJO!dhEKk@=*47|hU%5#Pyu>F>2wv=kq#oCg`OymZj? z^$_=O2mIr!s0`Mm7osNH?WU(y#lcqs*Usr1#wM`v|9)8HFD1*rO@a>_k>iNz9y_yv z?93kGoC3dYh}2wa@B2HmKXZvS>jxw`FAsZW=MHWse#6*oF7e!W{Q>7EjMFfc z;;TU!g+aMWcpy!b496^PP{=B!)F@?xa1V%N5N{D19fgEY3bf`fOq5nQOsjor%5rxsq72xp>Kx9hbYz z*_3;%_&d_S@MXjbOIqXNKz+yh^?hqNNaifaHG(X^0;JFbSs4nFISaBf6r?yDWc)11 vb%K;$0aEONygd|T{4B`LAt0l8$JXsSuiJE|KporIV!htu+I06VKCAx%_t%I0 literal 0 HcmV?d00001 diff --git a/AlexSubbotin/lesson_7/out/production/lesson_7/GearboxesProperties.class b/AlexSubbotin/lesson_7/out/production/lesson_7/GearboxesProperties.class new file mode 100644 index 0000000000000000000000000000000000000000..86262d0b10110055312f062ae0b9f4b01e15b9c7 GIT binary patch literal 1558 zcmZ{jTT|0O6vzKtO43UTrKMN|6cn{wq~1|M7>5~s0c55O54>&TT7qrTNfSptil4w2 zAJh?@@xc$^hjKi-2`LTXplhH;Wb2Gq{(-eLTqEVHP<& zlIF2APo!DZ@l?k%hP2H)f}ym1%s=pYo7=5=!*eaWwZ>p{xb45=rsuoDWzbE>w>|fS zq2Qf##Y^9FI^45N26o7xty{L`Z7>Yg77j>v%Xv$>quZ7(cKuFMxcj`>RxddwZy#{i zlIPHw_KvI`LuLE5;BM3TD0+LY(-p2~i5`KZ<$JW$4yAOV;c@f*4)2D+#h&n@xLuV_ zrFJnN8Jcee`oXP{RumXG#%l`~;~1*vAJ`eFNjVf8^iK4J2S1e0D{Y;XlQ>k?k%LtG z8AV>1=l)>f&+?IODvZ?&>kyo&6V#Yo!|`2Hys~8VtKo(71zwS@H&8-Z$8!T~Sf_c2 zx;q=ft>}1RU;{G@V>`k;;u9B6(O?o6nYjx@qM!q9e z8v2R!XXNE}n6^@H2vV;^U_gd!ma3H}t%A~?2;xI+Qj%pP^(nedsf_BhpT z;63<asm%ih+x^o3ZIXR=C>w= z0rnmmY8*VeXlkEHLge{mTLhR#I5Y+m$`S;9K^u&{`{!2JI;0-07QSgh5H zBxT_lo?FsCS0G=y z`pKNq@g1ASj+Nf<63od^e{FevEs(N@%09UWXF_LR25O-FGlAqto+xS_P-2?4?{@V_ zg&VR4`cSvLK>42HDaNimdnZS{8PqpS%fi#S(ze9 zmLf}&S!5ZqIkGI-JlVC&j+@AkQWPd)m_wWfG^k?&cj;z{x~|YCUPc;gG*69kHz;ch a*>J+bYzoS~M;a#TxQ`;uD5#Pj{NNvaGNIf6 literal 0 HcmV?d00001 diff --git a/AlexSubbotin/lesson_7/out/production/lesson_7/PhonesProperties.class b/AlexSubbotin/lesson_7/out/production/lesson_7/PhonesProperties.class new file mode 100644 index 0000000000000000000000000000000000000000..d39098a44cb224925be7255b239521f8f3f2b2f7 GIT binary patch literal 4127 zcmb7GT~`~&8GaTCX%PZr0geq6Hjc4DIFQ;-;+Dk0h&m?0m?ak+eqIRkSNG zF=^biNs}gRnzT*qHt|Jna?zaAk5k-pe9<4!pU}(xke)s>yNDH5;$t{xW_ISC_kG^4 zXY}v?-TN1Sr*S8NQT#;5r8bOUSq?ADVMPv?+wclrO;PS@0wz{mI!ZdqI_wl$P>D^g@GAdwydl+9b-1yqx2J+VPe&~__3_TSm^BRtxfYmZGl5bFMFIh&^N3mUl)&WMuS`hG>Q+H0+zRY%yOeuZrrD zxmw~*YR<`;rAubjlHb8*)GJ!9JXp~hPJY~CaA=7G$aeok~3=)v@JaPQYo36&zogpXeWZwqEi+$rlG4K zyy-^g=mXtrcPqlq?Km7AnU#)pWK{ry3sR`)Y}CJW0=eJ^w|C_J=t>1T%>^PoBcu1r zP=ZPp{3Jw2W_IobJA}r>_(2J_2#FEO)KjHPNV9gHF-R;rwQ5$Jvt;Od_eOVIray_3 zIK{}#iw#2wB$38g5)*hLiSOe?636j)96w9q9sHcpnsyw|^{Qs&g7At?&fOQoFLb<{ z#C!N<9PcOb0T{bJrOL2e!^!8zjd>w*h99{{nVIlm5UFjmdF%^SxI6XV;Xu^7=5E6 zYg*oSt#U=?AvW(+%cktV#`A*X=)+8Bxvbay64H z)l9nNET3_5D#s`JwZi9DCSD${-!QJ#jy`DjyfOf zHYE7pg?98J$^8!gyZ~296;9&^>JF(hFyjzb3-=DE|AFWo^!y!hxw=PXxQn*vH{3`i zxQcv3sR*RC19S?s5yyV6Q#gno7_=uX9q_dUmZ(?01+?{yx~(1L^4YqNQxulKI@1yQ zBrUbm(ym*bG$@^GML!)G2)WW37|?L0u5ByOb}CH|TJIux8;?ny9n_ibq7R*Q=k_V* zzDBz|?+R@C&iSDnVgLH#>)A z^t&Yz{h@$N5y)8rnP%l>*j(orknq~BN*oMq9q$~u=t-J*&*rZ!&; zscEg(7=KsNfDJw_Vat0Bw& z&V^9M>L_E1Ic2(Dz>9&daQY&DrP6Tv3Lzl7>6^oaI*^E>lvw&$1AqFitPx1*TYyOF zmO$p2(49K+$xGHz>@RzOI8A{p)Fb>KR)vi4mb~19M{a$A@5yE7=j7mY>d-d&WOMX0 zxnE<&7aE|@P$2J%4F+OEO6-JxX6%X$_+p0xvB#8{;=CgbRWr_p0$kF#$7-yR?Karm z*V$y7n8OXMVhcsQMTwjIdMD)DR*);ngE2&hj~Y4_JL4vVK0oYy9Q9`xssc zA#X)wXmF6gU#bJ24iXeN1wIX_-f4jd773<>ZGW3{g8DzlpKyyr Y@EX4jR@)Wsy{^Wh8XYy>P~%(w2MnV#ivR!s literal 0 HcmV?d00001 diff --git a/AlexSubbotin/lesson_7/src/Flashlights.java b/AlexSubbotin/lesson_7/src/Flashlights.java new file mode 100644 index 0000000..8444dd4 --- /dev/null +++ b/AlexSubbotin/lesson_7/src/Flashlights.java @@ -0,0 +1,23 @@ +public class Flashlights { + public FlashlightsProperties properties = new FlashlightsProperties(); + + public static void main(String[] args) { + Flashlights firstFlashlight = new Flashlights(); + firstFlashlight.properties.setName("BIG"); + firstFlashlight.properties.setColour("Silver"); + firstFlashlight.properties.setManufacturer("Big Corp."); + firstFlashlight.properties.setPrice(15.5f); + firstFlashlight.properties.putOnBatteries(Integer.parseInt(args[0])); + + printFlashlight(firstFlashlight); + } + + private static void printFlashlight(Flashlights flashlight) { + System.out.println("Flashlight name: " + flashlight.properties.getName()); + System.out.println("Flashlight manufacturer: " + flashlight.properties.getManufacturer()); + System.out.println("Flashlight colour: " + flashlight.properties.getColour()); + System.out.println("Flashlight price: " + flashlight.properties.getPrice() + "$"); + flashlight.properties.whichGlow(); + } + +} diff --git a/AlexSubbotin/lesson_7/src/FlashlightsProperties.java b/AlexSubbotin/lesson_7/src/FlashlightsProperties.java new file mode 100644 index 0000000..19a0fdc --- /dev/null +++ b/AlexSubbotin/lesson_7/src/FlashlightsProperties.java @@ -0,0 +1,65 @@ +public class FlashlightsProperties { + private final String RED = "RED LIGHT"; + private final String WHITE = "WHITE LIGHT"; + private final String FLASHING = "FLASHING LIGHT"; + + private String name; + private int batteries; + private String glow; + private String colour; + private float price; + private String manufacturer; + + public void putOnBatteries(int numberOfBatteries) { + batteries = numberOfBatteries; + } + + public void whichGlow() { + switch (batteries) { + case 1: + glow = WHITE; + break; + case 2: + glow = RED; + break; + case 3: + glow = FLASHING; + break; + default: + glow = "Not working. For start, put on 1,2 or 3 batteries, please."; + } + System.out.println("Flashlight glow: " + glow); + } + + public void setName(String flashlightName) { + name = flashlightName; + } + + public String getName() { + return name; + } + + public void setManufacturer(String flashlightManufacturer) { + manufacturer = flashlightManufacturer; + } + + public String getManufacturer() { + return manufacturer; + } + + public void setColour(String flashlightColour) { + colour = flashlightColour; + } + + public String getColour() { + return colour; + } + + public void setPrice(float flashlightPrice) { + price = flashlightPrice; + } + + public float getPrice() { + return price; + } +} diff --git a/AlexSubbotin/lesson_7/src/Gearboxes.java b/AlexSubbotin/lesson_7/src/Gearboxes.java new file mode 100644 index 0000000..99164f7 --- /dev/null +++ b/AlexSubbotin/lesson_7/src/Gearboxes.java @@ -0,0 +1,42 @@ +import java.util.Scanner; + +public class Gearboxes { + GearboxesProperties properties = new GearboxesProperties(); + GearboxesOperation operation = new GearboxesOperation(); + + public static void main(String[] args) { + Gearboxes firstGearbox = new Gearboxes(); + firstGearbox.properties.setGearboxesCountry("Japan"); + firstGearbox.properties.setGearboxesManufacturer("Jatco"); + firstGearbox.properties.setGearboxesName("J1039I"); + firstGearbox.properties.setTypeAutomatic(false); + firstGearbox.operation.setNumberOfGears((byte) 4); + firstGearbox.operation.setSpeedStep((byte) 26); + + gearboxResult(firstGearbox); + + Gearboxes secondGearbox = new Gearboxes(); + secondGearbox.properties.setGearboxesCountry("Germany"); + secondGearbox.properties.setGearboxesManufacturer("ZF Friedrichshafen AG"); + secondGearbox.properties.setGearboxesName("MS Tronic"); + secondGearbox.properties.setTypeAutomatic(true); + secondGearbox.operation.setNumberOfGears((byte) 4); + secondGearbox.operation.setSpeedStep((byte) 35); + + gearboxResult(secondGearbox); + + } + + private static void gearboxResult(Gearboxes gearbox) { + System.out.println("Gearbox name: " + gearbox.properties.getGearboxName()); + System.out.println("Gearbox manufacturer: " + gearbox.properties.getGearboxManufacturer()); + System.out.println("Gearbox country: " + gearbox.properties.getGearboxesCountry()); + gearbox.properties.type(gearbox.properties.isGearboxType()); //Print gearbox type. + System.out.println("To determine the maximum speed, enter the gear number: "); + Scanner scanner = new Scanner(System.in); + byte gearNumber = scanner.nextByte(); + gearbox.operation.setGearNumber(gearNumber); + byte speedStep = gearbox.operation.getSpeedStep(); + gearbox.operation.maxSpeedOnGear(gearNumber, speedStep, gearbox.properties.isGearboxType()); + } +} diff --git a/AlexSubbotin/lesson_7/src/GearboxesOperation.java b/AlexSubbotin/lesson_7/src/GearboxesOperation.java new file mode 100644 index 0000000..8fb8418 --- /dev/null +++ b/AlexSubbotin/lesson_7/src/GearboxesOperation.java @@ -0,0 +1,51 @@ +public class GearboxesOperation { + GearboxesProperties properties = new GearboxesProperties(); + + private byte numberOfGears; + private byte speedStep; + private byte gearNumber; + + public void maxSpeedOnGear(byte gearNumber, byte speedStep, boolean gearboxType) { + if (gearboxType) { + speedStep -= 5; + } + int speed; + switch (gearNumber) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + speed = gearNumber * speedStep; + System.out.println("Maximum speed in " + gearNumber + " gear " + speed + " km/h."); + break; + default: + System.out.println("Enter a correct gear number."); + } + } + + public void setNumberOfGears(byte numberGears) { + numberOfGears = numberGears; + } + + public byte getNumberOfGears() { + return numberOfGears; + } + + public void setSpeedStep(byte gearboxSpeedStep) { + speedStep = gearboxSpeedStep; + } + + public byte getSpeedStep() { + return speedStep; + } + + public void setGearNumber(byte setGearNumber) { + gearNumber = setGearNumber; + } + + public byte getGearNumber() { + return gearNumber; + } +} diff --git a/AlexSubbotin/lesson_7/src/GearboxesProperties.java b/AlexSubbotin/lesson_7/src/GearboxesProperties.java new file mode 100644 index 0000000..f113c4e --- /dev/null +++ b/AlexSubbotin/lesson_7/src/GearboxesProperties.java @@ -0,0 +1,46 @@ +public class GearboxesProperties { + private String name; + private String manufacturer; + private String country; + private boolean typeAutomatic; + + public void type(boolean typeAutomatic) { + if (typeAutomatic) { + System.out.println("Automatic gearbox."); + } else { + System.out.println("Mechanic gearbox."); + } + } + + public void setGearboxesName(String gearboxName) { + name = gearboxName; + } + + public String getGearboxName() { + return name; + } + + public void setGearboxesManufacturer(String gearboxManufacturer) { + manufacturer = gearboxManufacturer; + } + + public String getGearboxManufacturer() { + return manufacturer; + } + + public void setGearboxesCountry(String gearboxCountry) { + country = gearboxCountry; + } + + public String getGearboxesCountry() { + return country; + } + + public void setTypeAutomatic(boolean gearboxType) { + typeAutomatic = gearboxType; + } + + public boolean isGearboxType() { + return typeAutomatic; + } +} diff --git a/AlexSubbotin/lesson_7/src/Phones.java b/AlexSubbotin/lesson_7/src/Phones.java new file mode 100644 index 0000000..b8418b4 --- /dev/null +++ b/AlexSubbotin/lesson_7/src/Phones.java @@ -0,0 +1,16 @@ +public class Phones { + public static void main(String[] args) { + PhonesProperties phone = new PhonesProperties(); + phone.setModel("Iphone 12 Pro"); + phone.setPrice(1000); + phone.showInfo(); + phone.checkPrice(); + phone.checkCategory(); + phone.makePhoto(); + phone.callSomeone(); + phone.goToInternet(); + phone.playGame(); + phone.showBattery(); + phone.setOff(); + } +} diff --git a/AlexSubbotin/lesson_7/src/PhonesProperties.java b/AlexSubbotin/lesson_7/src/PhonesProperties.java new file mode 100644 index 0000000..f29e6bb --- /dev/null +++ b/AlexSubbotin/lesson_7/src/PhonesProperties.java @@ -0,0 +1,147 @@ +public class PhonesProperties { + private String model; + private double price; + private String category; + private int batteryCharge; + private boolean state; + + public PhonesProperties() { + model = "New Phone"; + batteryCharge = 100; + state = true; + price = 0; + } + + private boolean checkState(boolean state) { + if (batteryCharge > 0) { + System.out.println("Phone is on. Available " + batteryCharge + " %"); + return true; + } else { + System.out.println("Phone is off. Need charge!"); + return false; + } + } + + public void setOff() { + state = false; + System.out.println("Phone is off"); + } + + public void makePhoto() { + if (checkState(state)) { + System.out.println("Nice shot"); + spendCharge(10); + System.out.println("Left " + batteryCharge + " %"); + } + else { + System.out.println("Phone is off. Need to charge"); + } + } + + public void goToInternet() { + if (checkState(state)) { + System.out.println("What site are we going to?"); + spendCharge(20); + System.out.println("Left " + batteryCharge + " %"); + } + else { + System.out.println("Phone is off. Need to charge"); + } + } + + public void playGame() { + if (checkState(state)) { + System.out.println("Time to games"); + spendCharge(30); + System.out.println("Left " + batteryCharge + " %"); + } + else { + System.out.println("Phone is off. Need to charge"); + } + } + + public void callSomeone() { + if (checkState(state)) { + System.out.println("Who are we calling?"); + spendCharge(5); + System.out.println("Left " + batteryCharge + " %"); + } + else { + System.out.println("Phone is off. Need to charge"); + } + } + + public int getBatteryCharge() { + return batteryCharge; + } + + public void spendCharge(int batteryCharge) { + if (batteryCharge > 0) { + this.batteryCharge -= batteryCharge; + } else { + System.out.println("Nothing to spend. Need charge!"); + } + } + + public void chargeBattery(int batteryCharge) { + if (batteryCharge < 100) { + this.batteryCharge += batteryCharge; + } else { + System.out.println("Battery is full. Don't need to charge"); + } + } + + public void showBattery() { + System.out.println(model + " have " + batteryCharge + " % battery"); + } + + public void setModel(String model) { + this.model = model; + } + + public String getModel() { + return model; + } + + public void setPrice(double price) { + this.price = price; + } + + public double getPrice() { + return price; + } + + public void checkPrice() { + if (price < 100 && price > 0) { + this.category = "Cheap"; + System.out.println("Your phone is simple"); + } + else if (price < 500 && price > 100) { + this.category = "Normal"; + System.out.println("Your phone is good"); + } + else if (price < 1000 && price > 500 ) { + this.category = "Premium"; + System.out.println("Your phone is amazing. Can you give me a call?"); + } + else { + System.out.println("We don’t have such expensive phones yet"); + } + } + + public void checkCategory() { + if (category.equals("Cheap")) { + System.out.println("Your " + model + " from " + category + " segment"); + } + if (category.equals("Normal")) { + System.out.println("Your " + model + " from " + category + " segment"); + } + if (category.equals("Premium")) { + System.out.println("Your " + model + " from " + category + " segment"); + } + } + + public void showInfo() { + System.out.println("Model is " + model + ", price is " + price + " $"); + } +} From 9ec1909fd6189ff15b09d5cb2c86a72a354b2118 Mon Sep 17 00:00:00 2001 From: Militaryus Date: Sun, 3 Jan 2021 20:54:26 +0200 Subject: [PATCH 3/5] lesson_8 Signed-off-by: Militaryus --- AlexSubbotin/lesson_8/.idea/.gitignore | 2 + AlexSubbotin/lesson_8/.idea/misc.xml | 6 + AlexSubbotin/lesson_8/.idea/modules.xml | 8 + AlexSubbotin/lesson_8/.idea/vcs.xml | 6 + AlexSubbotin/lesson_8/lesson_8.iml | 11 ++ AlexSubbotin/lesson_8/src/HomeworkEight.java | 186 +++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 AlexSubbotin/lesson_8/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_8/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_8/.idea/modules.xml create mode 100644 AlexSubbotin/lesson_8/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_8/lesson_8.iml create mode 100644 AlexSubbotin/lesson_8/src/HomeworkEight.java diff --git a/AlexSubbotin/lesson_8/.idea/.gitignore b/AlexSubbotin/lesson_8/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_8/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/AlexSubbotin/lesson_8/.idea/misc.xml b/AlexSubbotin/lesson_8/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/AlexSubbotin/lesson_8/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_8/.idea/modules.xml b/AlexSubbotin/lesson_8/.idea/modules.xml new file mode 100644 index 0000000..348c044 --- /dev/null +++ b/AlexSubbotin/lesson_8/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_8/.idea/vcs.xml b/AlexSubbotin/lesson_8/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_8/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_8/lesson_8.iml b/AlexSubbotin/lesson_8/lesson_8.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/AlexSubbotin/lesson_8/lesson_8.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_8/src/HomeworkEight.java b/AlexSubbotin/lesson_8/src/HomeworkEight.java new file mode 100644 index 0000000..1074c7c --- /dev/null +++ b/AlexSubbotin/lesson_8/src/HomeworkEight.java @@ -0,0 +1,186 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class HomeworkEight { + public static void main(String[] args) { + // -------TASK 1------- + + System.out.println("HOW MANY ROWS OF PASCAL`S TRIANGLE?"); + Scanner scanner = new Scanner(System.in); + int rowsNumber = scanner.nextInt(); + int[][] pascalTriangle = new int[rowsNumber][rowsNumber]; + pascalTriangle(pascalTriangle, rowsNumber); + + //-------TASK 2------- + + Scanner scann = new Scanner(System.in); + System.out.println("Enter number of rows:"); + int rows = scann.nextInt(); + System.out.println("Enter number of columns:"); + int columns = scanner.nextInt(); + + arraysSpiralFill(rows, columns); + + //-------TASK 3------- + + System.out.println("To check for a palindrome, enter words separated by ',': "); + Scanner wordsScan = new Scanner(System.in); + String words = wordsScan.nextLine(); + + palindromeChecker(words); + + palindromeCheckerByChars(words); + + //-------TASK 4------- + + System.out.println("Sorted array: " + Arrays.toString(arraySorter())); + + //-------TASK 5------- + + int[] firstArray = arraySorter(); + int[] secondArray = arraySorter(); + + arraysMerger(firstArray, secondArray); + } + + public static void pascalTriangle(int[][] pascalTriangle, int rowsNumber) { + for (int row = 0; row < rowsNumber; row++) { + for (int column = 0; column <= row; column++) { + if (column == 0 || column == row) + pascalTriangle[row][column] = 1; + else + pascalTriangle[row][column] = pascalTriangle[row - 1][column - 1] + + pascalTriangle[row - 1][column]; + } + System.out.println(Arrays.toString(pascalTriangle[row]).replace(",", "\t")); + } + } + + static void arraysSpiralFill(int rows, int columns) { + int value = 1; + int[][] array = new int[rows][columns]; + int startRowIndex = 0; + int endColumnIndex = rows; + int startColumnIndex = 0; + int endRowIndex = columns; + + while (startRowIndex < endColumnIndex && startColumnIndex < endRowIndex) { + for (int i = startColumnIndex; i < endRowIndex; ++i) { + array[startRowIndex][i] = value++; + } + startRowIndex++; + for (int i = startRowIndex; i < endColumnIndex; ++i) { + array[i][endRowIndex - 1] = value++; + } + endRowIndex--; + if (startRowIndex < endColumnIndex) { + for (int i = endRowIndex - 1; i >= startColumnIndex; --i) { + array[endColumnIndex - 1][i] = value++; + } + endColumnIndex--; + } + if (startColumnIndex < endRowIndex) { + for (int i = endColumnIndex - 1; i >= startRowIndex; --i) { + array[i][startColumnIndex] = value++; + } + startColumnIndex++; + } + } + for (int i = 0; i < rows; i++) { + System.out.println(Arrays.toString(array[i]).replace(",", "\t")); + } + } + + public static void palindromeChecker(String words) { + String[] arrayWords = words.split(","); + System.out.println(Arrays.toString(arrayWords)); + boolean palindrome; + int counter = 0; + for (String word : arrayWords) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(word).reverse(); + palindrome = word.equalsIgnoreCase(String.valueOf(stringBuilder)); + if (palindrome) { + counter++; + } + } + System.out.println("There are " + counter + " palindromes in the text."); + } + + public static int[] arraySorter() { + System.out.println("Enter the size of the array: "); + Scanner scan = new Scanner(System.in); + int arraySize = scan.nextInt(); + System.out.println("Enter number generations lower limit: "); + int lowerLimit = scan.nextInt(); + System.out.println("Enter number generations upper limit: "); + int upperLimit = scan.nextInt(); + int[] array = new int[arraySize]; + + for (int i = 0; i < array.length; i++) { + array[i] = (int) (Math.random() * (upperLimit - lowerLimit + 1) + lowerLimit); + } + System.out.println("Unsorted arrey: " + Arrays.toString(array)); + boolean sorted = false; + int counter = 0; + int temp; + while (!sorted) { + sorted = true; + for (int i = 0; i < array.length - 1; i++) { + if (array[i] > array[i + 1]) { + sorted = false; + temp = array[i]; + array[i] = array[i + 1]; + array[i + 1] = temp; + counter++; + } + } + } + System.out.println("The number of cycles: " + counter); + return array; + } + + public static void arraysMerger(int[] firstArray, int[] secondArray) { + int[] resultArray = new int[firstArray.length + secondArray.length]; + int firstArrIndex = 0; + int secondArrIndex = 0; + + for (int i = 0; i < resultArray.length; i++) { + if (firstArrIndex == firstArray.length) { + resultArray[i] = secondArray[secondArrIndex]; + secondArrIndex++; + } else if (secondArrIndex == secondArray.length) { + resultArray[i] = firstArray[firstArrIndex]; + firstArrIndex++; + } else if (firstArray[firstArrIndex] < secondArray[secondArrIndex]) { + resultArray[i] = firstArray[firstArrIndex]; + firstArrIndex++; + } else { + resultArray[i] = secondArray[secondArrIndex]; + secondArrIndex++; + } + } + System.out.println("First array: " + Arrays.toString(firstArray)); + System.out.println("Second array: " + Arrays.toString(secondArray)); + System.out.println("Merged array: " + Arrays.toString(resultArray)); + } + + public static void palindromeCheckerByChars(String words) { + String[] arrayWords = words.split(","); + System.out.println(Arrays.toString(arrayWords)); + int counter = 0; + for (String word : arrayWords) { + String lowCaseWord = word.toLowerCase(); + boolean palindrome = true; + for (int i = 0; i < lowCaseWord.length() / 2; i++) { + if (lowCaseWord.charAt(i) != lowCaseWord.charAt(lowCaseWord.length() - 1 - i)) { + palindrome = false; + } + } + if (palindrome) { + counter++; + } + } + System.out.println("There are " + counter + " palindromes in the text."); + } +} From 040745d0602f4bdd6361006a1e56960394aa5a2d Mon Sep 17 00:00:00 2001 From: Militaryus Date: Tue, 23 Feb 2021 23:18:04 +0200 Subject: [PATCH 4/5] lessons_9_10_11 --- AlexSubbotin/lesson_10/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_10/.idea/misc.xml | 14 ++ .../lesson_10}/.idea/vcs.xml | 2 +- AlexSubbotin/lesson_10/.idea/workspace.xml | 60 ++++++ AlexSubbotin/lesson_10/lesson_10.iml | 2 + AlexSubbotin/lesson_10/pom.xml | 33 ++++ AlexSubbotin/lesson_10/src/main/java/Cow.java | 45 +++++ .../lesson_10/src/main/java/Farm.java | 109 ++++++++++ .../lesson_10/src/test/java/CowTest.java | 15 ++ .../lesson_10/src/test/java/FarmTest.java | 172 ++++++++++++++++ .../lesson_11}/.idea/.gitignore | 0 AlexSubbotin/lesson_11/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_11/.idea/misc.xml | 14 ++ AlexSubbotin/lesson_11/.idea/uiDesigner.xml | 124 ++++++++++++ AlexSubbotin/lesson_11/.idea/vcs.xml | 6 + AlexSubbotin/lesson_11/lesson_11.iml | 2 + AlexSubbotin/lesson_11/pom.xml | 45 +++++ .../lesson_11/src/main/java/Main.java | 65 ++++++ .../main/java/usersContainer/Container.java | 22 +++ .../src/main/java/usersContainer/User.java | 46 +++++ .../java/usersContainer/UsersManager.java | 186 ++++++++++++++++++ .../lesson_11/src/test/java/MainTest.java | 99 ++++++++++ .../java/usersContainer/ContainerTest.java | 20 ++ .../test/java/usersContainer/UserTest.java | 20 ++ .../java/usersContainer/UsersManagerTest.java | 153 ++++++++++++++ AlexSubbotin/lesson_9/.idea/.gitignore | 2 + .../lesson_9}/.idea/misc.xml | 0 .../lesson_9}/.idea/modules.xml | 2 +- AlexSubbotin/lesson_9/.idea/vcs.xml | 6 + .../lesson_9/lesson_9.iml | 0 AlexSubbotin/lesson_9/src/Circle.java | 17 ++ AlexSubbotin/lesson_9/src/Figures.java | 9 + AlexSubbotin/lesson_9/src/Homework_9.java | 88 +++++++++ AlexSubbotin/lesson_9/src/Rhombus.java | 24 +++ AlexSubbotin/lesson_9/src/Square.java | 19 ++ .../lesson_6/META-INF/lesson_6.kotlin_module | Bin 16 -> 0 bytes lesson_6/out/production/lesson_6/Main.class | Bin 4288 -> 0 bytes lesson_6/src/Main.java | 155 --------------- 38 files changed, 1445 insertions(+), 157 deletions(-) create mode 100644 AlexSubbotin/lesson_10/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_10/.idea/misc.xml rename {lesson_6 => AlexSubbotin/lesson_10}/.idea/vcs.xml (68%) create mode 100644 AlexSubbotin/lesson_10/.idea/workspace.xml create mode 100644 AlexSubbotin/lesson_10/lesson_10.iml create mode 100644 AlexSubbotin/lesson_10/pom.xml create mode 100644 AlexSubbotin/lesson_10/src/main/java/Cow.java create mode 100644 AlexSubbotin/lesson_10/src/main/java/Farm.java create mode 100644 AlexSubbotin/lesson_10/src/test/java/CowTest.java create mode 100644 AlexSubbotin/lesson_10/src/test/java/FarmTest.java rename {lesson_6 => AlexSubbotin/lesson_11}/.idea/.gitignore (100%) create mode 100644 AlexSubbotin/lesson_11/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_11/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_11/.idea/uiDesigner.xml create mode 100644 AlexSubbotin/lesson_11/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_11/lesson_11.iml create mode 100644 AlexSubbotin/lesson_11/pom.xml create mode 100644 AlexSubbotin/lesson_11/src/main/java/Main.java create mode 100644 AlexSubbotin/lesson_11/src/main/java/usersContainer/Container.java create mode 100644 AlexSubbotin/lesson_11/src/main/java/usersContainer/User.java create mode 100644 AlexSubbotin/lesson_11/src/main/java/usersContainer/UsersManager.java create mode 100644 AlexSubbotin/lesson_11/src/test/java/MainTest.java create mode 100644 AlexSubbotin/lesson_11/src/test/java/usersContainer/ContainerTest.java create mode 100644 AlexSubbotin/lesson_11/src/test/java/usersContainer/UserTest.java create mode 100644 AlexSubbotin/lesson_11/src/test/java/usersContainer/UsersManagerTest.java create mode 100644 AlexSubbotin/lesson_9/.idea/.gitignore rename {lesson_6 => AlexSubbotin/lesson_9}/.idea/misc.xml (100%) rename {lesson_6 => AlexSubbotin/lesson_9}/.idea/modules.xml (61%) create mode 100644 AlexSubbotin/lesson_9/.idea/vcs.xml rename lesson_6/lesson_6.iml => AlexSubbotin/lesson_9/lesson_9.iml (100%) create mode 100644 AlexSubbotin/lesson_9/src/Circle.java create mode 100644 AlexSubbotin/lesson_9/src/Figures.java create mode 100644 AlexSubbotin/lesson_9/src/Homework_9.java create mode 100644 AlexSubbotin/lesson_9/src/Rhombus.java create mode 100644 AlexSubbotin/lesson_9/src/Square.java delete mode 100644 lesson_6/out/production/lesson_6/META-INF/lesson_6.kotlin_module delete mode 100644 lesson_6/out/production/lesson_6/Main.class delete mode 100644 lesson_6/src/Main.java diff --git a/AlexSubbotin/lesson_10/.idea/compiler.xml b/AlexSubbotin/lesson_10/.idea/compiler.xml new file mode 100644 index 0000000..39231f3 --- /dev/null +++ b/AlexSubbotin/lesson_10/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_10/.idea/misc.xml b/AlexSubbotin/lesson_10/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_10/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/lesson_6/.idea/vcs.xml b/AlexSubbotin/lesson_10/.idea/vcs.xml similarity index 68% rename from lesson_6/.idea/vcs.xml rename to AlexSubbotin/lesson_10/.idea/vcs.xml index 6c0b863..b2bdec2 100644 --- a/lesson_6/.idea/vcs.xml +++ b/AlexSubbotin/lesson_10/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/AlexSubbotin/lesson_10/.idea/workspace.xml b/AlexSubbotin/lesson_10/.idea/workspace.xml new file mode 100644 index 0000000..f250dc4 --- /dev/null +++ b/AlexSubbotin/lesson_10/.idea/workspace.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1614103939587 + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_10/lesson_10.iml b/AlexSubbotin/lesson_10/lesson_10.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_10/lesson_10.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_10/pom.xml b/AlexSubbotin/lesson_10/pom.xml new file mode 100644 index 0000000..95b8254 --- /dev/null +++ b/AlexSubbotin/lesson_10/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + org.example + lesson_10 + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + junit + junit + RELEASE + test + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_10/src/main/java/Cow.java b/AlexSubbotin/lesson_10/src/main/java/Cow.java new file mode 100644 index 0000000..9ee54f7 --- /dev/null +++ b/AlexSubbotin/lesson_10/src/main/java/Cow.java @@ -0,0 +1,45 @@ +public class Cow { + public final int DAYS_IN_YEAR = 365; + private float cowMilkProduction; + private float cowFoodConsumption; + private float cowFoodPrise; + private float cowMilkPrice; + + protected float calculateYearlyCowRevenue() { + float revenue = (this.cowMilkProduction * this.cowMilkPrice + - this.cowFoodConsumption * this.cowFoodPrise) * DAYS_IN_YEAR; + return revenue; + } + + public float getCowMilkProduction() { + return cowMilkProduction; + } + + protected void setCowMilkProduction(float cowMilkProduction) { + this.cowMilkProduction = cowMilkProduction; + } + + public float getCowFoodConsumption() { + return cowFoodConsumption; + } + + protected void setCowFoodConsumption(float cowFoodConsumption) { + this.cowFoodConsumption = cowFoodConsumption; + } + + public float getCowFoodPrise() { + return cowFoodPrise; + } + + protected void setCowFoodPrise(float cowFoodPrise) { + this.cowFoodPrise = cowFoodPrise; + } + + public float getCowMilkPrice() { + return cowMilkPrice; + } + + protected void setCowMilkPrice(float cowMilkPrice) { + this.cowMilkPrice = cowMilkPrice; + } +} diff --git a/AlexSubbotin/lesson_10/src/main/java/Farm.java b/AlexSubbotin/lesson_10/src/main/java/Farm.java new file mode 100644 index 0000000..3d35e63 --- /dev/null +++ b/AlexSubbotin/lesson_10/src/main/java/Farm.java @@ -0,0 +1,109 @@ +public class Farm { + private float farmPrice; + private float percentIncomeTax; + private float percentSalaryToMilkmaids; + private int numberOfCows; + Cow cows = new Cow(); + + public String calculateFarmProfit() { + float revenueOfAllCows = calculateYearlyAllCowsRevenue(); + float revenueAfterTax = calculateYearlyRevenueAfterTax(revenueOfAllCows); + float revenueAfterSalary = calculateYearlyRevenueAfterSalary(revenueAfterTax); + String farmProfit = calculateChanceBuyNewFarms(revenueAfterSalary); + return farmProfit; + } + + public String calculateChanceBuyNewFarms(float revenue) { + String farmsNumber; + int farmsNumb = (int) (revenue / farmPrice); + if (farmsNumb > 3) { + System.out.println("You can buy " + farmsNumb + " farms."); + farmsNumber = "SUPER PROFITABLE"; + } else if (farmsNumb >= 1) { + System.out.println("You can buy " + farmsNumb + " farms."); + farmsNumber = "PROFITABLE"; + } else { + System.out.println("You can not buy farms."); + farmsNumber = "NOT PROFITABLE"; + } + System.out.println(farmsNumber); + return farmsNumber; + } + + public float calculateYearlyRevenueAfterSalary(float revenue) { + revenue -= revenue * percentSalaryToMilkmaids / 100; + return revenue; + } + + public float calculateYearlyRevenueAfterTax(float revenue) { + revenue -= revenue * percentIncomeTax / 100; + return revenue; + } + + public float calculateYearlyAllCowsRevenue() { + float revenue = cows.calculateYearlyCowRevenue() * numberOfCows; + return revenue; + } + + + protected boolean paramsLimitsChecking(int lowerLimit, int upperLimit, float parameter) { + if (parameter < lowerLimit || parameter > upperLimit) { + return false; + } else { + return true; + } + } + + public String setFarmParams(float farmPrice, float percentIncomeTax, float percentSalaryToMilkmaids) { + String result; + if (paramsLimitsChecking(500, 1000, farmPrice) + && paramsLimitsChecking(10, 20, percentIncomeTax) + && paramsLimitsChecking(5, 10, percentSalaryToMilkmaids)) { + this.farmPrice = farmPrice; + this.percentIncomeTax = percentIncomeTax; + this.percentSalaryToMilkmaids = percentSalaryToMilkmaids; + result = ""; + } else { + result = "INPUT PARAMS ARE INCORRECT."; + System.out.println(result); + } + return result; + } + + public String setCowParams(int numberOfCows, float cowFoodConsumption, float cowFoodPrise, + float cowMilkProduction, float cowMilkPrice) { + String result; + if (paramsLimitsChecking(50, 100, numberOfCows) + && paramsLimitsChecking(5, 10, cowFoodConsumption) + && paramsLimitsChecking(1, 3, cowFoodPrise) + && paramsLimitsChecking(1, 5, cowMilkProduction) + && paramsLimitsChecking(5, 10, cowMilkPrice)) { + this.cows.setCowFoodPrise(cowFoodPrise); + this.cows.setCowMilkPrice(cowMilkPrice); + this.cows.setCowMilkProduction(cowMilkProduction); + this.cows.setCowFoodConsumption(cowFoodConsumption); + this.numberOfCows = numberOfCows; + result = ""; + } else { + result = "INPUT PARAMS ARE INCORRECT."; + System.out.println(result); + } + return result; + } + + public float getFarmPrice() { + return farmPrice; + } + + public float getPercentIncomeTax() { + return percentIncomeTax; + } + + public float getPercentSalaryToMilkmaids() { + return percentSalaryToMilkmaids; + } + + public int getNumberOfCows() { + return numberOfCows; + } +} diff --git a/AlexSubbotin/lesson_10/src/test/java/CowTest.java b/AlexSubbotin/lesson_10/src/test/java/CowTest.java new file mode 100644 index 0000000..3f1a4c4 --- /dev/null +++ b/AlexSubbotin/lesson_10/src/test/java/CowTest.java @@ -0,0 +1,15 @@ +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class CowTest { + + Farm farm = new Farm(); + + @Test + public void testCalculateYearlyCowRevenue() { + farm.setCowParams(50, 8f, 3f, 3f, 10f); + assertThat(farm.cows.calculateYearlyCowRevenue(), is(equalTo((3*10-8*3f)*365))); + } +} diff --git a/AlexSubbotin/lesson_10/src/test/java/FarmTest.java b/AlexSubbotin/lesson_10/src/test/java/FarmTest.java new file mode 100644 index 0000000..cfef3af --- /dev/null +++ b/AlexSubbotin/lesson_10/src/test/java/FarmTest.java @@ -0,0 +1,172 @@ +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class FarmTest { + Farm farm = new Farm(); + + @Before + public void initFarmAndCowParameters() { + farm.setFarmParams(500, 10, 10); + farm.setCowParams(50, 8, 3, 3, 10); + } + + @Test + public void testOfSetMiddleValidFarmParams() { + farm.setFarmParams(850f, 15.5f, 8.5f); + assertThat(farm.getFarmPrice(), equalTo(850f)); + assertThat(farm.getPercentIncomeTax(), equalTo(15.5f)); + assertThat(farm.getPercentSalaryToMilkmaids(), equalTo(8.5f)); + } + + @Test + public void testOfSetMiddleValidCowParams() { + farm.setCowParams(80, 8f, 2f, 3f, 8f); + assertThat(farm.getNumberOfCows(), equalTo(80)); + assertThat(farm.cows.getCowFoodConsumption(), equalTo(8f)); + assertThat(farm.cows.getCowFoodPrise(), equalTo(2f)); + assertThat(farm.cows.getCowMilkProduction(), equalTo(3f)); + assertThat(farm.cows.getCowMilkPrice(), equalTo(8f)); + } + + @Test + public void testOfSetMinimalValidFarmParams() { + farm.setFarmParams(500f, 10f, 5f); + assertThat(farm.getFarmPrice(), equalTo(500f)); + assertThat(farm.getPercentIncomeTax(), equalTo(10f)); + assertThat(farm.getPercentSalaryToMilkmaids(), equalTo(5f)); + } + + @Test + public void testOfSetMinimalValidCowParams() { + farm.setCowParams(50, 5f, 1f, 1f, 5f); + assertThat(farm.getNumberOfCows(), equalTo(50)); + assertThat(farm.cows.getCowFoodConsumption(), equalTo(5f)); + assertThat(farm.cows.getCowFoodPrise(), equalTo(1f)); + assertThat(farm.cows.getCowMilkProduction(), equalTo(1f)); + assertThat(farm.cows.getCowMilkPrice(), equalTo(5f)); + } + + @Test + public void testOfSetMaximalValidFarmParams() { + farm.setFarmParams(1000f, 20f, 10f); + assertThat(farm.getFarmPrice(), equalTo(1000f)); + assertThat(farm.getPercentIncomeTax(), equalTo(20f)); + assertThat(farm.getPercentSalaryToMilkmaids(), equalTo(10f)); + } + + @Test + public void testOfSetMaximalValidCowParams() { + farm.setCowParams(100, 10f, 3f, 5f, 10f); + assertThat(farm.getNumberOfCows(), equalTo(100)); + assertThat(farm.cows.getCowFoodConsumption(), equalTo(10f)); + assertThat(farm.cows.getCowFoodPrise(), equalTo(3f)); + assertThat(farm.cows.getCowMilkProduction(), equalTo(5f)); + assertThat(farm.cows.getCowMilkPrice(), equalTo(10f)); + } + + @Test + public void ifFarmParamsLessThenLowerLimitsPrintInputParamsAreIncorrect() { + assertThat(farm.setFarmParams(499f, 15f, 8f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setFarmParams(500f, 9f, 8f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setFarmParams(500f, 15f, 4f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + } + + @Test + public void ifCowParamsLessThenLowerLimitsPrintInputParamsAreIncorrect() { + assertThat(farm.setCowParams(49, 7f, 3f, 5f, 6f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setCowParams(60, 4f, 3f, 5f, 6f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setCowParams(60, 7f, 0f, 5f, 6f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setCowParams(60, 7f, 3f, 0f, 6f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setCowParams(60, 7f, 3f, 5f, 4f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + } + + @Test + public void ifFarmParamsGreaterThenUpperLimitsPrintInputParamsAreIncorrect() { + assertThat(farm.setFarmParams(1001f, 15f, 8f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setFarmParams(700f, 21f, 8f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setFarmParams(1000f, 15f, 11f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + } + + @Test + public void ifCowParamsGreaterThenUpperLimitsPrintInputParamsAreIncorrect() { + assertThat(farm.setCowParams(101, 7f, 3f, 5f, 6f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setCowParams(60, 11f, 3f, 5f, 6f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setCowParams(60, 7f, 4f, 5f, 6f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setCowParams(60, 7f, 3f, 6f, 6f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + assertThat(farm.setCowParams(60, 7f, 3f, 5f, 11f), + equalTo("INPUT PARAMS ARE INCORRECT.")); + } + + @Test + public void testCalculateYearlyAllCowYearlyRevenue() { + assertThat(farm.calculateYearlyAllCowsRevenue(), is(equalTo((3*10-8*3f)*365*50f))); + } + + @Test + public void testCalculateYearlyRevenueAfter10PercentTax() { + assertThat(farm.calculateYearlyRevenueAfterTax(1000f), is(equalTo(900f))); + } + + @Test + public void testCalculateYearlyRevenueAfter10PercentSalary() { + assertThat(farm.calculateYearlyRevenueAfterSalary(2000f), is(equalTo(1800f))); + } + + @Test + public void ifRevenue2000NumberOfFarmsIs4chanceBuyNewFarmsIsSuperProfitable() { + assertThat(farm.calculateChanceBuyNewFarms(2000f), equalTo("SUPER PROFITABLE")); + } + + @Test + public void ifRevenue1500NumberOfFarmsIs3chanceBuyNewFarmsIsProfitable() { + assertThat(farm.calculateChanceBuyNewFarms(1500f), equalTo("PROFITABLE")); + } + + @Test + public void ifRevenue1000NumberOfFarmsIs2chanceBuyNewFarmsIsSuperProfitable() { + assertThat(farm.calculateChanceBuyNewFarms(1000f), equalTo("PROFITABLE")); + } + + + @Test + public void ifRevenue0chanceBuyNewFarmsIsNotProfitable() { + assertThat(farm.calculateChanceBuyNewFarms(0f), equalTo("NOT PROFITABLE")); + } + + @Test + public void testCalculateFarmProfitSuperProfitableResult() { + assertThat(farm.calculateFarmProfit(), equalTo("SUPER PROFITABLE")); + } + + @Test + public void testCalculateFarmProfitProfitableResult() { + farm.setFarmParams(500f, 20f, 10f); + farm.setCowParams(50, 6.65f, 3f, 2f, 10f); + assertThat(farm.calculateFarmProfit(), equalTo("PROFITABLE")); + } + + @Test + public void testCalculateFarmProfitNotProfitableResult() { + farm.setFarmParams(500f, 20f, 10f); + farm.setCowParams(50, 8f, 3f, 2f, 10f); + assertThat(farm.calculateFarmProfit(), equalTo("NOT PROFITABLE")); + } +} diff --git a/lesson_6/.idea/.gitignore b/AlexSubbotin/lesson_11/.idea/.gitignore similarity index 100% rename from lesson_6/.idea/.gitignore rename to AlexSubbotin/lesson_11/.idea/.gitignore diff --git a/AlexSubbotin/lesson_11/.idea/compiler.xml b/AlexSubbotin/lesson_11/.idea/compiler.xml new file mode 100644 index 0000000..5acb896 --- /dev/null +++ b/AlexSubbotin/lesson_11/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_11/.idea/misc.xml b/AlexSubbotin/lesson_11/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_11/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_11/.idea/uiDesigner.xml b/AlexSubbotin/lesson_11/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/AlexSubbotin/lesson_11/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_11/.idea/vcs.xml b/AlexSubbotin/lesson_11/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_11/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_11/lesson_11.iml b/AlexSubbotin/lesson_11/lesson_11.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_11/lesson_11.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_11/pom.xml b/AlexSubbotin/lesson_11/pom.xml new file mode 100644 index 0000000..e6552bd --- /dev/null +++ b/AlexSubbotin/lesson_11/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + org.example + lesson_11 + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + + + + + junit + junit + 4.12 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + junit + junit + 4.13.2 + test + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_11/src/main/java/Main.java b/AlexSubbotin/lesson_11/src/main/java/Main.java new file mode 100644 index 0000000..22b47b6 --- /dev/null +++ b/AlexSubbotin/lesson_11/src/main/java/Main.java @@ -0,0 +1,65 @@ +public class Main { + + public boolean printPairSums(Integer[] arraySorted, int sumValue) { + int firstIndexNumber = 0; + int lastIndexNumber = arraySorted.length - 1; + boolean result = false; + while (firstIndexNumber < lastIndexNumber) { + int pairSum = arraySorted[firstIndexNumber] + arraySorted[lastIndexNumber]; + if (pairSum == sumValue) { + result = true; + firstIndexNumber++; + lastIndexNumber--; + } else { + if (pairSum < sumValue) firstIndexNumber++; + else lastIndexNumber--; + } + } + return result; + } + + + public Integer[] selectionSort(Integer[] array) { + int counter = 0; + for (int i = 0; i < array.length; i++) { + int minValue = array[i]; + int minIndex = i; + for (int j = i + 1; j < array.length; j++) { + if (array[j] < minValue) { + minValue = array[j]; + minIndex = j; + counter++; + } + } + int temp = array[i]; + array[i] = minValue; + array[minIndex] = temp; + } + System.out.println(counter); + return array; + } + + + public int printFibonacciSequenceMemberByRecursion(int memberNumber) { + if (memberNumber == 0) { + return 0; + } + if (memberNumber == 1) { + return 1; + } else { + return printFibonacciSequenceMemberByRecursion(memberNumber - 1) + + printFibonacciSequenceMemberByRecursion(memberNumber - 2); + } + } + + public int printFibonacciSequenceMemberWithOutRecursion(int memberNumber) { + int firstIndex = 0; + int secondIndex = 1; + for (int i = 2; i <= memberNumber; ++i) { + int nextNumber = firstIndex + secondIndex; + firstIndex = secondIndex; + secondIndex = nextNumber; + } + return secondIndex; + } +} diff --git a/AlexSubbotin/lesson_11/src/main/java/usersContainer/Container.java b/AlexSubbotin/lesson_11/src/main/java/usersContainer/Container.java new file mode 100644 index 0000000..7048411 --- /dev/null +++ b/AlexSubbotin/lesson_11/src/main/java/usersContainer/Container.java @@ -0,0 +1,22 @@ +package usersContainer; + +public class Container { + private User user; + private Container nextContainer; + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Container getNextContainer() { + return nextContainer; + } + + public void setNextContainer(Container nextContainer) { + this.nextContainer = nextContainer; + } +} diff --git a/AlexSubbotin/lesson_11/src/main/java/usersContainer/User.java b/AlexSubbotin/lesson_11/src/main/java/usersContainer/User.java new file mode 100644 index 0000000..e6332d0 --- /dev/null +++ b/AlexSubbotin/lesson_11/src/main/java/usersContainer/User.java @@ -0,0 +1,46 @@ +package usersContainer; + +import java.util.Objects; + +public class User { + private String name; + private int age; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + User user = (User) o; + return age == user.age && + Objects.equals(name, user.name); + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } + + @Override + public String toString() { + return "User{" + + "name='" + name + '\'' + + ", age=" + age + + '}'; + } +} diff --git a/AlexSubbotin/lesson_11/src/main/java/usersContainer/UsersManager.java b/AlexSubbotin/lesson_11/src/main/java/usersContainer/UsersManager.java new file mode 100644 index 0000000..9aa7bc6 --- /dev/null +++ b/AlexSubbotin/lesson_11/src/main/java/usersContainer/UsersManager.java @@ -0,0 +1,186 @@ +package usersContainer; + +public class UsersManager { + private int counter; + private Container head; + + public void addUser(User user) { + if (this.head == null) { + this.head = new Container(); + this.head.setUser(user); + } + Container temp = new Container(); + temp.setUser(user); + Container current = this.head; + if (current != null) { + while (current.getNextContainer() != null) { + current = current.getNextContainer(); + } + current.setNextContainer(temp); + } + incrementCounter(); + } + + public void addArrayOfUsers(User[] users) { + for (User user : users) { + addUser(user); + } + } + + public void removeUser(User user) { + Container current = this.head; + for (int i = 0; i < this.counter; i++) { + if (current.getNextContainer().getUser().equals(user)) { + current.setNextContainer(current.getNextContainer().getNextContainer()); + decrementCounter(); + removeUser(user); + } + current = current.getNextContainer(); + } + } + + public void insertUserByIndex(User user, int index) { + Container current = this.head; + Container temp = new Container(); + temp.setUser(user); + for (int i = 0; i < index; i++) { + current = current.getNextContainer(); + } + temp.setNextContainer(current.getNextContainer()); + current.setNextContainer(temp); + incrementCounter(); + } + + public void updateUserByIndex(User user, int index) { + Container temp = new Container(); + temp.setUser(user); + Container current = this.head; + for (int i = 0; i < index; i++) { + current = current.getNextContainer(); + } + temp.setNextContainer(current.getNextContainer().getNextContainer()); + current.setNextContainer(temp); + } + + public User findUserByName(String name) { + Container current = this.head; + User userTemp = new User(); + String userName; + for (int i = 0; i < this.counter; i++) { + current = current.getNextContainer(); + userName = current.getUser().getName(); + if (userName.equals(name)) { + userTemp = current.getUser(); + } + } + return userTemp; + } + + public User[] getUsersOrderedByName() { + boolean isSorted = false; + User temp1; + User temp2; + User userWithLowestName; + while (!isSorted) { + isSorted = true; + for (int i = 0; i < counter - 1; i++) { + temp1 = getUserByIndex(i); + temp2 = getUserByIndex(i + 1); + userWithLowestName = getUserWithLowerName(temp1, temp2); + if (userWithLowestName.equals(temp2)) { + isSorted = false; + updateUserByIndex(temp2, i); + updateUserByIndex(temp1, i + 1); + } + } + } + return getArrayUsers(); + } + + public User[] getUsersOrderedByAge() { + boolean isSorted = false; + User temp1; + User temp2; + User userWithLowestAge; + while (!isSorted) { + isSorted = true; + for (int i = 0; i < this.counter - 1; i++) { + temp1 = getUserByIndex(i); + temp2 = getUserByIndex(i + 1); + userWithLowestAge = getUserWithLowerAge(temp1, temp2); + if (userWithLowestAge.equals(temp2)) { + isSorted = false; + updateUserByIndex(temp2, i); + updateUserByIndex(temp1, i + 1); + } + } + } + return getArrayUsers(); + } + + public User getUserByIndex(int index) { + Container current = this.head; + int position = 0; + while (position <= index) { + current = current.getNextContainer(); + position++; + } + User user = current.getUser(); + return user; + } + + + private User getUserWithLowerName(User firstUser, User secondUser) { + String firstUserName = firstUser.getName(); + String secondUserName = secondUser.getName(); + int firstLength = firstUserName.length(); + int secondLength = secondUserName.length(); + int minLength = firstLength <= secondLength ? firstLength : secondLength; + for (int i = 0; i < minLength; i++) { + char first = firstUserName.charAt(i); + char second = secondUserName.charAt(i); + if (first < second) { + return firstUser; + } + if (first > second) { + return secondUser; + } + } + return firstUser; + } + + private User getUserWithLowerAge(User firstUser, User secondUser) { + int firstUserAge = firstUser.getAge(); + int secondUserAge = secondUser.getAge(); + + if (firstUserAge <= secondUserAge) { + return firstUser; + } else { + return secondUser; + } + } + + private User[] getArrayUsers() { + Container current; + current = head; + User[] sortedUsers = new User[counter]; + for (int i = 0; i < counter; i++) { + sortedUsers[i] = current.getNextContainer().getUser(); + current = current.getNextContainer(); + } + return sortedUsers; + } + + private void incrementCounter() { + counter++; + } + + private void decrementCounter() { + counter--; + } + + public int getSizeOfContainer() { + return this.counter; + } + +} diff --git a/AlexSubbotin/lesson_11/src/test/java/MainTest.java b/AlexSubbotin/lesson_11/src/test/java/MainTest.java new file mode 100644 index 0000000..3ca7f78 --- /dev/null +++ b/AlexSubbotin/lesson_11/src/test/java/MainTest.java @@ -0,0 +1,99 @@ +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.equalTo; + +public class MainTest { + Main main = new Main(); + + @Test + public void testPrintPairSumsIfNegativeNumbersResultTrue() { + Integer[] sortedArray = {-7, -5, -3, -2, -1}; + int sum = -10; + assertThat(main.printPairSums(sortedArray, sum), equalTo(true)); + } + + @Test + public void testPrintPairSumsIfPositiveNumbersResultTrue() { + Integer[] sortedArray = {1, 2, 3, 5, 7}; + int sum = 10; + assertThat(main.printPairSums(sortedArray, sum), equalTo(true)); + } + + @Test + public void testPrintPairSumsForResultFalse() { + Integer[] sortedArray = {1, 2, 3, 5, 7}; + int sum = 11; + assertThat(main.printPairSums(sortedArray, sum), equalTo(false)); + } + + @Test + public void testPrintPairSumsIfSameNumbersResultTrue() { + Integer[] sortedArray = {1, 1, 3, 3, 7, 7}; + int sum = 4; + assertThat(main.printPairSums(sortedArray, sum), equalTo(true)); + } + + @Test + public void testPrintPairSumsIfSameAllNumbersResultTrue() { + Integer[] sortedArray = {1, 1, 1, 1, 1, 1}; + int sum = 2; + assertThat(main.printPairSums(sortedArray, sum), equalTo(true)); + } + + @Test + public void testSelectionSortIfPositiveNumbers() { + Integer[] array = {10, 3, 2, 5, 7, 9, 8, 1, 4, 6}; + assertThat(main.selectionSort(array), arrayContaining(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + } + + @Test + public void testSelectionSortIfPositiveNumbersArrayDoubleSize() { + Integer[] array = {10, 3, 2, 5, 7, 9, 8, 1, 4, 6, 0, 3, 2, 5, 7, 9, 8, 1, 4, 6}; + assertThat(main.selectionSort(array), + arrayContaining(0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10)); + } + + @Test + public void testSelectionSortIfNegativeNumbers() { + Integer[] array = {-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}; + assertThat(main.selectionSort(array), arrayContaining(-10, -9, -8, -7, -6, -5, -4, -3, -2, -1)); + } + + @Test + public void testSelectionSortIfSameNumbers() { + Integer[] array = {-1, -1, -3, 4, 5, 6, 7, 8, 8, -10}; + assertThat(main.selectionSort(array), arrayContaining(-10, -3, -1, -1, 4, 5, 6, 7, 8, 8)); + } + + @Test + public void testPrintFibonacciSequenceMemberWithOutRecursion() { + assertThat(main.printFibonacciSequenceMemberWithOutRecursion(10), equalTo(55)); + } + + @Test + public void testPrintFibonacciFirstMemberWithOutRecursionMustBe1() { + assertThat(main.printFibonacciSequenceMemberWithOutRecursion(1), equalTo(1)); + } + + @Test + public void testPrintFibonacciSecondMemberWithOutRecursionMustBe1() { + assertThat(main.printFibonacciSequenceMemberWithOutRecursion(2), equalTo(1)); + } + + @Test + public void testPrintFibonacciSequenceMemberWithRecursion() { + assertThat(main.printFibonacciSequenceMemberByRecursion(3), equalTo(2)); + } + + @Test + public void testPrintFibonacciFirstMemberByRecursionMustBe1() { + assertThat(main.printFibonacciSequenceMemberByRecursion(1), equalTo(1)); + } + + @Test + public void testPrintFibonacciSecondMemberByRecursionMustBe1() { + assertThat(main.printFibonacciSequenceMemberByRecursion(2), equalTo(1)); + } +} diff --git a/AlexSubbotin/lesson_11/src/test/java/usersContainer/ContainerTest.java b/AlexSubbotin/lesson_11/src/test/java/usersContainer/ContainerTest.java new file mode 100644 index 0000000..03dd3de --- /dev/null +++ b/AlexSubbotin/lesson_11/src/test/java/usersContainer/ContainerTest.java @@ -0,0 +1,20 @@ +package usersContainer; + +import org.hamcrest.Matchers; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; + +public class ContainerTest { + Container container = new Container(); + + @Test + public void testContainerHasFieldUser() { + assertThat(container, Matchers.hasProperty("user")); + } + + @Test + public void testContainerHasFieldNextContainer() { + assertThat(container, Matchers.hasProperty("nextContainer")); + } +} diff --git a/AlexSubbotin/lesson_11/src/test/java/usersContainer/UserTest.java b/AlexSubbotin/lesson_11/src/test/java/usersContainer/UserTest.java new file mode 100644 index 0000000..bc7278e --- /dev/null +++ b/AlexSubbotin/lesson_11/src/test/java/usersContainer/UserTest.java @@ -0,0 +1,20 @@ +package usersContainer; + +import org.hamcrest.Matchers; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; + +public class UserTest { + User user = new User(); + + @Test + public void testUserHasFieldName() { + assertThat(user, Matchers.hasProperty("name")); + } + + @Test + public void testUserHasFieldAge() { + assertThat(user, Matchers.hasProperty("age")); + } +} diff --git a/AlexSubbotin/lesson_11/src/test/java/usersContainer/UsersManagerTest.java b/AlexSubbotin/lesson_11/src/test/java/usersContainer/UsersManagerTest.java new file mode 100644 index 0000000..30a4cb2 --- /dev/null +++ b/AlexSubbotin/lesson_11/src/test/java/usersContainer/UsersManagerTest.java @@ -0,0 +1,153 @@ +package usersContainer; + +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class UsersManagerTest { + UsersManager usersManager = new UsersManager(); + User user1 = new User(); + User user2 = new User(); + User user3 = new User(); + User user4 = new User(); + + @Before + public void initUsers() { + user1.setName("FIRST USER"); + user1.setAge(10); + user2.setName("SECOND USER"); + user2.setAge(20); + user3.setName("THIRD USER"); + user3.setAge(30); + user4.setName("FOURTH USER"); + user4.setAge(40); + + } + + @Test + public void testAddUser() { + usersManager.addUser(user1); + usersManager.addUser(user2); + usersManager.addUser(user3); + usersManager.addUser(user4); + assertThat(usersManager.getUserByIndex(0).toString(), equalTo("User{name='FIRST USER', age=10}")); + assertThat(usersManager.getUserByIndex(1).toString(), equalTo("User{name='SECOND USER', age=20}")); + assertThat(usersManager.getUserByIndex(2).toString(), equalTo("User{name='THIRD USER', age=30}")); + assertThat(usersManager.getUserByIndex(3).toString(), equalTo("User{name='FOURTH USER', age=40}")); + } + + @Test + public void testAddArrayOfUsers() { + User[] users = new User[4]; + users[0] = user4; + users[1] = user3; + users[2] = user2; + users[3] = user1; + usersManager.addArrayOfUsers(users); + assertThat(usersManager.getUserByIndex(0).toString(), equalTo("User{name='FOURTH USER', age=40}")); + assertThat(usersManager.getUserByIndex(1).toString(), equalTo("User{name='THIRD USER', age=30}")); + assertThat(usersManager.getUserByIndex(2).toString(), equalTo("User{name='SECOND USER', age=20}")); + assertThat(usersManager.getUserByIndex(3).toString(), equalTo("User{name='FIRST USER', age=10}")); + } + + @Test + public void removeUserSizeOfContainerShouldBeLessBy1() { + usersManager.addUser(user1); + usersManager.addUser(user2); + usersManager.addUser(user3); + usersManager.addUser(user4); + usersManager.removeUser(user2); + assertThat(usersManager.getUserByIndex(0).toString(), equalTo("User{name='FIRST USER', age=10}")); + assertThat(usersManager.getUserByIndex(1).toString(), equalTo("User{name='THIRD USER', age=30}")); + assertThat(usersManager.getUserByIndex(2).toString(), equalTo("User{name='FOURTH USER', age=40}")); + assertThat(usersManager.getSizeOfContainer(), equalTo(3)); + + } + + @Test + public void removeUserSizeOfContainerShouldBeLessBy2IfSameUsers() { + usersManager.addUser(user2); + usersManager.addUser(user2); + usersManager.addUser(user2); + usersManager.addUser(user4); + usersManager.removeUser(user2); + assertThat(usersManager.getUserByIndex(0).toString(), equalTo("User{name='FOURTH USER', age=40}")); + assertThat(usersManager.getSizeOfContainer(), equalTo(1)); + + } + + @Test + public void insertUserByIndexSizeOfContainerShouldBeGreaterBy1AndUserInfoAdded() { + usersManager.addUser(user1); + usersManager.addUser(user2); + usersManager.addUser(user3); + usersManager.addUser(user4); + usersManager.insertUserByIndex(user1, 2); + assertThat(usersManager.getUserByIndex(0).toString(), equalTo("User{name='FIRST USER', age=10}")); + assertThat(usersManager.getUserByIndex(1).toString(), equalTo("User{name='SECOND USER', age=20}")); + assertThat(usersManager.getUserByIndex(2).toString(), equalTo("User{name='FIRST USER', age=10}")); + assertThat(usersManager.getUserByIndex(3).toString(), equalTo("User{name='THIRD USER', age=30}")); + assertThat(usersManager.getUserByIndex(4).toString(), equalTo("User{name='FOURTH USER', age=40}")); + assertThat(usersManager.getSizeOfContainer(), equalTo(5)); + } + + @Test + public void updateUserByIndexSizeOfContainerShouldBeSameAndUserInfoUpdate() { + usersManager.addUser(user1); + usersManager.addUser(user2); + usersManager.addUser(user3); + usersManager.addUser(user4); + usersManager.updateUserByIndex(user1, 2); + assertThat(usersManager.getUserByIndex(0).toString(), equalTo("User{name='FIRST USER', age=10}")); + assertThat(usersManager.getUserByIndex(1).toString(), equalTo("User{name='SECOND USER', age=20}")); + assertThat(usersManager.getUserByIndex(2).toString(), equalTo("User{name='FIRST USER', age=10}")); + assertThat(usersManager.getUserByIndex(3).toString(), equalTo("User{name='FOURTH USER', age=40}")); + assertThat(usersManager.getSizeOfContainer(), equalTo(4)); + } + + @Test + public void findUserByName() { + usersManager.addUser(user1); + usersManager.addUser(user2); + usersManager.addUser(user3); + usersManager.addUser(user4); + assertThat(usersManager.findUserByName("SECOND USER").toString(), + equalTo("User{name='SECOND USER', age=20}")); + } + + @Test + public void getUsersOrderedByAgeReturnSortedByAgeArrayOfUsers() { + user4.setAge(85); + usersManager.addUser(user4); + user3.setAge(55); + usersManager.addUser(user3); + user2.setAge(45); + usersManager.addUser(user2); + user1.setAge(15); + usersManager.addUser(user1); + User[] sortedUsersArray = usersManager.getUsersOrderedByAge(); + assertThat(sortedUsersArray[0], equalTo(user1)); + assertThat(sortedUsersArray[1], equalTo(user2)); + assertThat(sortedUsersArray[2], equalTo(user3)); + assertThat(sortedUsersArray[3], equalTo(user4)); + } + + @Test + public void getUsersOrderedByNameReturnSortedByNameArrayOfUsers() { + user4.setName("aaa"); + usersManager.addUser(user4); + user3.setName("aab"); + usersManager.addUser(user3); + user2.setName("ccc"); + usersManager.addUser(user2); + user1.setName("ab"); + usersManager.addUser(user1); + User[] sortedUsersArray = usersManager.getUsersOrderedByName(); + assertThat(sortedUsersArray[0], equalTo(user4)); + assertThat(sortedUsersArray[1], equalTo(user3)); + assertThat(sortedUsersArray[2], equalTo(user1)); + assertThat(sortedUsersArray[3], equalTo(user2)); + } +} diff --git a/AlexSubbotin/lesson_9/.idea/.gitignore b/AlexSubbotin/lesson_9/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_9/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/lesson_6/.idea/misc.xml b/AlexSubbotin/lesson_9/.idea/misc.xml similarity index 100% rename from lesson_6/.idea/misc.xml rename to AlexSubbotin/lesson_9/.idea/misc.xml diff --git a/lesson_6/.idea/modules.xml b/AlexSubbotin/lesson_9/.idea/modules.xml similarity index 61% rename from lesson_6/.idea/modules.xml rename to AlexSubbotin/lesson_9/.idea/modules.xml index e60485c..95f2885 100644 --- a/lesson_6/.idea/modules.xml +++ b/AlexSubbotin/lesson_9/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/AlexSubbotin/lesson_9/.idea/vcs.xml b/AlexSubbotin/lesson_9/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_9/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lesson_6/lesson_6.iml b/AlexSubbotin/lesson_9/lesson_9.iml similarity index 100% rename from lesson_6/lesson_6.iml rename to AlexSubbotin/lesson_9/lesson_9.iml diff --git a/AlexSubbotin/lesson_9/src/Circle.java b/AlexSubbotin/lesson_9/src/Circle.java new file mode 100644 index 0000000..c5db939 --- /dev/null +++ b/AlexSubbotin/lesson_9/src/Circle.java @@ -0,0 +1,17 @@ +public class Circle extends Figures { + private double radius; + + public void setRadius (double radius) { + this.radius = radius; + } + + public double getPerimeter() { + double perimeter = this.radius * 2 * Math.PI; + return perimeter; + } + + public double getArea() { + double area = Math.pow(this.radius, 2) * Math.PI; + return area; + } +} diff --git a/AlexSubbotin/lesson_9/src/Figures.java b/AlexSubbotin/lesson_9/src/Figures.java new file mode 100644 index 0000000..6a17290 --- /dev/null +++ b/AlexSubbotin/lesson_9/src/Figures.java @@ -0,0 +1,9 @@ +public abstract class Figures { + public double getPerimeter () { + return 0; + } + + public double getArea () { + return 0; + } +} diff --git a/AlexSubbotin/lesson_9/src/Homework_9.java b/AlexSubbotin/lesson_9/src/Homework_9.java new file mode 100644 index 0000000..4ecca70 --- /dev/null +++ b/AlexSubbotin/lesson_9/src/Homework_9.java @@ -0,0 +1,88 @@ +import java.util.Scanner; + +public class Homework_9 { + public static void main(String[] args) { +// 1) Напишите программу, которая заменяет символы в почтовом адресе пользователя: +// @ заменяется на [ at ] +// . заменяется на [ dot ] +// Пример ввода: +// person@gmail.com +// Результат: +// person[ at ]gmail[ dot ].com + + System.out.println("Please, enter email:"); + Scanner scanner = new Scanner(System.in); + String email = scanner.nextLine(); + + charChanger(email); + +// 2) i18n используется для обозначения слова internationalization, где 18 означает количество +// букв между первой и последней в этом слове, такое можно встретить в среде разработчиков. +// Например, для слова localization используется сокращение l10n. +// Напишите функцию, которая преобразует слова введенные из консоли через пробел в сокращенную форму. +// Слова длиной меньше 4х оставить без изменений. +// Пример ввода: +// internationalization localization cat elephant monitor +// Результат: +// i18n l10n cat e6t m5r +// PS: напишите функцию, которая сокращает слово, в основной функции используйте метод сплит, который поместит +// слова в массив и для каждого из них вызовет вашу функцию + + String enteredWords = "internationalization localization cat elephant monitor"; + String[] wordsArray = enteredWords.split(" "); + for (String fullWord : wordsArray) { + if (fullWord.length() >= 4) { + String resultWord = wordChanger(fullWord); + System.out.println(fullWord + " : " + resultWord); + } else { + System.out.println(fullWord); + } + } + +// 3) Создайте несколько классов геометрических фигур с инстанс методами: +// - getArea (расчет площади) +// - getPerimeter (расчет периметра) + + Circle firstCircle = new Circle(); + firstCircle.setRadius(10); + + Rhombus firstRhombus = new Rhombus(); + firstRhombus.setFirstSide(10); + firstRhombus.setHeight(8.66); + + Square firstSquare = new Square(); + firstSquare.setFirstSide(5); + + +// 4) Занесите все фигуры в массив и пощитайте в нем сумму площадей и периметров для всех фигур + + Figures[] figures = new Figures[3]; + figures[0] = firstCircle; + figures[1] = firstRhombus; + figures[2] = firstSquare; + + double sumAllPerimeters = 0; + double sumAllAreas = 0; + + for (int i = 0; i < figures.length; i++) { + sumAllAreas += figures[i].getArea(); + sumAllPerimeters += figures[i].getPerimeter(); + } + System.out.println("Sum of all areas: " + sumAllAreas); + System.out.println("Sum of all perimeters: " + sumAllPerimeters); + } + + private static String wordChanger(String fullWord) { + StringBuilder stringBuilder = new StringBuilder(fullWord); + String middleCharLength = String.valueOf(stringBuilder.length() - 2); + String resultWord = String.valueOf(stringBuilder.replace(1, stringBuilder.length() - 1, middleCharLength)); + return resultWord; + } + + private static void charChanger(String email) { + email = email + .replace("@", "[ at ]") + .replace(".", "[ dot ]"); + System.out.println(email); + } +} diff --git a/AlexSubbotin/lesson_9/src/Rhombus.java b/AlexSubbotin/lesson_9/src/Rhombus.java new file mode 100644 index 0000000..1a7ab7f --- /dev/null +++ b/AlexSubbotin/lesson_9/src/Rhombus.java @@ -0,0 +1,24 @@ +public class Rhombus extends Figures { + private double firstSide; + + private double height; + + + public void setFirstSide (double firstSide) { + this.firstSide = firstSide; + } + public void setHeight (double height) { + this.height = height; + } + + + public double getPerimeter () { + double perimeter = this.firstSide * 4; + return perimeter; + } + + public double getArea () { + double area = this.firstSide * this.height; + return area; + } +} diff --git a/AlexSubbotin/lesson_9/src/Square.java b/AlexSubbotin/lesson_9/src/Square.java new file mode 100644 index 0000000..5684d0b --- /dev/null +++ b/AlexSubbotin/lesson_9/src/Square.java @@ -0,0 +1,19 @@ +public class Square extends Figures { + private double firstSide; + + + public void setFirstSide (double firstSide) { + this.firstSide = firstSide; + } + + public double getPerimeter () { + double perimeter = this.firstSide * 4; + return perimeter; + } + + public double getArea () { + double area = Math.pow(this.firstSide, 2); + return area; + } +} + diff --git a/lesson_6/out/production/lesson_6/META-INF/lesson_6.kotlin_module b/lesson_6/out/production/lesson_6/META-INF/lesson_6.kotlin_module deleted file mode 100644 index a49347afef10a9b5f95305e1058ba36adec7d6dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16 RcmZQzU|?ooU|@t|0RRA102TlM diff --git a/lesson_6/out/production/lesson_6/Main.class b/lesson_6/out/production/lesson_6/Main.class deleted file mode 100644 index 45fb38a68de1ff4642e2ad2bd55cd56d137074de..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4288 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 diff --git a/lesson_6/src/Main.java b/lesson_6/src/Main.java deleted file mode 100644 index 6c10414..0000000 --- a/lesson_6/src/Main.java +++ /dev/null @@ -1,155 +0,0 @@ -public class Main { - public static void main(String[] args) { - // 1) Создайте программу, выводящую на экран все четырёхзначные - // числа последовательности 1000 1003 1006 1009 1012 1015 …. - taskOne(); - // 2) Создайте программу, выводящую на экран первые 55 элементов - // последовательности 1 3 5 7 9 11 13 15 17 …. - taskTwo(); - // 3) Создайте программу, выводящую на экран все неотрицательные элементы - // последовательности 90 85 80 75 70 65 60 …. - taskThree(); - // 4) Создайте программу, выводящую на экран первые 20 элементов - // последовательности 2 4 8 16 32 64 128 …. - taskFour(); - // 5) Найти сумму первых n элементов массива - int n = 5; - int[] arr = new int[]{200, 100, -3, 400, 2, 600, 1, 100, 150, -9, 10, 23, 40, 56, 100}; - taskFive(arr, n); - // 6) Найти минимальный и максимальный элемент массива - taskSix(arr); - // 7) Найти сумму всех четных и сумму всех нечетных элементов массива - taskSeven(arr); - // 8) Найти все счастливые билеты от 100000 до 999999 : - // билет счастливый если сумма первых трех цифр равна сумме трех последних - // например, 123312: 1+2+3==3+1+2 - taskEight(); - // 9) Создайте программу которая устанавливает введеный номер бита в 1 у введенного числа, - // выведите на экран полученое число в двоичной и десятеричной системе счисления - taskNine(8, 10); - // 10) Вывести первые 5 минимальных элементов массива - taskTen(arr); - } - - public static void taskOne() { - System.out.println("TASK 1"); - for (int i = 1000; i < 10000; i += 3) { - System.out.println(i); - } - } - - public static void taskTwo() { - System.out.println("TASK 2"); - int counter = 0; - for (int i = 1; ; i += 2) { - System.out.println(i); - counter++; - if (counter == 55) { - break; - } - } - } - - public static void taskThree() { - System.out.println("TASK 3"); - for (int i = 90; i >= 0; i -= 5) { - System.out.println(i); - } - } - - public static void taskFour() { - System.out.println("TASK 4"); - int startNumber = 2; - int counter = 0; - for (int i = 0; ; i++) { - System.out.println(startNumber << i); - counter++; - if (counter == 20) { - break; - } - } - } - - public static void taskFive(int array[], int n) { - System.out.println("TASK 5"); - int sumElements = 0; - for (int i = 0; i < n; i++) { - sumElements += array[i]; - } - System.out.println(sumElements); - } - - public static void taskSix(int array[]) { - System.out.println("TASK 6"); - int minElement = array[0]; - int maxElement = array[0]; - for (int i = 1; i < array.length; i++) { - if (array[i] <= minElement) { - minElement = array[i]; - } - if (array[i] >= maxElement) { - maxElement = array[i]; - } - } - System.out.println("Minimal element of array: " + minElement); - System.out.println("Maximal element of array: " + maxElement); - } - - public static void taskSeven(int array[]) { - System.out.println("TASK 7"); - int sumEvenElements = 0; - int sumOddElements = 0; - for (int element : array) { - if (element % 2 == 0) { - sumEvenElements += element; - } else { - sumOddElements += element; - } - } - System.out.format("Even elements sum: %d\n", sumEvenElements); - System.out.format("Odd elements sum: %d\n", sumOddElements); - } - - public static void taskEight() { - System.out.println("TASK 8"); - int luckyTicketCounter = 0; - for (int ticketNumber = 100_000; ticketNumber <= 999_999; ticketNumber++) { - int leftPartSum = ticketNumber / 100_000 + (ticketNumber / 10_000) % 10 + (ticketNumber / 1_000) % 10; - int rightPartSum = (ticketNumber / 100) % 10 + (ticketNumber / 10) % 10 + ticketNumber % 10; - if (leftPartSum == rightPartSum) { - luckyTicketCounter++; - } - } - System.out.println("The number of lucky tickets: " + luckyTicketCounter); - } - - public static void taskNine(int bitNumber, int number) { - System.out.println("TASK 9"); - int binaryBitNumber = (int) Math.pow(2, (bitNumber - 1)); - int result = number | binaryBitNumber; - System.out.println("Entered bit number: " + bitNumber); - System.out.println("Entered number: " + Integer.toBinaryString(number)); - System.out.println("Switched bit number: " + Integer.toBinaryString(result)); - System.out.println("Decimal result: " + result); - } - - public static void taskTen(int array[]) { - System.out.println("TASK 10"); - boolean sorted = false; - int temp; - while (!sorted) { - sorted = true; - for (int i = 0; i < array.length - 1; i++) { - if (array[i] > array[i + 1]) { - sorted = false; - temp = array[i]; - array[i] = array[i + 1]; - array[i + 1] = temp; - } - } - } - for (int i = 0; i < 5; i++) { - System.out.println(array[i]); - } - } -} From 0090488da8c85b25e78ea016d7cacc15ba4f9d80 Mon Sep 17 00:00:00 2001 From: Militaryus Date: Sun, 28 Feb 2021 14:52:55 +0200 Subject: [PATCH 5/5] lesson_12_13_21_23_24_25_26 --- AlexSubbotin/lesson_12/.idea/.gitignore | 2 + AlexSubbotin/lesson_12/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_12/.idea/misc.xml | 14 ++ AlexSubbotin/lesson_12/.idea/vcs.xml | 6 + AlexSubbotin/lesson_12/lesson_12.iml | 2 + AlexSubbotin/lesson_12/pom.xml | 39 ++++++ .../lesson_12/src/main/java/Main.java | 52 ++++++++ .../src/main/java/animalInfo/Animal.java | 25 ++++ .../src/main/java/animalInfo/AnimalInfo.java | 6 + .../src/main/java/animalInfo/BigCats.java | 23 ++++ .../src/main/java/animalInfo/Caracals.java | 23 ++++ .../src/main/java/animalInfo/Carnivora.java | 24 ++++ .../src/main/java/animalInfo/Cats.java | 28 ++++ .../main/java/animalInfo/DomesticCats.java | 27 ++++ .../src/main/java/animalInfo/ForestCats.java | 24 ++++ .../src/main/java/animalInfo/Herbivorous.java | 23 ++++ .../src/main/java/animalInfo/Lion.java | 22 ++++ .../src/main/java/animalInfo/Mammals.java | 23 ++++ .../src/main/java/animalInfo/Persian.java | 30 +++++ .../src/main/java/animalInfo/Siam.java | 35 +++++ .../src/main/java/animalInfo/SmallCats.java | 24 ++++ .../src/main/java/animalInfo/Tigers.java | 22 ++++ .../lesson_12/src/test/java/TestMain.java | 86 ++++++++++++ AlexSubbotin/lesson_13/.idea/.gitignore | 2 + AlexSubbotin/lesson_13/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_13/.idea/misc.xml | 14 ++ AlexSubbotin/lesson_13/.idea/vcs.xml | 6 + AlexSubbotin/lesson_13/lesson_13.iml | 2 + AlexSubbotin/lesson_13/pom.xml | 33 +++++ .../lesson_13/src/main/java/User.java | 54 ++++++++ .../src/main/java/store/Category.java | 27 ++++ .../src/main/java/store/Product.java | 38 ++++++ .../lesson_13/src/test/java/UserTest.java | 46 +++++++ .../src/test/java/store/CategoryTest.java | 56 ++++++++ .../src/test/java/store/ProductTest.java | 18 +++ AlexSubbotin/lesson_21/.idea/.gitignore | 2 + AlexSubbotin/lesson_21/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_21/.idea/misc.xml | 14 ++ AlexSubbotin/lesson_21/.idea/vcs.xml | 6 + AlexSubbotin/lesson_21/lesson_21.iml | 2 + AlexSubbotin/lesson_21/pom.xml | 27 ++++ .../src/main/java/shopsolid/Checker.java | 8 ++ .../java/shopsolid/ConfirmationSender.java | 6 + .../main/java/shopsolid/OrderCollector.java | 8 ++ .../OrderCollectorSendControler.java | 23 ++++ ...llectorSendControllerWithConfirmation.java | 24 ++++ .../src/main/java/shopsolid/OrderSender.java | 6 + .../src/main/java/shopsolid/Preparer.java | 8 ++ .../src/main/java/shopsolid/Product.java | 28 ++++ .../main/java/shopsolid/ProductChecker.java | 14 ++ .../main/java/shopsolid/ProductPreparer.java | 10 ++ .../src/main/java/shopsolid/Stock.java | 20 +++ .../test/java/OrderSendControllerTest.java | 37 ++++++ AlexSubbotin/lesson_23/.idea/.gitignore | 2 + AlexSubbotin/lesson_23/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_23/.idea/misc.xml | 14 ++ AlexSubbotin/lesson_23/.idea/vcs.xml | 6 + AlexSubbotin/lesson_23/lesson_23.iml | 2 + AlexSubbotin/lesson_23/pom.xml | 12 ++ .../java/abstractf/AbstractCarFactory.java | 22 ++++ .../java/abstractf/AbstractFactoryClient.java | 19 +++ .../src/main/java/abstractf/DodgeFactory.java | 12 ++ .../src/main/java/abstractf/DodgePickup.java | 23 ++++ .../src/main/java/abstractf/DodgeSedan.java | 23 ++++ .../src/main/java/abstractf/Factory.java | 7 + .../src/main/java/abstractf/Pickup.java | 6 + .../src/main/java/abstractf/Sedan.java | 6 + .../src/main/java/abstractf/VAGFactory.java | 12 ++ .../src/main/java/abstractf/VAGPickup.java | 23 ++++ .../src/main/java/abstractf/VAGSedan.java | 23 ++++ .../src/main/java/builder/BuilderClient.java | 21 +++ .../lesson_23/src/main/java/builder/User.java | 95 ++++++++++++++ .../src/main/java/factorym/ExcelReport.java | 25 ++++ .../java/factorym/FactoryMethodClient.java | 11 ++ .../src/main/java/factorym/PDFReport.java | 25 ++++ .../src/main/java/factorym/Report.java | 21 +++ .../src/main/java/factorym/ReportCreator.java | 7 + .../main/java/prototype/ClientPrototype.java | 17 +++ .../java/prototype/RectangularWindow.java | 39 ++++++ .../src/main/java/prototype/RoundWindow.java | 25 ++++ .../src/main/java/prototype/Window.java | 21 +++ .../main/java/singleton/ClientSingleton.java | 11 ++ .../src/main/java/singleton/Singleton.java | 16 +++ AlexSubbotin/lesson_24/.idea/.gitignore | 2 + AlexSubbotin/lesson_24/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_24/.idea/misc.xml | 14 ++ AlexSubbotin/lesson_24/.idea/uiDesigner.xml | 124 ++++++++++++++++++ AlexSubbotin/lesson_24/.idea/vcs.xml | 6 + AlexSubbotin/lesson_24/lesson_24.iml | 2 + AlexSubbotin/lesson_24/pom.xml | 12 ++ .../src/main/java/adapter/AdapterClient.java | 12 ++ .../src/main/java/adapter/PlugAdapter.java | 6 + .../java/adapter/PlugToSocketAdapter.java | 15 +++ .../main/java/adapter/PlugWithThreeLegs.java | 14 ++ .../main/java/adapter/TwoLeggedSocket.java | 8 ++ .../src/main/java/bridge/BridgeClient.java | 18 +++ .../src/main/java/bridge/MagazineWriter.java | 8 ++ .../src/main/java/bridge/Newspaper.java | 13 ++ .../src/main/java/bridge/NewspaperWriter.java | 8 ++ .../lesson_24/src/main/java/bridge/Press.java | 12 ++ .../src/main/java/bridge/SportMagazine.java | 13 ++ .../src/main/java/bridge/Writer.java | 6 + .../main/java/composite/CompositeClient.java | 18 +++ .../src/main/java/composite/NewsWriter.java | 8 ++ .../main/java/composite/NewspaperFactory.java | 25 ++++ .../main/java/composite/SportNewsWriter.java | 8 ++ .../src/main/java/composite/Writer.java | 6 + .../main/java/decorator/DecoratorClient.java | 11 ++ .../java/decorator/EmailReportDuplicator.java | 17 +++ .../src/main/java/decorator/PaperReport.java | 8 ++ .../main/java/decorator/ReportDecorator.java | 14 ++ .../src/main/java/decorator/ReportSender.java | 5 + .../main/java/decorator/SmsConfirmSender.java | 17 +++ .../src/main/java/facade/CarAssembler.java | 20 +++ .../src/main/java/facade/CarBodyPainter.java | 20 +++ .../src/main/java/facade/CarWasher.java | 13 ++ .../src/main/java/facade/FacadeClient.java | 10 ++ .../src/main/java/facade/Workflow.java | 15 +++ .../src/main/java/flyweight/Archer.java | 8 ++ .../main/java/flyweight/FlyweightClient.java | 20 +++ .../src/main/java/flyweight/Hero.java | 6 + .../src/main/java/flyweight/HeroFactory.java | 24 ++++ .../src/main/java/flyweight/Knight.java | 8 ++ .../lesson_24/src/main/java/proxy/Car.java | 6 + .../src/main/java/proxy/ProxyClient.java | 9 ++ .../src/main/java/proxy/ProxyVAG.java | 18 +++ .../lesson_24/src/main/java/proxy/VAG.java | 21 +++ AlexSubbotin/lesson_25/.idea/.gitignore | 2 + AlexSubbotin/lesson_25/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_25/.idea/misc.xml | 14 ++ AlexSubbotin/lesson_25/.idea/uiDesigner.xml | 124 ++++++++++++++++++ AlexSubbotin/lesson_25/.idea/vcs.xml | 6 + AlexSubbotin/lesson_25/lesson_25.iml | 2 + AlexSubbotin/lesson_25/pom.xml | 24 ++++ .../java/chainOfResposibility/Client.java | 17 +++ .../chainOfResposibility/EmailNotifier.java | 11 ++ .../java/chainOfResposibility/Notifier.java | 25 ++++ .../java/chainOfResposibility/Priority.java | 8 ++ .../chainOfResposibility/SMSNotifier.java | 12 ++ .../SimpleReportNotifier.java | 11 ++ .../src/main/java/command/Client.java | 16 +++ .../src/main/java/command/Command.java | 6 + .../src/main/java/command/Database.java | 20 +++ .../src/main/java/command/DeleteCommand.java | 14 ++ .../src/main/java/command/InsertCommand.java | 13 ++ .../src/main/java/command/Invoker.java | 31 +++++ .../src/main/java/command/SelectCommand.java | 14 ++ .../src/main/java/command/UpdateCommand.java | 14 ++ .../java/interpreter/BinaryExpression.java | 15 +++ .../src/main/java/interpreter/Client.java | 39 ++++++ .../src/main/java/interpreter/Context.java | 16 +++ .../src/main/java/interpreter/Expression.java | 5 + .../interpreter/HexadecimalExpression.java | 15 +++ .../java/interpreter/OctalExpression.java | 15 +++ .../src/main/java/iterator/Client.java | 17 +++ .../src/main/java/iterator/Collection.java | 6 + .../src/main/java/iterator/Iterator.java | 7 + .../src/main/java/iterator/JavaDeveloper.java | 50 +++++++ .../src/main/java/memento/Client.java | 27 ++++ .../src/main/java/memento/GitHubRepo.java | 14 ++ .../src/main/java/memento/Project.java | 30 +++++ .../lesson_25/src/main/java/memento/Save.java | 22 ++++ .../src/main/java/templateMethod/Client.java | 12 ++ .../main/java/templateMethod/GlassHouse.java | 14 ++ .../java/templateMethod/HouseTemplate.java | 25 ++++ .../main/java/templateMethod/WoodenHouse.java | 14 ++ .../src/main/java/visitor/Client.java | 18 +++ .../src/main/java/visitor/Database.java | 9 ++ .../src/main/java/visitor/Developer.java | 10 ++ .../main/java/visitor/JuniorDeveloper.java | 19 +++ .../src/main/java/visitor/Project.java | 21 +++ .../src/main/java/visitor/ProjectClass.java | 9 ++ .../src/main/java/visitor/ProjectElement.java | 6 + .../main/java/visitor/SeniorDeveloper.java | 19 +++ .../lesson_25/src/main/java/visitor/Test.java | 9 ++ AlexSubbotin/lesson_26/.idea/.gitignore | 2 + AlexSubbotin/lesson_26/.idea/compiler.xml | 13 ++ AlexSubbotin/lesson_26/.idea/misc.xml | 14 ++ AlexSubbotin/lesson_26/.idea/vcs.xml | 6 + AlexSubbotin/lesson_26/lesson_26.iml | 2 + AlexSubbotin/lesson_26/pom.xml | 24 ++++ .../src/main/java/mediator/Action.java | 12 ++ .../src/main/java/mediator/Chef.java | 38 ++++++ .../src/main/java/mediator/Client.java | 43 ++++++ .../src/main/java/mediator/Guest.java | 38 ++++++ .../src/main/java/mediator/Mediator.java | 8 ++ .../src/main/java/mediator/Order.java | 36 +++++ .../src/main/java/mediator/Product.java | 14 ++ .../src/main/java/mediator/Waiter.java | 25 ++++ .../src/main/java/observer/Client.java | 21 +++ .../main/java/observer/DeveloperJobSite.java | 35 +++++ .../src/main/java/observer/Observed.java | 10 ++ .../src/main/java/observer/Observer.java | 7 + .../src/main/java/observer/Subscriber.java | 17 +++ .../src/main/java/state/Activity.java | 5 + .../lesson_26/src/main/java/state/Client.java | 16 +++ .../lesson_26/src/main/java/state/Coding.java | 9 ++ .../src/main/java/state/Developer.java | 26 ++++ .../src/main/java/state/Reading.java | 9 ++ .../src/main/java/state/Sleeping.java | 9 ++ .../src/main/java/state/Training.java | 9 ++ .../java/strategy/AggressiveStrategy.java | 9 ++ .../src/main/java/strategy/CounterStrike.java | 24 ++++ .../main/java/strategy/DefensiveStrategy.java | 9 ++ .../src/main/java/strategy/Player.java | 20 +++ .../src/main/java/strategy/Strategy.java | 6 + 206 files changed, 3714 insertions(+) create mode 100644 AlexSubbotin/lesson_12/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_12/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_12/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_12/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_12/lesson_12.iml create mode 100644 AlexSubbotin/lesson_12/pom.xml create mode 100644 AlexSubbotin/lesson_12/src/main/java/Main.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Animal.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/AnimalInfo.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/BigCats.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Caracals.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Carnivora.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Cats.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/DomesticCats.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/ForestCats.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Herbivorous.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Lion.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Mammals.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Persian.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Siam.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/SmallCats.java create mode 100644 AlexSubbotin/lesson_12/src/main/java/animalInfo/Tigers.java create mode 100644 AlexSubbotin/lesson_12/src/test/java/TestMain.java create mode 100644 AlexSubbotin/lesson_13/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_13/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_13/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_13/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_13/lesson_13.iml create mode 100644 AlexSubbotin/lesson_13/pom.xml create mode 100644 AlexSubbotin/lesson_13/src/main/java/User.java create mode 100644 AlexSubbotin/lesson_13/src/main/java/store/Category.java create mode 100644 AlexSubbotin/lesson_13/src/main/java/store/Product.java create mode 100644 AlexSubbotin/lesson_13/src/test/java/UserTest.java create mode 100644 AlexSubbotin/lesson_13/src/test/java/store/CategoryTest.java create mode 100644 AlexSubbotin/lesson_13/src/test/java/store/ProductTest.java create mode 100644 AlexSubbotin/lesson_21/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_21/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_21/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_21/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_21/lesson_21.iml create mode 100644 AlexSubbotin/lesson_21/pom.xml create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/Checker.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/ConfirmationSender.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollector.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollectorSendControler.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollectorSendControllerWithConfirmation.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderSender.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/Preparer.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/Product.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/ProductChecker.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/ProductPreparer.java create mode 100644 AlexSubbotin/lesson_21/src/main/java/shopsolid/Stock.java create mode 100644 AlexSubbotin/lesson_21/src/test/java/OrderSendControllerTest.java create mode 100644 AlexSubbotin/lesson_23/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_23/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_23/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_23/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_23/lesson_23.iml create mode 100644 AlexSubbotin/lesson_23/pom.xml create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/AbstractCarFactory.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/AbstractFactoryClient.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/DodgeFactory.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/DodgePickup.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/DodgeSedan.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/Factory.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/Pickup.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/Sedan.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/VAGFactory.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/VAGPickup.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/abstractf/VAGSedan.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/builder/BuilderClient.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/builder/User.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/factorym/ExcelReport.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/factorym/FactoryMethodClient.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/factorym/PDFReport.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/factorym/Report.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/factorym/ReportCreator.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/prototype/ClientPrototype.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/prototype/RectangularWindow.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/prototype/RoundWindow.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/prototype/Window.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/singleton/ClientSingleton.java create mode 100644 AlexSubbotin/lesson_23/src/main/java/singleton/Singleton.java create mode 100644 AlexSubbotin/lesson_24/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_24/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_24/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_24/.idea/uiDesigner.xml create mode 100644 AlexSubbotin/lesson_24/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_24/lesson_24.iml create mode 100644 AlexSubbotin/lesson_24/pom.xml create mode 100644 AlexSubbotin/lesson_24/src/main/java/adapter/AdapterClient.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/adapter/PlugAdapter.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/adapter/PlugToSocketAdapter.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/adapter/PlugWithThreeLegs.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/adapter/TwoLeggedSocket.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/bridge/BridgeClient.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/bridge/MagazineWriter.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/bridge/Newspaper.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/bridge/NewspaperWriter.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/bridge/Press.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/bridge/SportMagazine.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/bridge/Writer.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/composite/CompositeClient.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/composite/NewsWriter.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/composite/NewspaperFactory.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/composite/SportNewsWriter.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/composite/Writer.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/decorator/DecoratorClient.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/decorator/EmailReportDuplicator.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/decorator/PaperReport.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/decorator/ReportDecorator.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/decorator/ReportSender.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/decorator/SmsConfirmSender.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/facade/CarAssembler.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/facade/CarBodyPainter.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/facade/CarWasher.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/facade/FacadeClient.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/facade/Workflow.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/flyweight/Archer.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/flyweight/FlyweightClient.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/flyweight/Hero.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/flyweight/HeroFactory.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/flyweight/Knight.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/proxy/Car.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/proxy/ProxyClient.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/proxy/ProxyVAG.java create mode 100644 AlexSubbotin/lesson_24/src/main/java/proxy/VAG.java create mode 100644 AlexSubbotin/lesson_25/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_25/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_25/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_25/.idea/uiDesigner.xml create mode 100644 AlexSubbotin/lesson_25/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_25/lesson_25.iml create mode 100644 AlexSubbotin/lesson_25/pom.xml create mode 100644 AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Client.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/EmailNotifier.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Notifier.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Priority.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/SMSNotifier.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/SimpleReportNotifier.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/command/Client.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/command/Command.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/command/Database.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/command/DeleteCommand.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/command/InsertCommand.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/command/Invoker.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/command/SelectCommand.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/command/UpdateCommand.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/interpreter/BinaryExpression.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/interpreter/Client.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/interpreter/Context.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/interpreter/Expression.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/interpreter/HexadecimalExpression.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/interpreter/OctalExpression.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/iterator/Client.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/iterator/Collection.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/iterator/Iterator.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/iterator/JavaDeveloper.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/memento/Client.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/memento/GitHubRepo.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/memento/Project.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/memento/Save.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/templateMethod/Client.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/templateMethod/GlassHouse.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/templateMethod/HouseTemplate.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/templateMethod/WoodenHouse.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/Client.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/Database.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/Developer.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/JuniorDeveloper.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/Project.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/ProjectClass.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/ProjectElement.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/SeniorDeveloper.java create mode 100644 AlexSubbotin/lesson_25/src/main/java/visitor/Test.java create mode 100644 AlexSubbotin/lesson_26/.idea/.gitignore create mode 100644 AlexSubbotin/lesson_26/.idea/compiler.xml create mode 100644 AlexSubbotin/lesson_26/.idea/misc.xml create mode 100644 AlexSubbotin/lesson_26/.idea/vcs.xml create mode 100644 AlexSubbotin/lesson_26/lesson_26.iml create mode 100644 AlexSubbotin/lesson_26/pom.xml create mode 100644 AlexSubbotin/lesson_26/src/main/java/mediator/Action.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/mediator/Chef.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/mediator/Client.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/mediator/Guest.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/mediator/Mediator.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/mediator/Order.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/mediator/Product.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/mediator/Waiter.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/observer/Client.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/observer/DeveloperJobSite.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/observer/Observed.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/observer/Observer.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/observer/Subscriber.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/state/Activity.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/state/Client.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/state/Coding.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/state/Developer.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/state/Reading.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/state/Sleeping.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/state/Training.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/strategy/AggressiveStrategy.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/strategy/CounterStrike.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/strategy/DefensiveStrategy.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/strategy/Player.java create mode 100644 AlexSubbotin/lesson_26/src/main/java/strategy/Strategy.java diff --git a/AlexSubbotin/lesson_12/.idea/.gitignore b/AlexSubbotin/lesson_12/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/AlexSubbotin/lesson_12/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/AlexSubbotin/lesson_12/.idea/compiler.xml b/AlexSubbotin/lesson_12/.idea/compiler.xml new file mode 100644 index 0000000..159cfc1 --- /dev/null +++ b/AlexSubbotin/lesson_12/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_12/.idea/misc.xml b/AlexSubbotin/lesson_12/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_12/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_12/.idea/vcs.xml b/AlexSubbotin/lesson_12/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_12/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_12/lesson_12.iml b/AlexSubbotin/lesson_12/lesson_12.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_12/lesson_12.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_12/pom.xml b/AlexSubbotin/lesson_12/pom.xml new file mode 100644 index 0000000..dc65d34 --- /dev/null +++ b/AlexSubbotin/lesson_12/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + org.example + lesson_12 + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + junit + junit + 4.13.2 + test + + + junit + junit + 4.13.2 + test + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_12/src/main/java/Main.java b/AlexSubbotin/lesson_12/src/main/java/Main.java new file mode 100644 index 0000000..ddb386e --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/Main.java @@ -0,0 +1,52 @@ +import animalInfo.Animal; +import animalInfo.Persian; +import animalInfo.Siam; + +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + Persian firstPersian = new Persian("Barsik"); + Persian secondPersian = new Persian("Murzik"); + Siam firstSiam = new Siam("Murka"); + Animal[] animals = {firstPersian, firstSiam, secondPersian}; + + String animalName = typeAnimalName(); + String animalInfo = getInfoByName(animals, animalName); + printInfo(animalInfo); + String hierarchy = getHierarchySubspeciesOfAnimal(animals, animalName); + printInfo(hierarchy); + } + + public static String getInfoByName(Animal[] animals, String name) { + String info = null; + for (Animal animal : animals) { + if (animal.getName().equals(name)) { + info = animal.getInfo(); + } + } + return info; + } + + public static String getHierarchySubspeciesOfAnimal(Animal[] animals, String name) { + String info = null; + for (Animal animal : animals) { + if (animal.getName().equalsIgnoreCase(name)) { + info = animal.getGroupName(); + } + } + return info; + } + + public static String typeAnimalName() { + System.out.println("Enter animal Name:"); + Scanner scanner = new Scanner(System.in); + String animalName = scanner.nextLine(); + return animalName.trim(); + } + + public static void printInfo(String info) { + System.out.println("Result:\n" + info); + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Animal.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Animal.java new file mode 100644 index 0000000..e89c18e --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Animal.java @@ -0,0 +1,25 @@ +package animalInfo; + +public class Animal extends AnimalInfo { + + protected String name; + private String groupName; + + public String getName() { + return name; + } + + protected Animal() { + this.groupName = "Kingdom - Animal."; + } + + public String getGroupName() { + String groupInfo = this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = "Are able to move.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/AnimalInfo.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/AnimalInfo.java new file mode 100644 index 0000000..8071226 --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/AnimalInfo.java @@ -0,0 +1,6 @@ +package animalInfo; + +public abstract class AnimalInfo { + + public abstract String getInfo(); +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/BigCats.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/BigCats.java new file mode 100644 index 0000000..6e1134e --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/BigCats.java @@ -0,0 +1,23 @@ +package animalInfo; + +public class BigCats extends Cats { + private String groupName; + + + protected BigCats() { + this.groupName = "Subfamily - Big Cats."; + this.canGrowl = true; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = super.getInfo() + + "Include the largest representatives. Can growl.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Caracals.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Caracals.java new file mode 100644 index 0000000..59d462c --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Caracals.java @@ -0,0 +1,23 @@ +package animalInfo; + +public class Caracals extends SmallCats { + + private String groupName; + + protected Caracals() { + this.groupName = "Genus - Caracals."; + this.wildCat = true; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = super.getInfo() + + "Is a medium-sized wild cat.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Carnivora.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Carnivora.java new file mode 100644 index 0000000..b9977ef --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Carnivora.java @@ -0,0 +1,24 @@ +package animalInfo; + +public class Carnivora extends Mammals { + + private String groupName; + protected boolean haveNightVision; + + protected Carnivora() { + this.groupName = "Order - Carnivora."; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + + String mainInfo = super.getInfo() + + "Eat other animals.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Cats.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Cats.java new file mode 100644 index 0000000..4b79fae --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Cats.java @@ -0,0 +1,28 @@ +package animalInfo; + +public class Cats extends Carnivora { + + private String groupName; + protected boolean canGrowl; + + protected Cats() { + this.groupName = "Family - Cats."; + this.haveNightVision = true; + } + + protected String howLegs() { + return "Have 4 legs."; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = super.getInfo() + + "Have retractile claws, slender muscular bodies and strong flexible forelimbs.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/DomesticCats.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/DomesticCats.java new file mode 100644 index 0000000..33f2a6d --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/DomesticCats.java @@ -0,0 +1,27 @@ +package animalInfo; + +public class DomesticCats extends ForestCats { + + private String groupName; + + protected DomesticCats() { + this.groupName = "Species - Domestic Cats."; + this.wildCat = false; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = super.getInfo() + + howLegs() + "\n" + + "Lives near people.\n" + + "This animal have night vision - " + this.haveNightVision + "\n" + + "This animal can growl - " + this.canGrowl + "\n" + + "This animal wild - " + this.wildCat + "\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/ForestCats.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/ForestCats.java new file mode 100644 index 0000000..c161c07 --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/ForestCats.java @@ -0,0 +1,24 @@ +package animalInfo; + +public class ForestCats extends SmallCats { + + private String groupName; + + + protected ForestCats() { + this.groupName = "Genus - Forest Cats."; + this.wildCat = true; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = super.getInfo() + + "Can hunt small rodents and other animals of a similar size.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Herbivorous.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Herbivorous.java new file mode 100644 index 0000000..9bdb959 --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Herbivorous.java @@ -0,0 +1,23 @@ +package animalInfo; + +public class Herbivorous extends Mammals { + + private String groupName; + + protected Herbivorous() { + this.groupName = "Order - Herbivorous."; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + + String mainInfo = super.getInfo() + + "Eats plant foods.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Lion.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Lion.java new file mode 100644 index 0000000..cb1a703 --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Lion.java @@ -0,0 +1,22 @@ +package animalInfo; + +public class Lion extends BigCats { + + private String groupName; + + protected Lion() { + this.groupName = "Genus - Lion."; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = super.getInfo() + +"The largest member of the cats family.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Mammals.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Mammals.java new file mode 100644 index 0000000..8695759 --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Mammals.java @@ -0,0 +1,23 @@ +package animalInfo; + +public class Mammals extends Animal { + + private String groupName; + + protected Mammals() { + this.groupName = "Class - Mammals."; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + + String mainInfo = super.getInfo() + + "Produce milk for feeding their young\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Persian.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Persian.java new file mode 100644 index 0000000..eebb07d --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Persian.java @@ -0,0 +1,30 @@ +package animalInfo; + +public class Persian extends DomesticCats { + + private String groupName; + + public Persian(String catName) { + this.name = catName; + this.groupName = "Breed - Persian."; + } + + public String getName() { + return name; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = getName() + "\n" + + this.groupName + "\n" + + super.getInfo() + + "Has an extremely long and thick coat, short legs, " + + "a wide head with the ears set far apart, large eyes."; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Siam.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Siam.java new file mode 100644 index 0000000..5289623 --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Siam.java @@ -0,0 +1,35 @@ +package animalInfo; + +public class Siam extends DomesticCats { + + private String name; + private String groupName; + + + public Siam(String catName) { + this.name = catName; + this.groupName = "Breed - Siam."; + } + + public String getName() { + return name; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = getName() + "\n" + + this.groupName + "\n" + + super.getInfo() + + "Is characterized by blue almond-shaped eyes; " + + "a triangular head shape; " + + "large ears; " + + "an elongated, slender, and muscular body; " + + "and various forms of point colouration."; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/SmallCats.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/SmallCats.java new file mode 100644 index 0000000..27f1db7 --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/SmallCats.java @@ -0,0 +1,24 @@ +package animalInfo; + +public class SmallCats extends Cats { + + private String groupName; + protected boolean wildCat; + + protected SmallCats() { + this.groupName = "Subfamily - Small Cats."; + this.canGrowl = false; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = super.getInfo() + + "Are able to purr but not roar.\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/main/java/animalInfo/Tigers.java b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Tigers.java new file mode 100644 index 0000000..9cb162b --- /dev/null +++ b/AlexSubbotin/lesson_12/src/main/java/animalInfo/Tigers.java @@ -0,0 +1,22 @@ +package animalInfo; + +public class Tigers extends BigCats { + + private String groupName; + + protected Tigers () { + this.groupName = "Genus - Tiger."; + } + + public String getGroupName() { + String groupInfo = super.getGroupName() + + this.groupName; + return groupInfo + "\n"; + } + + public String getInfo() { + String mainInfo = super.getInfo() + + "Have dark vertical stripes on orange-brown fur with a lighter underside\n"; + return mainInfo; + } +} diff --git a/AlexSubbotin/lesson_12/src/test/java/TestMain.java b/AlexSubbotin/lesson_12/src/test/java/TestMain.java new file mode 100644 index 0000000..8d3a87c --- /dev/null +++ b/AlexSubbotin/lesson_12/src/test/java/TestMain.java @@ -0,0 +1,86 @@ +import animalInfo.Animal; +import animalInfo.Persian; +import animalInfo.Siam; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class TestMain { + + Main main = new Main(); + Persian firstPersian = new Persian("Barsik"); + Persian secondPersian = new Persian("Murzik"); + Siam firstSiam = new Siam("Murka"); + Animal[] animals = {firstPersian, firstSiam, secondPersian}; + + @Test + public void ifNameMurzikShouldPrintPersianInfo() { + String animalInfo = main.getInfoByName(animals, "Murzik"); + main.printInfo(animalInfo); + assertThat(animalInfo, equalTo("Murzik\n" + + "Breed - Persian.\n" + + "Are able to move.\n" + + "Produce milk for feeding their young\n" + + "Eat other animals.\n" + + "Have retractile claws, slender muscular bodies and strong flexible forelimbs.\n" + + "Are able to purr but not roar.\n" + + "Can hunt small rodents and other animals of a similar size.\n" + + "Have 4 legs.\n" + + "Lives near people.\n" + + "This animal have night vision - true\n" + + "This animal can growl - false\n" + + "This animal wild - false\n" + + "Has an extremely long and thick coat, short legs, a wide head with the ears set far apart, large eyes.")); + } + + @Test + public void testGetMurzikHierarchySubspeciesOfAnimal() { + String animalInfo = main.getHierarchySubspeciesOfAnimal(animals, "Murzik"); +// main.printInfo(animalInfo); + assertThat(animalInfo, equalTo("Kingdom - Animal.\n" + + "Class - Mammals.\n" + + "Order - Carnivora.\n" + + "Family - Cats.\n" + + "Subfamily - Small Cats.\n" + + "Genus - Forest Cats.\n" + + "Species - Domestic Cats.\n" + + "Breed - Persian.\n")); + } + + @Test + public void ifNameMurkaShouldPrintSiamInfo() { + String animalInfo = main.getInfoByName(animals, "Murka"); + main.printInfo(animalInfo); + assertThat(animalInfo, equalTo("Murka\n" + + "Breed - Siam.\n" + + "Are able to move.\n" + + "Produce milk for feeding their young\n" + + "Eat other animals.\n" + + "Have retractile claws, slender muscular bodies and strong flexible forelimbs.\n" + + "Are able to purr but not roar.\n" + + "Can hunt small rodents and other animals of a similar size.\n" + + "Have 4 legs.\n" + + "Lives near people.\n" + + "This animal have night vision - true\n" + + "This animal can growl - false\n" + + "This animal wild - false\n" + + "Is characterized by blue almond-shaped eyes; " + + "a triangular head shape; " + + "large ears; " + + "an elongated, slender, and muscular body; and various forms of point colouration.")); + } + + @Test + public void testGetMurkaHierarchySubspeciesOfAnimal() { + String animalInfo = main.getHierarchySubspeciesOfAnimal(animals, "Murka"); + assertThat(animalInfo, equalTo("Kingdom - Animal.\n" + + "Class - Mammals.\n" + + "Order - Carnivora.\n" + + "Family - Cats.\n" + + "Subfamily - Small Cats.\n" + + "Genus - Forest Cats.\n" + + "Species - Domestic Cats.\n" + + "Breed - Siam.\n")); + } +} diff --git a/AlexSubbotin/lesson_13/.idea/.gitignore b/AlexSubbotin/lesson_13/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_13/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/AlexSubbotin/lesson_13/.idea/compiler.xml b/AlexSubbotin/lesson_13/.idea/compiler.xml new file mode 100644 index 0000000..4653d66 --- /dev/null +++ b/AlexSubbotin/lesson_13/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_13/.idea/misc.xml b/AlexSubbotin/lesson_13/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_13/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_13/.idea/vcs.xml b/AlexSubbotin/lesson_13/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_13/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_13/lesson_13.iml b/AlexSubbotin/lesson_13/lesson_13.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_13/lesson_13.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_13/pom.xml b/AlexSubbotin/lesson_13/pom.xml new file mode 100644 index 0000000..8f4ea4c --- /dev/null +++ b/AlexSubbotin/lesson_13/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + org.example + lesson_13 + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + junit + junit + 4.13.2 + test + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_13/src/main/java/User.java b/AlexSubbotin/lesson_13/src/main/java/User.java new file mode 100644 index 0000000..ea3ca3c --- /dev/null +++ b/AlexSubbotin/lesson_13/src/main/java/User.java @@ -0,0 +1,54 @@ +import store.Product; + +public class User { + + private String login; + private String password; + private Basket userBasket; + + protected class Basket { + + private Product[] boughtProducts; + + public Basket(Product... boughtProducts) { + this.boughtProducts = boughtProducts; + } + + public Product[] getBoughtProducts() { + return this.boughtProducts; + } + + public void setBoughtProducts(Product... boughtProducts) { + this.boughtProducts = boughtProducts; + } + } + + public User(String login, String password) { + this.login = login; + this.password = password; + } + + public String getLogin() { + return this.login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public Basket getUserBasket() { + return this.userBasket; + } + + public void setUserBasket(Basket userBasket) { + this.userBasket = userBasket; + } +} diff --git a/AlexSubbotin/lesson_13/src/main/java/store/Category.java b/AlexSubbotin/lesson_13/src/main/java/store/Category.java new file mode 100644 index 0000000..67103e0 --- /dev/null +++ b/AlexSubbotin/lesson_13/src/main/java/store/Category.java @@ -0,0 +1,27 @@ +package store; + +public class Category { + + private String categoryName; + private Product[] products; + + protected Category(String categoryName) { + this.categoryName = categoryName; + } + + public String getCategoryName() { + return this.categoryName; + } + + public Product[] getProducts() { + return this.products; + } + + protected void setCategoryName(String categoryName) { + this.categoryName = categoryName; + } + + protected void setProducts(Product... products) { + this.products = products; + } +} diff --git a/AlexSubbotin/lesson_13/src/main/java/store/Product.java b/AlexSubbotin/lesson_13/src/main/java/store/Product.java new file mode 100644 index 0000000..8bc8245 --- /dev/null +++ b/AlexSubbotin/lesson_13/src/main/java/store/Product.java @@ -0,0 +1,38 @@ +package store; + +public class Product { + + private String name; + private int price; + private byte rate; + + protected Product(String name, int price, byte rate) { + this.name = name; + this.price = price; + this.rate = rate; + } + + public String getName() { + return this.name; + } + + public int getPrice() { + return this.price; + } + + public byte getRate() { + return this.rate; + } + + protected void setPrice(int price) { + this.price = price; + } + + protected void setName(String name) { + this.name = name; + } + + protected void setRate(byte rate) { + this.rate = rate; + } +} diff --git a/AlexSubbotin/lesson_13/src/test/java/UserTest.java b/AlexSubbotin/lesson_13/src/test/java/UserTest.java new file mode 100644 index 0000000..7153a0d --- /dev/null +++ b/AlexSubbotin/lesson_13/src/test/java/UserTest.java @@ -0,0 +1,46 @@ +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import store.CategoryTest; +import store.Product; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class UserTest { + + private CategoryTest categoryTest = new CategoryTest(); + private User firstUser = new User("aaa", "BBB"); + + @Before + public void initAssortment() { + categoryTest.setProductsInTelephonesCategory(); + categoryTest.setProductsInTVCategory(); + categoryTest.setProductsInComputersCategory(); + } + + @Test + public void testUserFields() { + User user = new User("", ""); + assertThat(user, Matchers.hasProperty("login")); + assertThat(user, Matchers.hasProperty("password")); + assertThat(user, Matchers.hasProperty("userBasket")); + } + + @Test + public void testUserAddToBasketIBMIphone10Samsung75() { + Product[] storeAssortmentTelephones = categoryTest.telephones.getProducts(); + Product[] storeAssortmentTv = categoryTest.tvsets.getProducts(); + Product[] storeAssortmentComputers = categoryTest.computers.getProducts(); + + User.Basket userBasket = firstUser.new Basket(); + userBasket.setBoughtProducts( + storeAssortmentComputers[0], + storeAssortmentTelephones[1], + storeAssortmentTv[2] + ); + assertThat(userBasket.getBoughtProducts()[0].getName(), (equalTo("IBM"))); + assertThat(userBasket.getBoughtProducts()[1].getName(), (equalTo("Iphone 10"))); + assertThat(userBasket.getBoughtProducts()[2].getName(), (equalTo("Samsung 75``"))); + } +} diff --git a/AlexSubbotin/lesson_13/src/test/java/store/CategoryTest.java b/AlexSubbotin/lesson_13/src/test/java/store/CategoryTest.java new file mode 100644 index 0000000..cf72186 --- /dev/null +++ b/AlexSubbotin/lesson_13/src/test/java/store/CategoryTest.java @@ -0,0 +1,56 @@ +package store; + +import org.hamcrest.Matchers; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItemInArray; + +public class CategoryTest { + + public Category telephones = new Category("TELEPHONES"); + public Category tvsets = new Category("TV"); + public Category computers = new Category("Computers"); + + private Product iphone11 = new Product("Iphone 11", 1000, (byte) 10); + private Product iphone10 = new Product("Iphone 10", 900, (byte) 9); + private Product iphone8 = new Product("Iphone 8", 800, (byte) 8); + + private Product samsung75 = new Product("Samsung 75``", 1000, (byte) 10); + private Product samsung65 = new Product("Samsung 65``", 900, (byte) 9); + private Product samsung55 = new Product("Samsung 55``", 800, (byte) 8); + + private Product ibm = new Product("IBM", 360, (byte) 4); + private Product hp = new Product("HP", 600, (byte) 7); + private Product xiaomi = new Product("Xiaomi", 800, (byte) 9); + + @Test + public void testCategoryFields() { + assertThat(telephones, Matchers.hasProperty("categoryName")); + assertThat(telephones, Matchers.hasProperty("products")); + } + + @Test + public void setProductsInTelephonesCategory() { + telephones.setProducts(iphone8, iphone10, iphone11); + assertThat(telephones.getProducts(), hasItemInArray(iphone8)); + assertThat(telephones.getProducts(), hasItemInArray(iphone10)); + assertThat(telephones.getProducts(), hasItemInArray(iphone11)); + } + + @Test + public void setProductsInTVCategory() { + tvsets.setProducts(samsung55, samsung65, samsung75); + assertThat(tvsets.getProducts(), hasItemInArray(samsung55)); + assertThat(tvsets.getProducts(), hasItemInArray(samsung65)); + assertThat(tvsets.getProducts(), hasItemInArray(samsung75)); + } + + @Test + public void setProductsInComputersCategory() { + computers.setProducts(ibm, hp, xiaomi); + assertThat(computers.getProducts(), hasItemInArray(ibm)); + assertThat(computers.getProducts(), hasItemInArray(hp)); + assertThat(computers.getProducts(), hasItemInArray(xiaomi)); + } +} diff --git a/AlexSubbotin/lesson_13/src/test/java/store/ProductTest.java b/AlexSubbotin/lesson_13/src/test/java/store/ProductTest.java new file mode 100644 index 0000000..d9acc1b --- /dev/null +++ b/AlexSubbotin/lesson_13/src/test/java/store/ProductTest.java @@ -0,0 +1,18 @@ +package store; + +import org.hamcrest.Matchers; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; + +public class ProductTest { + + private Product product = new Product("a", 10, (byte) 2); + + @Test + public void testProductFields() { + assertThat(product, Matchers.hasProperty("name")); + assertThat(product, Matchers.hasProperty("price")); + assertThat(product, Matchers.hasProperty("rate")); + } +} diff --git a/AlexSubbotin/lesson_21/.idea/.gitignore b/AlexSubbotin/lesson_21/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_21/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/AlexSubbotin/lesson_21/.idea/compiler.xml b/AlexSubbotin/lesson_21/.idea/compiler.xml new file mode 100644 index 0000000..904a94c --- /dev/null +++ b/AlexSubbotin/lesson_21/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_21/.idea/misc.xml b/AlexSubbotin/lesson_21/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_21/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_21/.idea/vcs.xml b/AlexSubbotin/lesson_21/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_21/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_21/lesson_21.iml b/AlexSubbotin/lesson_21/lesson_21.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_21/lesson_21.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_21/pom.xml b/AlexSubbotin/lesson_21/pom.xml new file mode 100644 index 0000000..9ad8089 --- /dev/null +++ b/AlexSubbotin/lesson_21/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + org.example + lesson_21 + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + test + + + junit + junit + 4.13.2 + test + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/Checker.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/Checker.java new file mode 100644 index 0000000..6161f72 --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/Checker.java @@ -0,0 +1,8 @@ +package shopsolid; + +import java.util.List; + +public interface Checker { + + int checkProduct(List productsList, Product product); +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/ConfirmationSender.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/ConfirmationSender.java new file mode 100644 index 0000000..76d3f7e --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/ConfirmationSender.java @@ -0,0 +1,6 @@ +package shopsolid; + +public interface ConfirmationSender { + + void sendConfirmationSMS(); +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollector.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollector.java new file mode 100644 index 0000000..1cf93b8 --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollector.java @@ -0,0 +1,8 @@ +package shopsolid; + +import java.util.List; + +public interface OrderCollector { + + Product collectOrder(List productList, Product product); +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollectorSendControler.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollectorSendControler.java new file mode 100644 index 0000000..b6e5e99 --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollectorSendControler.java @@ -0,0 +1,23 @@ +package shopsolid; + +import java.util.List; + +public class OrderCollectorSendControler implements OrderCollector, OrderSender { + + private ProductChecker pc; + private ProductPreparer pp; + + public OrderCollectorSendControler() { + this.pc = new ProductChecker(); + this.pp = new ProductPreparer(); + } + + public Product collectOrder(List productList, Product product) { + int productIndex = pc.checkProduct(productList, product); + return pp.prepareProduct(productList, productIndex); + } + + public void sendOrder(Product product) { + System.out.println("Order: " + product.toString() + " is send."); + } +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollectorSendControllerWithConfirmation.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollectorSendControllerWithConfirmation.java new file mode 100644 index 0000000..c25c9e1 --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderCollectorSendControllerWithConfirmation.java @@ -0,0 +1,24 @@ +package shopsolid; + +import java.util.List; + +public class OrderCollectorSendControllerWithConfirmation extends OrderCollectorSendControler implements ConfirmationSender { + + @Override + public Product collectOrder(List productList, Product product) { + printConfirmation(); //This method break Liskov’s Substitution Principle.(Prints an extra line) + sendConfirmationSMS(); + return super.collectOrder(productList, product); + } + + //This method break Liskov’s Substitution Principle.(Prints an extra line) + private void printConfirmation() { + System.out.println("Your order complete"); + } + + public void sendConfirmationSMS() { + String sms = "SMS: Your order on the way."; + //sms sender body... + System.out.println(sms); + } +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderSender.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderSender.java new file mode 100644 index 0000000..f03adac --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/OrderSender.java @@ -0,0 +1,6 @@ +package shopsolid; + +public interface OrderSender { + + void sendOrder(Product product); +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/Preparer.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/Preparer.java new file mode 100644 index 0000000..9bf22c4 --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/Preparer.java @@ -0,0 +1,8 @@ +package shopsolid; + +import java.util.List; + +public interface Preparer { + + Product prepareProduct(List productsList, int productIndex); +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/Product.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/Product.java new file mode 100644 index 0000000..720333c --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/Product.java @@ -0,0 +1,28 @@ +package shopsolid; + +public class Product { + + private String productName; + private int productPrice; + + public Product(String productName, int productPrice) { + this.productName = productName; + this.productPrice = productPrice; + } + + public String getProductName() { + return productName; + } + + public int getProductPrice() { + return productPrice; + } + + @Override + public String toString() { + return + "productName = " + productName + + ", productPrice = " + productPrice + + "грн."; + } +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/ProductChecker.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/ProductChecker.java new file mode 100644 index 0000000..f719d11 --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/ProductChecker.java @@ -0,0 +1,14 @@ +package shopsolid; + +import java.util.List; + +public class ProductChecker implements Checker { + + public int checkProduct(List productsList, Product product) { + int productIndex = productsList.size() + 1; + if (productsList.contains(product)) { + productIndex = productsList.indexOf(product); + } + return productIndex; + } +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/ProductPreparer.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/ProductPreparer.java new file mode 100644 index 0000000..41695c4 --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/ProductPreparer.java @@ -0,0 +1,10 @@ +package shopsolid; + +import java.util.List; + +public class ProductPreparer implements Preparer { + + public Product prepareProduct(List productsList, int productIndex) { + return productsList.get(productIndex); + } +} diff --git a/AlexSubbotin/lesson_21/src/main/java/shopsolid/Stock.java b/AlexSubbotin/lesson_21/src/main/java/shopsolid/Stock.java new file mode 100644 index 0000000..ddcdd46 --- /dev/null +++ b/AlexSubbotin/lesson_21/src/main/java/shopsolid/Stock.java @@ -0,0 +1,20 @@ +package shopsolid; + +import java.util.List; + +public class Stock { + + private List productList; + + public Stock(List productList) { + this.productList = productList; + } + + public List getProductList() { + return productList; + } + + public void addProduct(Product product) { + this.productList.add(product); + } +} diff --git a/AlexSubbotin/lesson_21/src/test/java/OrderSendControllerTest.java b/AlexSubbotin/lesson_21/src/test/java/OrderSendControllerTest.java new file mode 100644 index 0000000..e95f6fc --- /dev/null +++ b/AlexSubbotin/lesson_21/src/test/java/OrderSendControllerTest.java @@ -0,0 +1,37 @@ +import org.junit.Before; +import org.junit.Test; + + +import java.util.ArrayList; + +public class OrderSendControllerTest { + + private ArrayList shopProductsList = new ArrayList(); + private Stock stockShop = new Stock(shopProductsList); + private Product bread = new Product("White bread", 15); + private Product meat = new Product("Pork meat", 100); + private Product fish = new Product("Dorado fish", 150); + private Product milk = new Product("Cow milk", 25); + + @Before + public void initProducts() { + stockShop.addProduct(bread); + stockShop.addProduct(meat); + stockShop.addProduct(fish); + stockShop.addProduct(milk); + } + + @Test + public void sendOrderTest() { + OrderSendController orderController = new OrderSendController( + new ProductChecker(), new ProductPreparer()); + orderController.sendOrder(orderController.collectOrder(shopProductsList, meat)); + } + + @Test + public void sendOrderWithConfirmationTest() { + OrderSendControllerWithConfirmation ocwc = new OrderSendControllerWithConfirmation( + new ProductChecker(), new ProductPreparer()); + ocwc.sendOrder(ocwc.collectOrder(shopProductsList, milk)); + } +} diff --git a/AlexSubbotin/lesson_23/.idea/.gitignore b/AlexSubbotin/lesson_23/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_23/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/AlexSubbotin/lesson_23/.idea/compiler.xml b/AlexSubbotin/lesson_23/.idea/compiler.xml new file mode 100644 index 0000000..3cc0c45 --- /dev/null +++ b/AlexSubbotin/lesson_23/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_23/.idea/misc.xml b/AlexSubbotin/lesson_23/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_23/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_23/.idea/vcs.xml b/AlexSubbotin/lesson_23/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_23/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_23/lesson_23.iml b/AlexSubbotin/lesson_23/lesson_23.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_23/lesson_23.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_23/pom.xml b/AlexSubbotin/lesson_23/pom.xml new file mode 100644 index 0000000..be5caf3 --- /dev/null +++ b/AlexSubbotin/lesson_23/pom.xml @@ -0,0 +1,12 @@ + + + 4.0.0 + + org.example + lesson_23 + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/AbstractCarFactory.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/AbstractCarFactory.java new file mode 100644 index 0000000..76ce7a3 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/AbstractCarFactory.java @@ -0,0 +1,22 @@ +package abstractf; + +public class AbstractCarFactory implements Factory { + + private Factory factory; + + public AbstractCarFactory(Factory factory) { + this.factory = factory; + } + + public void setFactory(Factory factory) { + this.factory = factory; + } + + public Sedan createSedan() { + return this.factory.createSedan(); + } + + public Pickup createPickup() { + return this.factory.createPickup(); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/AbstractFactoryClient.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/AbstractFactoryClient.java new file mode 100644 index 0000000..81d67c8 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/AbstractFactoryClient.java @@ -0,0 +1,19 @@ +package abstractf; + +public class AbstractFactoryClient { + + public static void main(String[] args) { + DodgeFactory dodge = new DodgeFactory(); + VAGFactory volkswagen = new VAGFactory(); + + AbstractCarFactory acf = new AbstractCarFactory(dodge); + Pickup pickup = acf.createPickup(); + System.out.println(pickup); + + acf.setFactory(volkswagen); + pickup = acf.createPickup(); + Sedan sedan = acf.createSedan(); + System.out.println(sedan); + System.out.println(pickup); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgeFactory.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgeFactory.java new file mode 100644 index 0000000..d6c241c --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgeFactory.java @@ -0,0 +1,12 @@ +package abstractf; + +public class DodgeFactory implements Factory { + + public Sedan createSedan() { + return new DodgeSedan(); + } + + public Pickup createPickup() { + return new DodgePickup(); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgePickup.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgePickup.java new file mode 100644 index 0000000..fe6f2c0 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgePickup.java @@ -0,0 +1,23 @@ +package abstractf; + +public class DodgePickup implements Pickup { + + private final String TRADEMARK = "Dodge"; + private String type; + + public DodgePickup() { + setTypePickup(); + } + + public void setTypePickup() { + this.type = "Pickup"; + } + + @Override + public String toString() { + return "DodgePickup{" + + "TRADEMARK='" + TRADEMARK + '\'' + + ", type='" + type + '\'' + + '}'; + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgeSedan.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgeSedan.java new file mode 100644 index 0000000..c65e835 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/DodgeSedan.java @@ -0,0 +1,23 @@ +package abstractf; + +public class DodgeSedan implements Sedan { + + private final String TRADEMARK = "Dodge"; + private String type; + + public DodgeSedan() { + setTypeSedan(); + } + + public void setTypeSedan() { + this.type = "Sedan"; + } + + @Override + public String toString() { + return "DodgeSedan{" + + "TRADEMARK='" + TRADEMARK + '\'' + + ", type='" + type + '\'' + + '}'; + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/Factory.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/Factory.java new file mode 100644 index 0000000..812b1db --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/Factory.java @@ -0,0 +1,7 @@ +package abstractf; + +public interface Factory { + + Sedan createSedan(); + Pickup createPickup(); +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/Pickup.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/Pickup.java new file mode 100644 index 0000000..832bf22 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/Pickup.java @@ -0,0 +1,6 @@ +package abstractf; + +public interface Pickup { + + void setTypePickup(); +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/Sedan.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/Sedan.java new file mode 100644 index 0000000..1ff5487 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/Sedan.java @@ -0,0 +1,6 @@ +package abstractf; + +public interface Sedan { + + void setTypeSedan(); +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGFactory.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGFactory.java new file mode 100644 index 0000000..0e1d2ca --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGFactory.java @@ -0,0 +1,12 @@ +package abstractf; + +public class VAGFactory implements Factory { + + public Sedan createSedan() { + return new VAGSedan(); + } + + public Pickup createPickup() { + return new VAGPickup(); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGPickup.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGPickup.java new file mode 100644 index 0000000..1975827 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGPickup.java @@ -0,0 +1,23 @@ +package abstractf; + +public class VAGPickup implements Pickup { + + private final String TRADEMARK = "Volkswagen"; + private String type; + + public VAGPickup() { + setTypePickup(); + } + + public void setTypePickup() { + this.type = "Pickup"; + } + + @Override + public String toString() { + return "VolkswagenPickup{" + + "TRADEMARK='" + TRADEMARK + '\'' + + ", type='" + type + '\'' + + '}'; + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGSedan.java b/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGSedan.java new file mode 100644 index 0000000..9904b01 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/abstractf/VAGSedan.java @@ -0,0 +1,23 @@ +package abstractf; + +public class VAGSedan implements Sedan { + + private final String TRADEMARK = "Volkswagen"; + private String type; + + public VAGSedan() { + setTypeSedan(); + } + + public void setTypeSedan() { + this.type = "Sedan"; + } + + @Override + public String toString() { + return "VolkswagenSedan{" + + "TRADEMARK='" + TRADEMARK + '\'' + + ", type='" + type + '\'' + + '}'; + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/builder/BuilderClient.java b/AlexSubbotin/lesson_23/src/main/java/builder/BuilderClient.java new file mode 100644 index 0000000..128510c --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/builder/BuilderClient.java @@ -0,0 +1,21 @@ +package builder; + +public class BuilderClient { + public static void main(String[] args) { + User newUser = User.newUser() + .setAge((byte) 37) + .setBornCity("Kyiv") + .setBornCountry("Ukraine") + .setName("Petya").build(); + + System.out.println(newUser.toString()); + + User second = User.newUser() + .setAge((byte) 20) + .setName("Vasya") + .setFootSize((byte) 45) + .setWeight((byte) 80) + .build(); + System.out.println(second); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/builder/User.java b/AlexSubbotin/lesson_23/src/main/java/builder/User.java new file mode 100644 index 0000000..e761dfd --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/builder/User.java @@ -0,0 +1,95 @@ +package builder; + +public class User { + + private String name; + private String surname; + private String bornCity; + private String bornCountry; + private String education; + private String email; + private byte age; + private byte weight; + private byte height; + private byte footSize; + + private User() { + } + + public static UserBuilder newUser() { + return new User().new UserBuilder(); + } + + @Override + public String toString() { + return "User{" + + "name='" + name + '\'' + + ", surname='" + surname + '\'' + + ", bornCity='" + bornCity + '\'' + + ", bornCountry='" + bornCountry + '\'' + + ", education='" + education + '\'' + + ", email='" + email + '\'' + + ", age=" + age + + ", weight=" + weight + + ", height=" + height + + ", footSize=" + footSize + + '}'; + } + + public class UserBuilder { + + public UserBuilder setName(String name) { + User.this.name = name; + return this; + } + + public UserBuilder setSurname(String surname) { + User.this.surname = surname; + return this; + } + + public UserBuilder setBornCity(String bornCity) { + User.this.bornCity = bornCity; + return this; + } + + public UserBuilder setBornCountry(String bornCountry) { + User.this.bornCountry = bornCountry; + return this; + } + + public UserBuilder setEducation(String education) { + User.this.education = education; + return this; + } + + public UserBuilder setEmail(String email) { + User.this.email = email; + return this; + } + + public UserBuilder setAge(byte age) { + User.this.age = age; + return this; + } + + public UserBuilder setWeight(byte weight) { + User.this.weight = weight; + return this; + } + + public UserBuilder setHeight(byte height) { + User.this.height = height; + return this; + } + + public UserBuilder setFootSize(byte footSize) { + User.this.footSize = footSize; + return this; + } + + public User build() { + return User.this; + } + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/factorym/ExcelReport.java b/AlexSubbotin/lesson_23/src/main/java/factorym/ExcelReport.java new file mode 100644 index 0000000..05c0bdb --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/factorym/ExcelReport.java @@ -0,0 +1,25 @@ +package factorym; + +public class ExcelReport implements ReportCreator { + + private Report report; + + public ExcelReport(String type) { + this.report = new Report(type); + } + + public Report createReport() { + return this.report; + } + + public void getType() { + System.out.println(this.report.getType()); + } + + @Override + public String toString() { + return "ExcelReport{" + + "report=" + report + + '}'; + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/factorym/FactoryMethodClient.java b/AlexSubbotin/lesson_23/src/main/java/factorym/FactoryMethodClient.java new file mode 100644 index 0000000..4c9d724 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/factorym/FactoryMethodClient.java @@ -0,0 +1,11 @@ +package factorym; + +public class FactoryMethodClient { + + public static void main(String[] args) { + ReportCreator rc = new PDFReport("PDF"); + rc.getType(); + rc = new ExcelReport("EXCEL"); + rc.getType(); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/factorym/PDFReport.java b/AlexSubbotin/lesson_23/src/main/java/factorym/PDFReport.java new file mode 100644 index 0000000..ca3c238 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/factorym/PDFReport.java @@ -0,0 +1,25 @@ +package factorym; + +public class PDFReport implements ReportCreator { + + private Report report; + + public PDFReport(String type) { + this.report = new Report(type); + } + + public Report createReport() { + return this.report; + } + + public void getType() { + System.out.println(this.report.getType()); + } + + @Override + public String toString() { + return "PDFReport{" + + "report=" + report + + '}'; + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/factorym/Report.java b/AlexSubbotin/lesson_23/src/main/java/factorym/Report.java new file mode 100644 index 0000000..1905b31 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/factorym/Report.java @@ -0,0 +1,21 @@ +package factorym; + +public class Report { + + private String type; + + public Report(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + @Override + public String toString() { + return "Report{" + + "type='" + type + '\'' + + '}'; + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/factorym/ReportCreator.java b/AlexSubbotin/lesson_23/src/main/java/factorym/ReportCreator.java new file mode 100644 index 0000000..69dfaec --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/factorym/ReportCreator.java @@ -0,0 +1,7 @@ +package factorym; + +public interface ReportCreator { + + Report createReport(); + void getType(); +} diff --git a/AlexSubbotin/lesson_23/src/main/java/prototype/ClientPrototype.java b/AlexSubbotin/lesson_23/src/main/java/prototype/ClientPrototype.java new file mode 100644 index 0000000..609aecd --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/prototype/ClientPrototype.java @@ -0,0 +1,17 @@ +package prototype; + +public class ClientPrototype { + + public static void main(String[] args) { + RectangularWindow first = new RectangularWindow(); + first.setHeight(10); + first.setWidth(20); + RectangularWindow second = (RectangularWindow) first.clone(); + Window window = first.clone(); + window.setColour("Black"); + + System.out.println(first); + System.out.println(second); + System.out.println(window); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/prototype/RectangularWindow.java b/AlexSubbotin/lesson_23/src/main/java/prototype/RectangularWindow.java new file mode 100644 index 0000000..d06fea5 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/prototype/RectangularWindow.java @@ -0,0 +1,39 @@ +package prototype; + +public class RectangularWindow extends Window { + + private int width; + private int height; + + public RectangularWindow() { + } + + public void setWidth(int width) { + this.width = width; + } + + public void setHeight(int height) { + this.height = height; + } + + public RectangularWindow(RectangularWindow rectangularWindow) { + super(rectangularWindow); + if (rectangularWindow != null) { + this.width = rectangularWindow.width; + this.height = rectangularWindow.height; + } + } + + @Override + public Window clone() { + return new RectangularWindow(this); + } + + @Override + public String toString() { + return "RectangularWindow{" + + "width=" + width + + ", height=" + height + + '}'; + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/prototype/RoundWindow.java b/AlexSubbotin/lesson_23/src/main/java/prototype/RoundWindow.java new file mode 100644 index 0000000..7181152 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/prototype/RoundWindow.java @@ -0,0 +1,25 @@ +package prototype; + +public class RoundWindow extends Window { + + private int radius; + + public RoundWindow() { + } + + public RoundWindow(RoundWindow roundWindow) { + super(roundWindow); + if (roundWindow != null) { + this.radius = roundWindow.radius; + } + } + + public void setRadius(int radius) { + this.radius = radius; + } + + @Override + public Window clone() { + return new RoundWindow(this); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/prototype/Window.java b/AlexSubbotin/lesson_23/src/main/java/prototype/Window.java new file mode 100644 index 0000000..57b6ae7 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/prototype/Window.java @@ -0,0 +1,21 @@ +package prototype; + +public abstract class Window { + + private String colour; + + public Window() { + } + + public Window(Window window) { + if (window != null) { + this.colour = window.colour; + } + } + + public void setColour(String colour) { + this.colour = colour; + } + + public abstract Window clone(); +} diff --git a/AlexSubbotin/lesson_23/src/main/java/singleton/ClientSingleton.java b/AlexSubbotin/lesson_23/src/main/java/singleton/ClientSingleton.java new file mode 100644 index 0000000..44d2bcc --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/singleton/ClientSingleton.java @@ -0,0 +1,11 @@ +package singleton; + +public class ClientSingleton { + + public static void main(String[] args) { + Singleton firstSingleton = Singleton.getInstance(); + System.out.println(firstSingleton.hashCode()); + Singleton secondSingleton = Singleton.getInstance(); + System.out.println(secondSingleton.hashCode()); + } +} diff --git a/AlexSubbotin/lesson_23/src/main/java/singleton/Singleton.java b/AlexSubbotin/lesson_23/src/main/java/singleton/Singleton.java new file mode 100644 index 0000000..30e8ff6 --- /dev/null +++ b/AlexSubbotin/lesson_23/src/main/java/singleton/Singleton.java @@ -0,0 +1,16 @@ +package singleton; + +public class Singleton { + + private Singleton() { + System.out.println("Singleton created."); + } + + private static class SingletonHolder { + public static final Singleton INSTANCE_HOLDER = new Singleton(); + } + + public static Singleton getInstance() { + return SingletonHolder.INSTANCE_HOLDER; + } +} diff --git a/AlexSubbotin/lesson_24/.idea/.gitignore b/AlexSubbotin/lesson_24/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_24/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/AlexSubbotin/lesson_24/.idea/compiler.xml b/AlexSubbotin/lesson_24/.idea/compiler.xml new file mode 100644 index 0000000..9ac200e --- /dev/null +++ b/AlexSubbotin/lesson_24/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_24/.idea/misc.xml b/AlexSubbotin/lesson_24/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_24/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_24/.idea/uiDesigner.xml b/AlexSubbotin/lesson_24/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/AlexSubbotin/lesson_24/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_24/.idea/vcs.xml b/AlexSubbotin/lesson_24/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_24/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_24/lesson_24.iml b/AlexSubbotin/lesson_24/lesson_24.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_24/lesson_24.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_24/pom.xml b/AlexSubbotin/lesson_24/pom.xml new file mode 100644 index 0000000..e8c7ad6 --- /dev/null +++ b/AlexSubbotin/lesson_24/pom.xml @@ -0,0 +1,12 @@ + + + 4.0.0 + + org.example + lesson_24 + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_24/src/main/java/adapter/AdapterClient.java b/AlexSubbotin/lesson_24/src/main/java/adapter/AdapterClient.java new file mode 100644 index 0000000..3bc1c80 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/adapter/AdapterClient.java @@ -0,0 +1,12 @@ +package adapter; + +public class AdapterClient { + + public static void main(String[] args) { + PlugWithThreeLegs plugWithThreeLegs = + new PlugWithThreeLegs( + new PlugToSocketAdapter( + new TwoLeggedSocket())); + plugWithThreeLegs.insertPlug(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/adapter/PlugAdapter.java b/AlexSubbotin/lesson_24/src/main/java/adapter/PlugAdapter.java new file mode 100644 index 0000000..0c3fd72 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/adapter/PlugAdapter.java @@ -0,0 +1,6 @@ +package adapter; + +public interface PlugAdapter { + + void plugIntoSocket(); +} diff --git a/AlexSubbotin/lesson_24/src/main/java/adapter/PlugToSocketAdapter.java b/AlexSubbotin/lesson_24/src/main/java/adapter/PlugToSocketAdapter.java new file mode 100644 index 0000000..8af963b --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/adapter/PlugToSocketAdapter.java @@ -0,0 +1,15 @@ +package adapter; + +public class PlugToSocketAdapter implements PlugAdapter{ + + private TwoLeggedSocket twoLeggedSocket; + + public PlugToSocketAdapter(TwoLeggedSocket twoLeggedSocket) { + this.twoLeggedSocket = twoLeggedSocket; + } + + public void plugIntoSocket() { + System.out.println("Isolate one leg for changed three legged plug into two legged plug"); + this.twoLeggedSocket.acceptTwoLeggedPlug(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/adapter/PlugWithThreeLegs.java b/AlexSubbotin/lesson_24/src/main/java/adapter/PlugWithThreeLegs.java new file mode 100644 index 0000000..9d674f2 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/adapter/PlugWithThreeLegs.java @@ -0,0 +1,14 @@ +package adapter; + +public class PlugWithThreeLegs { + + private PlugAdapter plugAdapter; + + public PlugWithThreeLegs(PlugAdapter plugAdapter) { + this.plugAdapter = plugAdapter; + } + + public void insertPlug() { + this.plugAdapter.plugIntoSocket(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/adapter/TwoLeggedSocket.java b/AlexSubbotin/lesson_24/src/main/java/adapter/TwoLeggedSocket.java new file mode 100644 index 0000000..d92a728 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/adapter/TwoLeggedSocket.java @@ -0,0 +1,8 @@ +package adapter; + +public class TwoLeggedSocket { + + public void acceptTwoLeggedPlug() { + System.out.println("Two legged plug accepted."); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/bridge/BridgeClient.java b/AlexSubbotin/lesson_24/src/main/java/bridge/BridgeClient.java new file mode 100644 index 0000000..42dc6fa --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/bridge/BridgeClient.java @@ -0,0 +1,18 @@ +package bridge; + +public class BridgeClient { + public static void main(String[] args) { + + Press[] press = {new SportMagazine(new MagazineWriter()), + new Newspaper(new NewspaperWriter())}; + for (Press pr : press) { + pr.createArticles(); + } + System.out.println("===================================="); + Press[] press2 = {new SportMagazine(new NewspaperWriter()), + new Newspaper(new MagazineWriter())}; + for (Press pr : press2) { + pr.createArticles(); + } +} +} diff --git a/AlexSubbotin/lesson_24/src/main/java/bridge/MagazineWriter.java b/AlexSubbotin/lesson_24/src/main/java/bridge/MagazineWriter.java new file mode 100644 index 0000000..baf016f --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/bridge/MagazineWriter.java @@ -0,0 +1,8 @@ +package bridge; + +public class MagazineWriter implements Writer { + + public void writeArticle() { + System.out.println("Magazine writer writes an article..."); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/bridge/Newspaper.java b/AlexSubbotin/lesson_24/src/main/java/bridge/Newspaper.java new file mode 100644 index 0000000..eda364c --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/bridge/Newspaper.java @@ -0,0 +1,13 @@ +package bridge; + +public class Newspaper extends Press { + + public Newspaper(Writer writer) { + super(writer); + } + + public void createArticles() { + System.out.println("Newspaper in progress..."); + writer.writeArticle(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/bridge/NewspaperWriter.java b/AlexSubbotin/lesson_24/src/main/java/bridge/NewspaperWriter.java new file mode 100644 index 0000000..379841e --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/bridge/NewspaperWriter.java @@ -0,0 +1,8 @@ +package bridge; + +public class NewspaperWriter implements Writer { + + public void writeArticle() { + System.out.println("Newspaper writer writes an article..."); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/bridge/Press.java b/AlexSubbotin/lesson_24/src/main/java/bridge/Press.java new file mode 100644 index 0000000..7f4c9ab --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/bridge/Press.java @@ -0,0 +1,12 @@ +package bridge; + +public abstract class Press { + + protected Writer writer; + + public Press(Writer writer) { + this.writer = writer; + } + + public abstract void createArticles(); +} diff --git a/AlexSubbotin/lesson_24/src/main/java/bridge/SportMagazine.java b/AlexSubbotin/lesson_24/src/main/java/bridge/SportMagazine.java new file mode 100644 index 0000000..921322f --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/bridge/SportMagazine.java @@ -0,0 +1,13 @@ +package bridge; + +public class SportMagazine extends Press { + + public SportMagazine(Writer writer) { + super(writer); + } + + public void createArticles() { + System.out.println("Sport magazine in progress..."); + writer.writeArticle(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/bridge/Writer.java b/AlexSubbotin/lesson_24/src/main/java/bridge/Writer.java new file mode 100644 index 0000000..f744f4b --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/bridge/Writer.java @@ -0,0 +1,6 @@ +package bridge; + +public interface Writer { + + void writeArticle(); +} diff --git a/AlexSubbotin/lesson_24/src/main/java/composite/CompositeClient.java b/AlexSubbotin/lesson_24/src/main/java/composite/CompositeClient.java new file mode 100644 index 0000000..34246de --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/composite/CompositeClient.java @@ -0,0 +1,18 @@ +package composite; + +public class CompositeClient { + public static void main(String[] args) { + + NewspaperFactory newspaperFactory = new NewspaperFactory(); + Writer firstNewsWriter = new NewsWriter(); + Writer secondNewsWriter = new NewsWriter(); + Writer sportNewsWriter = new SportNewsWriter(); + + newspaperFactory.addWriter(firstNewsWriter); + newspaperFactory.addWriter(secondNewsWriter); + newspaperFactory.addWriter(sportNewsWriter); + newspaperFactory.removeWriter(secondNewsWriter); + + newspaperFactory.createNewspaper(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/composite/NewsWriter.java b/AlexSubbotin/lesson_24/src/main/java/composite/NewsWriter.java new file mode 100644 index 0000000..cec5e92 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/composite/NewsWriter.java @@ -0,0 +1,8 @@ +package composite; + +public class NewsWriter implements Writer { + + public void writeArticle() { + System.out.println("News writer write an news article..."); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/composite/NewspaperFactory.java b/AlexSubbotin/lesson_24/src/main/java/composite/NewspaperFactory.java new file mode 100644 index 0000000..8eb917d --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/composite/NewspaperFactory.java @@ -0,0 +1,25 @@ +package composite; + +import java.util.ArrayList; +import java.util.List; + +public class NewspaperFactory { + + private List writers = new ArrayList(); + + public void addWriter(Writer writer) { + writers.add(writer); + } + + public void removeWriter(Writer writer) { + writers.remove(writer); + } + + public void createNewspaper() { + System.out.println("Factory creates newspaper...\n "); + + for (Writer writers : writers) { + writers.writeArticle(); + } + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/composite/SportNewsWriter.java b/AlexSubbotin/lesson_24/src/main/java/composite/SportNewsWriter.java new file mode 100644 index 0000000..42f6df2 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/composite/SportNewsWriter.java @@ -0,0 +1,8 @@ +package composite; + +public class SportNewsWriter implements Writer { + + public void writeArticle() { + System.out.println("Sport news writer writes an sport article... "); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/composite/Writer.java b/AlexSubbotin/lesson_24/src/main/java/composite/Writer.java new file mode 100644 index 0000000..7abd9c2 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/composite/Writer.java @@ -0,0 +1,6 @@ +package composite; + +public interface Writer { + + void writeArticle(); +} diff --git a/AlexSubbotin/lesson_24/src/main/java/decorator/DecoratorClient.java b/AlexSubbotin/lesson_24/src/main/java/decorator/DecoratorClient.java new file mode 100644 index 0000000..511ab85 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/decorator/DecoratorClient.java @@ -0,0 +1,11 @@ +package decorator; + +public class DecoratorClient { + public static void main(String[] args) { + ReportSender reportSender = new SmsConfirmSender( + new EmailReportDuplicator( + new PaperReport())); + + System.out.println(reportSender.sendReport()); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/decorator/EmailReportDuplicator.java b/AlexSubbotin/lesson_24/src/main/java/decorator/EmailReportDuplicator.java new file mode 100644 index 0000000..b3cb112 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/decorator/EmailReportDuplicator.java @@ -0,0 +1,17 @@ +package decorator; + +public class EmailReportDuplicator extends ReportDecorator { + + public EmailReportDuplicator(ReportSender reportSender) { + super(reportSender); + } + + public String sendEmail() { + return "Duplicate of report sent on email... "; + } + + @Override + public String sendReport() { + return super.sendReport() + sendEmail(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/decorator/PaperReport.java b/AlexSubbotin/lesson_24/src/main/java/decorator/PaperReport.java new file mode 100644 index 0000000..cee0b46 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/decorator/PaperReport.java @@ -0,0 +1,8 @@ +package decorator; + +public class PaperReport implements ReportSender { + + public String sendReport() { + return "Report on paper sent... "; + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/decorator/ReportDecorator.java b/AlexSubbotin/lesson_24/src/main/java/decorator/ReportDecorator.java new file mode 100644 index 0000000..aea4bcf --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/decorator/ReportDecorator.java @@ -0,0 +1,14 @@ +package decorator; + +public class ReportDecorator implements ReportSender { + + private ReportSender reportSender; + + public ReportDecorator(ReportSender reportSender) { + this.reportSender = reportSender; + } + + public String sendReport() { + return this.reportSender.sendReport(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/decorator/ReportSender.java b/AlexSubbotin/lesson_24/src/main/java/decorator/ReportSender.java new file mode 100644 index 0000000..3f6d79e --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/decorator/ReportSender.java @@ -0,0 +1,5 @@ +package decorator; + +public interface ReportSender { + String sendReport (); +} diff --git a/AlexSubbotin/lesson_24/src/main/java/decorator/SmsConfirmSender.java b/AlexSubbotin/lesson_24/src/main/java/decorator/SmsConfirmSender.java new file mode 100644 index 0000000..bf55185 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/decorator/SmsConfirmSender.java @@ -0,0 +1,17 @@ +package decorator; + +public class SmsConfirmSender extends ReportDecorator { + + public SmsConfirmSender(ReportSender reportSender) { + super(reportSender); + } + + public String sendSmsConfirmation() { + return "Confirmation from the sent report has been sent.."; + } + + @Override + public String sendReport() { + return super.sendReport() + sendSmsConfirmation(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/facade/CarAssembler.java b/AlexSubbotin/lesson_24/src/main/java/facade/CarAssembler.java new file mode 100644 index 0000000..781000a --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/facade/CarAssembler.java @@ -0,0 +1,20 @@ +package facade; + +public class CarAssembler { + + private boolean assemblyComplete; + + public boolean isAssemblyComplete() { + return assemblyComplete; + } + + public void doAssemble(CarBodyPainter carBodyPainter) { + if (carBodyPainter.isFinishedPainting()) { + System.out.println("Assembly in progress..."); + this.assemblyComplete = true; + } else { + System.out.println("Assembly is not possible, finish painting..."); + this.assemblyComplete = false; + } + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/facade/CarBodyPainter.java b/AlexSubbotin/lesson_24/src/main/java/facade/CarBodyPainter.java new file mode 100644 index 0000000..974d674 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/facade/CarBodyPainter.java @@ -0,0 +1,20 @@ +package facade; + +public class CarBodyPainter { + + private boolean finishedPainting; + + public boolean isFinishedPainting() { + return finishedPainting; + } + + public void startPaint() { + System.out.println("Painting in progress..."); + this.finishedPainting = false; + } + + public void finishPaint() { + System.out.println("Painting is finished."); + this.finishedPainting = true; + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/facade/CarWasher.java b/AlexSubbotin/lesson_24/src/main/java/facade/CarWasher.java new file mode 100644 index 0000000..8d35ea4 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/facade/CarWasher.java @@ -0,0 +1,13 @@ +package facade; + +public class CarWasher { + + public void washCar(CarAssembler carAssembler) { + if (carAssembler.isAssemblyComplete()) { + System.out.println("The car is ready for sale!"); + + } else { + System.out.println("The car is not ready for sale, finish all process..."); + } + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/facade/FacadeClient.java b/AlexSubbotin/lesson_24/src/main/java/facade/FacadeClient.java new file mode 100644 index 0000000..8dbd465 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/facade/FacadeClient.java @@ -0,0 +1,10 @@ +package facade; + +public class FacadeClient { + + public static void main(String[] args) { + Workflow workflow = new Workflow(); + workflow.prepareCar(); + } + +} diff --git a/AlexSubbotin/lesson_24/src/main/java/facade/Workflow.java b/AlexSubbotin/lesson_24/src/main/java/facade/Workflow.java new file mode 100644 index 0000000..e0171b7 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/facade/Workflow.java @@ -0,0 +1,15 @@ +package facade; + +public class Workflow { + + private CarBodyPainter cbp = new CarBodyPainter(); + private CarAssembler ca = new CarAssembler(); + private CarWasher cw = new CarWasher(); + + public void prepareCar() { + cbp.startPaint(); + cbp.finishPaint(); + ca.doAssemble(cbp); + cw.washCar(ca); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/flyweight/Archer.java b/AlexSubbotin/lesson_24/src/main/java/flyweight/Archer.java new file mode 100644 index 0000000..21507f6 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/flyweight/Archer.java @@ -0,0 +1,8 @@ +package flyweight; + +public class Archer implements Hero { + + public void move() { + System.out.println("Archer move ..."); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/flyweight/FlyweightClient.java b/AlexSubbotin/lesson_24/src/main/java/flyweight/FlyweightClient.java new file mode 100644 index 0000000..e42d156 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/flyweight/FlyweightClient.java @@ -0,0 +1,20 @@ +package flyweight; + +import java.util.ArrayList; +import java.util.List; + +public class FlyweightClient { + + public static void main(String[] args) { + HeroFactory heroFactory = new HeroFactory(); + List heroes = new ArrayList(); + for (int i = 0; i < 10; i++) { + heroes.add(heroFactory.takeHeroByClassName("Archer")); + heroes.add(heroFactory.takeHeroByClassName("Knight")); + } + + for (Hero hero : heroes) { + hero.move(); + } + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/flyweight/Hero.java b/AlexSubbotin/lesson_24/src/main/java/flyweight/Hero.java new file mode 100644 index 0000000..102a8b6 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/flyweight/Hero.java @@ -0,0 +1,6 @@ +package flyweight; + +public interface Hero { + + void move (); +} diff --git a/AlexSubbotin/lesson_24/src/main/java/flyweight/HeroFactory.java b/AlexSubbotin/lesson_24/src/main/java/flyweight/HeroFactory.java new file mode 100644 index 0000000..82bc609 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/flyweight/HeroFactory.java @@ -0,0 +1,24 @@ +package flyweight; + +import java.util.HashMap; +import java.util.Map; + +public class HeroFactory { + + private static final Map heroes = new HashMap(); + + public Hero takeHeroByClassName(String warriorName) { + Hero hero = heroes.get(warriorName); + if (hero == null) { + if ("Knight".equals(warriorName)) { + System.out.println("Take Knight..."); + hero = new Knight(); + } else if ("Archer".equals(warriorName)) { + System.out.println("Take Archer..."); + hero = new Archer(); + } + heroes.put(warriorName, hero); + } + return hero; + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/flyweight/Knight.java b/AlexSubbotin/lesson_24/src/main/java/flyweight/Knight.java new file mode 100644 index 0000000..8364e58 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/flyweight/Knight.java @@ -0,0 +1,8 @@ +package flyweight; + +public class Knight implements Hero { + + public void move() { + System.out.println("Knight move ..."); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/proxy/Car.java b/AlexSubbotin/lesson_24/src/main/java/proxy/Car.java new file mode 100644 index 0000000..9fdd116 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/proxy/Car.java @@ -0,0 +1,6 @@ +package proxy; + +public interface Car { + + void move(); +} diff --git a/AlexSubbotin/lesson_24/src/main/java/proxy/ProxyClient.java b/AlexSubbotin/lesson_24/src/main/java/proxy/ProxyClient.java new file mode 100644 index 0000000..a212b11 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/proxy/ProxyClient.java @@ -0,0 +1,9 @@ +package proxy; + +public class ProxyClient { + + public static void main(String[] args) { + Car car = new ProxyVAG(true); + car.move(); + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/proxy/ProxyVAG.java b/AlexSubbotin/lesson_24/src/main/java/proxy/ProxyVAG.java new file mode 100644 index 0000000..8e42764 --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/proxy/ProxyVAG.java @@ -0,0 +1,18 @@ +package proxy; + +public class ProxyVAG implements Car { + + private boolean turnOffAlarm = false; + private VAG volvo; + + public ProxyVAG(boolean turnOffAlarm) { + this.turnOffAlarm = turnOffAlarm; + } + + public void move() { + if (volvo == null) { + volvo = new VAG(turnOffAlarm); + volvo.move(); + } + } +} diff --git a/AlexSubbotin/lesson_24/src/main/java/proxy/VAG.java b/AlexSubbotin/lesson_24/src/main/java/proxy/VAG.java new file mode 100644 index 0000000..e4c3fdd --- /dev/null +++ b/AlexSubbotin/lesson_24/src/main/java/proxy/VAG.java @@ -0,0 +1,21 @@ +package proxy; + +public class VAG implements Car { + + private boolean turnOffAlarm = false; + + public VAG (boolean turnOffAlarm) { + this.turnOffAlarm = turnOffAlarm; + startEngine(); + } + + public void startEngine() { + if (turnOffAlarm) { + System.out.println("Engine started..."); + } + } + + public void move() { + System.out.println("Car is moving..."); + } +} diff --git a/AlexSubbotin/lesson_25/.idea/.gitignore b/AlexSubbotin/lesson_25/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_25/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/AlexSubbotin/lesson_25/.idea/compiler.xml b/AlexSubbotin/lesson_25/.idea/compiler.xml new file mode 100644 index 0000000..db19eb9 --- /dev/null +++ b/AlexSubbotin/lesson_25/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_25/.idea/misc.xml b/AlexSubbotin/lesson_25/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_25/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_25/.idea/uiDesigner.xml b/AlexSubbotin/lesson_25/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/AlexSubbotin/lesson_25/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_25/.idea/vcs.xml b/AlexSubbotin/lesson_25/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_25/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_25/lesson_25.iml b/AlexSubbotin/lesson_25/lesson_25.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_25/lesson_25.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_25/pom.xml b/AlexSubbotin/lesson_25/pom.xml new file mode 100644 index 0000000..c1b3e5f --- /dev/null +++ b/AlexSubbotin/lesson_25/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + org.example + lesson_25 + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 6 + 6 + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Client.java b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Client.java new file mode 100644 index 0000000..4cf1361 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Client.java @@ -0,0 +1,17 @@ +package chainOfResposibility; + +public class Client { + + public static void main(String[] args) { + Notifier reportNotifier = new SimpleReportNotifier(Priority.ROUTINE); + Notifier emailNotifier = new EmailNotifier(Priority.IMPORTANT); + Notifier smsNotifier = new SMSNotifier(Priority.ASAP); + + reportNotifier.setNextNotifier(emailNotifier); + emailNotifier.setNextNotifier(smsNotifier); + + reportNotifier.notifyManager("Everything is OK", Priority.ROUTINE); + reportNotifier.notifyManager("Something went wrong!", Priority.IMPORTANT); + reportNotifier.notifyManager("We had a problem here!!!", Priority.ASAP); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/EmailNotifier.java b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/EmailNotifier.java new file mode 100644 index 0000000..d9e9c0e --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/EmailNotifier.java @@ -0,0 +1,11 @@ +package chainOfResposibility; + +public class EmailNotifier extends Notifier{ + public EmailNotifier(int priority) { + super(priority); + } + + public void write(String massage) { + System.out.println("Sending email: " + massage); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Notifier.java b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Notifier.java new file mode 100644 index 0000000..dbc4abf --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Notifier.java @@ -0,0 +1,25 @@ +package chainOfResposibility; + +public abstract class Notifier { + private int priority; + private Notifier nextNotifier; + + public Notifier(int priority) { + this.priority = priority; + } + + public void setNextNotifier(Notifier nextNotifier) { + this.nextNotifier = nextNotifier; + } + + public void notifyManager(String massage, int level) { + if (level >= priority) { + write(massage); + } + if (nextNotifier != null) { + nextNotifier.notifyManager(massage, level); + } + } + + public abstract void write(String massage); +} diff --git a/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Priority.java b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Priority.java new file mode 100644 index 0000000..7a347ac --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/Priority.java @@ -0,0 +1,8 @@ +package chainOfResposibility; + +public class Priority { + + public static final int ROUTINE = 1; + public static final int IMPORTANT = 2; + public static final int ASAP = 3; +} diff --git a/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/SMSNotifier.java b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/SMSNotifier.java new file mode 100644 index 0000000..094f8e9 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/SMSNotifier.java @@ -0,0 +1,12 @@ +package chainOfResposibility; + +public class SMSNotifier extends Notifier { + + public SMSNotifier(int priority) { + super(priority); + } + + public void write(String massage) { + System.out.println("Sending SMS to manager: " + massage); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/SimpleReportNotifier.java b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/SimpleReportNotifier.java new file mode 100644 index 0000000..3632cda --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/chainOfResposibility/SimpleReportNotifier.java @@ -0,0 +1,11 @@ +package chainOfResposibility; + +public class SimpleReportNotifier extends Notifier { + public SimpleReportNotifier(int priority) { + super(priority); + } + + public void write(String massage) { + System.out.println("Notifying using simple report: " + massage); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/command/Client.java b/AlexSubbotin/lesson_25/src/main/java/command/Client.java new file mode 100644 index 0000000..de4b9fa --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/command/Client.java @@ -0,0 +1,16 @@ +package command; + +public class Client { + + public static void main(String[] args) { + Database database = new Database(); + + Invoker developer = new Invoker(new InsertCommand(database), (Command) new UpdateCommand (database), + new SelectCommand(database), new DeleteCommand(database)); + + developer.insertRecord(); + developer.updateRecord(); + developer.selectRecord(); + developer.deleteRecord(); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/command/Command.java b/AlexSubbotin/lesson_25/src/main/java/command/Command.java new file mode 100644 index 0000000..2d2f1c5 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/command/Command.java @@ -0,0 +1,6 @@ +package command; + +public interface Command { + + void execute(); +} diff --git a/AlexSubbotin/lesson_25/src/main/java/command/Database.java b/AlexSubbotin/lesson_25/src/main/java/command/Database.java new file mode 100644 index 0000000..ed7e558 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/command/Database.java @@ -0,0 +1,20 @@ +package command; + +public class Database { + + public void insert() { + System.out.println("inserting record..."); + } + + public void update() { + System.out.println("Updating record..."); + } + + public void select() { + System.out.println("Reading record..."); + } + + public void delete() { + System.out.println("Deleting record..."); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/command/DeleteCommand.java b/AlexSubbotin/lesson_25/src/main/java/command/DeleteCommand.java new file mode 100644 index 0000000..1e9d443 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/command/DeleteCommand.java @@ -0,0 +1,14 @@ +package command; + +public class DeleteCommand implements Command { + + private Database database; + + public DeleteCommand(Database database) { + this.database = database; + } + + public void execute() { + this.database.delete(); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/command/InsertCommand.java b/AlexSubbotin/lesson_25/src/main/java/command/InsertCommand.java new file mode 100644 index 0000000..ce96e93 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/command/InsertCommand.java @@ -0,0 +1,13 @@ +package command; + +public class InsertCommand implements Command { + + private Database database; + + public InsertCommand(Database database) { + this.database = database; + } + public void execute() { + this.database.insert(); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/command/Invoker.java b/AlexSubbotin/lesson_25/src/main/java/command/Invoker.java new file mode 100644 index 0000000..2b68b04 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/command/Invoker.java @@ -0,0 +1,31 @@ +package command; + +public class Invoker { + private Command insert; + private Command update; + private Command select; + private Command delete; + + public Invoker(Command insert, Command update, Command select, Command delete) { + this.insert = insert; + this.update = update; + this.select = select; + this.delete = delete; + } + + public void insertRecord() { + this.insert.execute(); + } + + public void updateRecord() { + this.update.execute(); + } + + public void selectRecord() { + this.select.execute(); + } + + public void deleteRecord() { + this.delete.execute(); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/command/SelectCommand.java b/AlexSubbotin/lesson_25/src/main/java/command/SelectCommand.java new file mode 100644 index 0000000..098e2a1 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/command/SelectCommand.java @@ -0,0 +1,14 @@ +package command; + +public class SelectCommand implements Command { + + private Database database; + + public SelectCommand(Database database) { + this.database = database; + } + + public void execute() { + this.database.select(); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/command/UpdateCommand.java b/AlexSubbotin/lesson_25/src/main/java/command/UpdateCommand.java new file mode 100644 index 0000000..7c4f258 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/command/UpdateCommand.java @@ -0,0 +1,14 @@ +package command; + +public class UpdateCommand { + + private Database database; + + public UpdateCommand( Database database) { + this.database = database; + } + + public void execute() { + this.database.update(); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/interpreter/BinaryExpression.java b/AlexSubbotin/lesson_25/src/main/java/interpreter/BinaryExpression.java new file mode 100644 index 0000000..d097b1e --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/interpreter/BinaryExpression.java @@ -0,0 +1,15 @@ +package interpreter; + +public class BinaryExpression implements Expression { + + private int number; + + public BinaryExpression(int number) { + this.number = number; + } + + @Override + public String interpret(Context context) { + return context.getBinaryExpression(number); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/interpreter/Client.java b/AlexSubbotin/lesson_25/src/main/java/interpreter/Client.java new file mode 100644 index 0000000..acfb679 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/interpreter/Client.java @@ -0,0 +1,39 @@ +package interpreter; + +public class Client { + + private Context context; + + public Client(Context context) { + this.context = context; + } + + public static void main(String[] args) { + String binary = "256 in Binary: "; + String octal = "256 in Octal: "; + String hexadecimal = "256 in Hexadecimal: "; + + Client expression = new Client(new Context()); + System.out.println(binary + expression.interpret(binary)); + System.out.println(octal + expression.interpret(octal)); + System.out.println(hexadecimal + expression.interpret(hexadecimal)); + } + + private String interpret(String text) { + Expression expression; + + int number = Integer.parseInt(text.substring(0, text.indexOf(" "))); + + if (text.contains("Binary")) { + expression = new BinaryExpression(number); + } else if (text.contains("Octal")) { + expression = new OctalExpression(number); + } else if (text.contains("Hexadecimal")) { + expression = new HexadecimalExpression(number); + } else { + return text; + } + + return expression.interpret(context); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/interpreter/Context.java b/AlexSubbotin/lesson_25/src/main/java/interpreter/Context.java new file mode 100644 index 0000000..adc18ce --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/interpreter/Context.java @@ -0,0 +1,16 @@ +package interpreter; + +public class Context { + + public String getBinaryExpression(int number) { + return Integer.toBinaryString(number); + } + + public String getOctalExpression(int number) { + return Integer.toOctalString(number); + } + + public String getHexadecimalExpression(int number) { + return Integer.toHexString(number); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/interpreter/Expression.java b/AlexSubbotin/lesson_25/src/main/java/interpreter/Expression.java new file mode 100644 index 0000000..93ebbe7 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/interpreter/Expression.java @@ -0,0 +1,5 @@ +package interpreter; + +public interface Expression { + String interpret(Context context); +} \ No newline at end of file diff --git a/AlexSubbotin/lesson_25/src/main/java/interpreter/HexadecimalExpression.java b/AlexSubbotin/lesson_25/src/main/java/interpreter/HexadecimalExpression.java new file mode 100644 index 0000000..6289f97 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/interpreter/HexadecimalExpression.java @@ -0,0 +1,15 @@ +package interpreter; + +public class HexadecimalExpression implements Expression { + + private int number; + + public HexadecimalExpression(int number) { + this.number = number; + } + + @Override + public String interpret(Context context) { + return context.getHexadecimalExpression(number); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/interpreter/OctalExpression.java b/AlexSubbotin/lesson_25/src/main/java/interpreter/OctalExpression.java new file mode 100644 index 0000000..c257755 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/interpreter/OctalExpression.java @@ -0,0 +1,15 @@ +package interpreter; + +public class OctalExpression implements Expression { + + private int number; + + public OctalExpression(int number) { + this.number = number; + } + + @Override + public String interpret(Context context) { + return context.getOctalExpression(number); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/iterator/Client.java b/AlexSubbotin/lesson_25/src/main/java/iterator/Client.java new file mode 100644 index 0000000..765bdd0 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/iterator/Client.java @@ -0,0 +1,17 @@ +package iterator; + +public class Client { + + public static void main(String[] args) { + String[] skills = {"Java Core", "OOP", "Maven", "SQL", "Algorithms", "Patterns"}; + JavaDeveloper javaDeveloper = new JavaDeveloper("Alex", skills); + + Iterator iterator = javaDeveloper.getIterator(); + System.out.println("Developer: " + javaDeveloper.getName()); + System.out.println("Skills: "); + + while (iterator.hasNext()) { + System.out.print(iterator.next() + " "); + } + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/iterator/Collection.java b/AlexSubbotin/lesson_25/src/main/java/iterator/Collection.java new file mode 100644 index 0000000..c405b0f --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/iterator/Collection.java @@ -0,0 +1,6 @@ +package iterator; + +public interface Collection { + + Iterator getIterator(); +} diff --git a/AlexSubbotin/lesson_25/src/main/java/iterator/Iterator.java b/AlexSubbotin/lesson_25/src/main/java/iterator/Iterator.java new file mode 100644 index 0000000..987f9c2 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/iterator/Iterator.java @@ -0,0 +1,7 @@ +package iterator; + +public interface Iterator { + + boolean hasNext(); + Object next(); +} diff --git a/AlexSubbotin/lesson_25/src/main/java/iterator/JavaDeveloper.java b/AlexSubbotin/lesson_25/src/main/java/iterator/JavaDeveloper.java new file mode 100644 index 0000000..e58ad8e --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/iterator/JavaDeveloper.java @@ -0,0 +1,50 @@ +package iterator; + +public class JavaDeveloper implements Collection { + + private String name; + private String[] skills; + + public JavaDeveloper(String name, String[] skills) { + this.name = name; + this.skills = skills; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String[] getSkills() { + return skills; + } + + public void setSkills(String[] skills) { + this.skills = skills; + } + + @Override + public Iterator getIterator() { + return new SkillIterator(); + } + + private class SkillIterator implements Iterator { + private int index; + + @Override + public boolean hasNext() { + if (index < skills.length) { + return true; + } + return false; + } + + @Override + public Object next() { + return skills[index++]; + } + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/memento/Client.java b/AlexSubbotin/lesson_25/src/main/java/memento/Client.java new file mode 100644 index 0000000..b2624c2 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/memento/Client.java @@ -0,0 +1,27 @@ +package memento; + +public class Client { + + public static void main(String[] args) throws InterruptedException { + Project project = new Project(); + GitHubRepo gitHubRepo = new GitHubRepo(); + + System.out.println("Creating project. Version 1.0"); + project.setVersionAndDate("Version 1.0"); + System.out.println(project); + + System.out.println("Saving current version..."); + gitHubRepo.setSave(project.save()); + + System.out.println("Updating project to version 1.1"); + Thread.sleep(5000); + project.setVersionAndDate("Version 1.1"); + System.out.println(project); + + System.out.println("Rolling back to Version 1.0"); + project.load(gitHubRepo.getSave()); + + System.out.println("Project after roll back"); + System.out.println(project); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/memento/GitHubRepo.java b/AlexSubbotin/lesson_25/src/main/java/memento/GitHubRepo.java new file mode 100644 index 0000000..d568e9f --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/memento/GitHubRepo.java @@ -0,0 +1,14 @@ +package memento; + +public class GitHubRepo { + + private Save save; + + public Save getSave() { + return save; + } + + public void setSave(Save save) { + this.save = save; + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/memento/Project.java b/AlexSubbotin/lesson_25/src/main/java/memento/Project.java new file mode 100644 index 0000000..52ab8d8 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/memento/Project.java @@ -0,0 +1,30 @@ +package memento; + +import java.util.Date; + +public class Project { + + private String version; + private Date date; + + public void setVersionAndDate(String version) { + this.version = version; + this.date = new Date(); + } + + public Save save() { + return new Save(version); + } + + public void load(Save save) { + this.version = save.getVersion(); + this.date = save.getDate(); + } + + @Override + public String toString() { + return "Project: " + + "\nVersion: " + version + + "\nDate: " + date + "\n"; + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/memento/Save.java b/AlexSubbotin/lesson_25/src/main/java/memento/Save.java new file mode 100644 index 0000000..abb1eaa --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/memento/Save.java @@ -0,0 +1,22 @@ +package memento; + +import java.util.Date; + +public class Save { + + private final String version; + private final Date date; + + public Save(String version) { + this.version = version; + this.date = new Date(); + } + + public String getVersion() { + return version; + } + + public Date getDate() { + return date; + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/templateMethod/Client.java b/AlexSubbotin/lesson_25/src/main/java/templateMethod/Client.java new file mode 100644 index 0000000..894bc78 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/templateMethod/Client.java @@ -0,0 +1,12 @@ +package templateMethod; + +public class Client { + + public static void main(String[] args) { + HouseTemplate houseType = new WoodenHouse(); + houseType.buildHouse(); + + houseType = new GlassHouse(); + houseType.buildHouse(); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/templateMethod/GlassHouse.java b/AlexSubbotin/lesson_25/src/main/java/templateMethod/GlassHouse.java new file mode 100644 index 0000000..bbc8e5a --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/templateMethod/GlassHouse.java @@ -0,0 +1,14 @@ +package templateMethod; + +public class GlassHouse extends HouseTemplate { + + @Override + public void buildWalls() { + System.out.println("Building Glass Walls"); + } + + @Override + public void buildPillars() { + System.out.println("Building Pillars with glass coating"); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/templateMethod/HouseTemplate.java b/AlexSubbotin/lesson_25/src/main/java/templateMethod/HouseTemplate.java new file mode 100644 index 0000000..8758df6 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/templateMethod/HouseTemplate.java @@ -0,0 +1,25 @@ +package templateMethod; + +public abstract class HouseTemplate { + + public final void buildHouse() { + buildFoundation(); + buildPillars(); + buildWalls(); + buildWindows(); + System.out.println("House is built."); + } + + private void buildWindows() { + System.out.println("Building Glass Windows"); + } + + public abstract void buildWalls(); + + public abstract void buildPillars(); + + private void buildFoundation() { + System.out.println("Build foundation with cement," + + "iron rods and sand"); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/templateMethod/WoodenHouse.java b/AlexSubbotin/lesson_25/src/main/java/templateMethod/WoodenHouse.java new file mode 100644 index 0000000..b59e0d1 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/templateMethod/WoodenHouse.java @@ -0,0 +1,14 @@ +package templateMethod; + +public class WoodenHouse extends HouseTemplate { + + @Override + public void buildWalls() { + System.out.println("Building Wooden Walls"); + } + + @Override + public void buildPillars() { + System.out.println("Building Pillars with Wood coating"); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/Client.java b/AlexSubbotin/lesson_25/src/main/java/visitor/Client.java new file mode 100644 index 0000000..73876e0 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/Client.java @@ -0,0 +1,18 @@ +package visitor; + +public class Client { + + public static void main(String[] args) { + Project project = new Project(); + + Developer junior = new JuniorDeveloper(); + Developer senior = new SeniorDeveloper(); + + System.out.println("Junior in action..."); + project.beWritten(junior); + + System.out.println("Senior in action...."); + project.beWritten(senior); + + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/Database.java b/AlexSubbotin/lesson_25/src/main/java/visitor/Database.java new file mode 100644 index 0000000..cc683d3 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/Database.java @@ -0,0 +1,9 @@ +package visitor; + +public class Database implements ProjectElement { + + @Override + public void beWritten(Developer developer) { + developer.create(this); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/Developer.java b/AlexSubbotin/lesson_25/src/main/java/visitor/Developer.java new file mode 100644 index 0000000..68af30d --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/Developer.java @@ -0,0 +1,10 @@ +package visitor; + +public interface Developer { + + void create(ProjectClass projectClass); + + void create(Database database); + + void create(Test test); +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/JuniorDeveloper.java b/AlexSubbotin/lesson_25/src/main/java/visitor/JuniorDeveloper.java new file mode 100644 index 0000000..1d70086 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/JuniorDeveloper.java @@ -0,0 +1,19 @@ +package visitor; + +public class JuniorDeveloper implements Developer { + + @Override + public void create(ProjectClass projectClass) { + System.out.println("Writing poor code..."); + } + + @Override + public void create(Database database) { + System.out.println("Drop database..."); + } + + @Override + public void create(Test test) { + System.out.println("Creating not reliable test..."); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/Project.java b/AlexSubbotin/lesson_25/src/main/java/visitor/Project.java new file mode 100644 index 0000000..57a2044 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/Project.java @@ -0,0 +1,21 @@ +package visitor; + +public class Project implements ProjectElement { + + ProjectElement[] projectElements; + + public Project() { + this.projectElements = new ProjectElement[] { + new ProjectClass(), + new Database(), + new Test() + }; + } + + @Override + public void beWritten(Developer developer) { + for (ProjectElement element : projectElements) { + element.beWritten(developer); + } + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/ProjectClass.java b/AlexSubbotin/lesson_25/src/main/java/visitor/ProjectClass.java new file mode 100644 index 0000000..7babdde --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/ProjectClass.java @@ -0,0 +1,9 @@ +package visitor; + +public class ProjectClass implements ProjectElement { + + @Override + public void beWritten(Developer developer) { + developer.create(this); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/ProjectElement.java b/AlexSubbotin/lesson_25/src/main/java/visitor/ProjectElement.java new file mode 100644 index 0000000..e6fe350 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/ProjectElement.java @@ -0,0 +1,6 @@ +package visitor; + +public interface ProjectElement { + + void beWritten(Developer developer); +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/SeniorDeveloper.java b/AlexSubbotin/lesson_25/src/main/java/visitor/SeniorDeveloper.java new file mode 100644 index 0000000..d5f2407 --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/SeniorDeveloper.java @@ -0,0 +1,19 @@ +package visitor; + +public class SeniorDeveloper implements Developer { + + @Override + public void create(ProjectClass projectClass) { + System.out.println("Rewriting code after junior..."); + } + + @Override + public void create(Database database) { + System.out.println("Fixing database..."); + } + + @Override + public void create(Test test) { + System.out.println("Creating reliable test..."); + } +} diff --git a/AlexSubbotin/lesson_25/src/main/java/visitor/Test.java b/AlexSubbotin/lesson_25/src/main/java/visitor/Test.java new file mode 100644 index 0000000..8d02b5a --- /dev/null +++ b/AlexSubbotin/lesson_25/src/main/java/visitor/Test.java @@ -0,0 +1,9 @@ +package visitor; + +public class Test implements ProjectElement { + + @Override + public void beWritten(Developer developer) { + developer.create(this); + } +} diff --git a/AlexSubbotin/lesson_26/.idea/.gitignore b/AlexSubbotin/lesson_26/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/AlexSubbotin/lesson_26/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/AlexSubbotin/lesson_26/.idea/compiler.xml b/AlexSubbotin/lesson_26/.idea/compiler.xml new file mode 100644 index 0000000..cd79aa3 --- /dev/null +++ b/AlexSubbotin/lesson_26/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_26/.idea/misc.xml b/AlexSubbotin/lesson_26/.idea/misc.xml new file mode 100644 index 0000000..d24ea8e --- /dev/null +++ b/AlexSubbotin/lesson_26/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_26/.idea/vcs.xml b/AlexSubbotin/lesson_26/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/AlexSubbotin/lesson_26/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_26/lesson_26.iml b/AlexSubbotin/lesson_26/lesson_26.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/AlexSubbotin/lesson_26/lesson_26.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_26/pom.xml b/AlexSubbotin/lesson_26/pom.xml new file mode 100644 index 0000000..93ff174 --- /dev/null +++ b/AlexSubbotin/lesson_26/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + org.example + lesson_26 + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + + + + \ No newline at end of file diff --git a/AlexSubbotin/lesson_26/src/main/java/mediator/Action.java b/AlexSubbotin/lesson_26/src/main/java/mediator/Action.java new file mode 100644 index 0000000..31eeec5 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/mediator/Action.java @@ -0,0 +1,12 @@ +package mediator; + +public interface Action { + + void createOrder(); + + void setOrder(Order order); + + String getInfo(); + + Order getOrder(); +} diff --git a/AlexSubbotin/lesson_26/src/main/java/mediator/Chef.java b/AlexSubbotin/lesson_26/src/main/java/mediator/Chef.java new file mode 100644 index 0000000..1de293c --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/mediator/Chef.java @@ -0,0 +1,38 @@ +package mediator; + +public class Chef implements Action { + + private Mediator mediator; + + private String name; + + private Order order; + + public Chef(Mediator mediator, String name) { + this.mediator = mediator; + this.name = name; + } + + @Override + public void createOrder() { + System.out.println(this.name + " create order: "); + for (Product product : order.getProducts()) { + System.out.println(product.getName()); + } + } + + @Override + public void setOrder(Order order) { + this.order = order; + } + + @Override + public String getInfo() { + return name; + } + + @Override + public Order getOrder() { + return order; + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/mediator/Client.java b/AlexSubbotin/lesson_26/src/main/java/mediator/Client.java new file mode 100644 index 0000000..3aab576 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/mediator/Client.java @@ -0,0 +1,43 @@ +package mediator; + +public class Client { + + public static void main(String[] args) { + Product coffee = new Product("Coffee"); + Product tea = new Product("Tea"); + Product cake = new Product("Cake"); + + Mediator mediator = new Waiter(); + + Action firstCooker = new Chef(mediator, "First cooker"); + Action secondCooker = new Chef(mediator, "Second cooker"); + Action firstVisitor = new Guest(mediator, "Bob"); + Action secondVisitor = new Guest(mediator, "Ashly"); + + Order firstOrder = new Order(firstVisitor.getInfo()); + firstOrder.addProduct(coffee); + firstOrder.addProduct(cake); + + mediator.addAction(firstVisitor, firstOrder); + mediator.addAction(firstCooker, firstOrder); + + Order secondOrder = new Order(secondVisitor.getInfo()); + secondOrder.addProduct(tea); + secondOrder.addProduct(cake); + + mediator.addAction(secondVisitor, secondOrder); + mediator.addAction(secondCooker, secondOrder); + + mediator.transferFrom(firstVisitor); + System.out.println("\n=====================\n"); + + mediator.transferFrom(firstCooker); + System.out.println("\n=====================\n"); + + mediator.transferFrom(secondVisitor); + System.out.println("\n=====================\n"); + + mediator.transferFrom(secondCooker); + System.out.println("\n=====================\n"); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/mediator/Guest.java b/AlexSubbotin/lesson_26/src/main/java/mediator/Guest.java new file mode 100644 index 0000000..7925f4b --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/mediator/Guest.java @@ -0,0 +1,38 @@ +package mediator; + +public class Guest implements Action { + + private Mediator mediator; + + private String name; + + private Order order; + + public Guest(Mediator mediator, String name) { + this.mediator = mediator; + this.name = name; + } + + @Override + public void createOrder() { + System.out.println(this.name + " making order: "); + for (Product product : this.order.getProducts()) { + System.out.println(product.getName()); + } + } + + @Override + public void setOrder(Order order) { + this.order = order; + } + + @Override + public String getInfo() { + return name; + } + + @Override + public Order getOrder() { + return order; + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/mediator/Mediator.java b/AlexSubbotin/lesson_26/src/main/java/mediator/Mediator.java new file mode 100644 index 0000000..6d1fa0c --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/mediator/Mediator.java @@ -0,0 +1,8 @@ +package mediator; + +public interface Mediator { + + void transferFrom(Action sender); + + void addAction(Action action, Order order); +} diff --git a/AlexSubbotin/lesson_26/src/main/java/mediator/Order.java b/AlexSubbotin/lesson_26/src/main/java/mediator/Order.java new file mode 100644 index 0000000..29b9db1 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/mediator/Order.java @@ -0,0 +1,36 @@ +package mediator; + + import java.util.ArrayList; + import java.util.List; + +public class Order { + + private String id; + + private List products; + + public Order(String id) { + this.id = id; + this.products = new ArrayList<>(); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public List getProducts() { + return products; + } + + public void addProduct(Product product) { + this.products.add(product); + } + + public void removeProduct(Product product) { + this.products.remove(product); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/mediator/Product.java b/AlexSubbotin/lesson_26/src/main/java/mediator/Product.java new file mode 100644 index 0000000..90b4d25 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/mediator/Product.java @@ -0,0 +1,14 @@ +package mediator; + +public class Product { + + private String name; + + public Product(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/mediator/Waiter.java b/AlexSubbotin/lesson_26/src/main/java/mediator/Waiter.java new file mode 100644 index 0000000..ce5d115 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/mediator/Waiter.java @@ -0,0 +1,25 @@ +package mediator; + +import java.util.ArrayList; +import java.util.List; + +public class Waiter implements Mediator { + + private List actions = new ArrayList<>(); + + @Override + public void transferFrom(Action sender) { + for (Action action : actions) { + if (action.equals(sender)) { + sender.createOrder(); + System.out.println("Order from: " + sender.getOrder().getId()); + } + } + } + + @Override + public void addAction(Action action, Order order) { + action.setOrder(order); + this.actions.add(action); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/observer/Client.java b/AlexSubbotin/lesson_26/src/main/java/observer/Client.java new file mode 100644 index 0000000..373812e --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/observer/Client.java @@ -0,0 +1,21 @@ +package observer; + +public class Client { + + public static void main(String[] args) { + DeveloperJobSite jobSite = new DeveloperJobSite(); + + jobSite.addVacancy("First java position"); + jobSite.addVacancy("Second java position"); + + Observer firstSubscriber = new Subscriber("Bob"); + Observer secondSubscriber = new Subscriber("Tom"); + + jobSite.addObserver(firstSubscriber); + jobSite.addObserver(secondSubscriber); + + jobSite.addVacancy("Third java position"); + + jobSite.removeVacancy("First java position"); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/observer/DeveloperJobSite.java b/AlexSubbotin/lesson_26/src/main/java/observer/DeveloperJobSite.java new file mode 100644 index 0000000..c333241 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/observer/DeveloperJobSite.java @@ -0,0 +1,35 @@ +package observer; + +import java.util.ArrayList; +import java.util.List; + +public class DeveloperJobSite implements Observed { + + private List vacancies = new ArrayList<>(); + + private List subscribers = new ArrayList<>(); + + public void addVacancy(String vacancy) { + this.vacancies.add(vacancy); + notifyObservers(); + } + + public void removeVacancy(String vacancy) { + this.vacancies.remove(vacancy); + notifyObservers(); + } + + public void addObserver(Observer observer) { + this.subscribers.add(observer); + } + + public void removeObserver(Observer observer) { + this.subscribers.remove(observer); + } + + public void notifyObservers() { + for (Observer observer : subscribers) { + observer.handleEvent(this.vacancies); + } + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/observer/Observed.java b/AlexSubbotin/lesson_26/src/main/java/observer/Observed.java new file mode 100644 index 0000000..f2c9e96 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/observer/Observed.java @@ -0,0 +1,10 @@ +package observer; + +public interface Observed { + void addObserver(Observer observer); + + void removeObserver(Observer observer); + + void notifyObservers(); + +} diff --git a/AlexSubbotin/lesson_26/src/main/java/observer/Observer.java b/AlexSubbotin/lesson_26/src/main/java/observer/Observer.java new file mode 100644 index 0000000..d491019 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/observer/Observer.java @@ -0,0 +1,7 @@ +package observer; + +import java.util.List; + +public interface Observer { + void handleEvent(List vacancies); +} diff --git a/AlexSubbotin/lesson_26/src/main/java/observer/Subscriber.java b/AlexSubbotin/lesson_26/src/main/java/observer/Subscriber.java new file mode 100644 index 0000000..15cccaa --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/observer/Subscriber.java @@ -0,0 +1,17 @@ +package observer; + +import java.util.List; + +public class Subscriber implements Observer { + + private String name; + + public Subscriber(String name) { + this.name = name; + } + + public void handleEvent(List vacancies) { + System.out.println("Dear " + name + "\nWe have some changes in vacancies:\n" + + vacancies + "\n============================================\n"); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/state/Activity.java b/AlexSubbotin/lesson_26/src/main/java/state/Activity.java new file mode 100644 index 0000000..2474a1f --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/state/Activity.java @@ -0,0 +1,5 @@ +package state; + +public interface Activity { + void doAction(); +} diff --git a/AlexSubbotin/lesson_26/src/main/java/state/Client.java b/AlexSubbotin/lesson_26/src/main/java/state/Client.java new file mode 100644 index 0000000..914b505 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/state/Client.java @@ -0,0 +1,16 @@ +package state; + +public class Client { + + public static void main(String[] args) { + Activity activity = new Sleeping(); + Developer developer = new Developer(); + + developer.setActivity(activity); + + for (int i = 0; i < 10; i++) { + developer.doAction(); + developer.changeActivity(); + } + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/state/Coding.java b/AlexSubbotin/lesson_26/src/main/java/state/Coding.java new file mode 100644 index 0000000..3955da0 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/state/Coding.java @@ -0,0 +1,9 @@ +package state; + +public class Coding implements Activity { + + @Override + public void doAction() { + System.out.println("Writing code..."); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/state/Developer.java b/AlexSubbotin/lesson_26/src/main/java/state/Developer.java new file mode 100644 index 0000000..bdea21a --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/state/Developer.java @@ -0,0 +1,26 @@ +package state; + +public class Developer { + + Activity activity; + + public void setActivity(Activity activity) { + this.activity = activity; + } + + public void changeActivity() { + if (this.activity instanceof Sleeping) { + setActivity(new Training()); + } else if (this.activity instanceof Training) { + setActivity(new Coding()); + } else if (this.activity instanceof Coding) { + setActivity(new Reading()); + } else if (this.activity instanceof Reading) { + setActivity(new Sleeping()); + } + } + + public void doAction() { + this.activity.doAction(); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/state/Reading.java b/AlexSubbotin/lesson_26/src/main/java/state/Reading.java new file mode 100644 index 0000000..d54b261 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/state/Reading.java @@ -0,0 +1,9 @@ +package state; + +public class Reading implements Activity { + + @Override + public void doAction() { + System.out.println("Reading book..."); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/state/Sleeping.java b/AlexSubbotin/lesson_26/src/main/java/state/Sleeping.java new file mode 100644 index 0000000..474368b --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/state/Sleeping.java @@ -0,0 +1,9 @@ +package state; + +public class Sleeping implements Activity { + + @Override + public void doAction() { + System.out.println("Sleeping"); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/state/Training.java b/AlexSubbotin/lesson_26/src/main/java/state/Training.java new file mode 100644 index 0000000..ad7133a --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/state/Training.java @@ -0,0 +1,9 @@ +package state; + +public class Training implements Activity { + + @Override + public void doAction() { + System.out.println("Training..."); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/strategy/AggressiveStrategy.java b/AlexSubbotin/lesson_26/src/main/java/strategy/AggressiveStrategy.java new file mode 100644 index 0000000..9119bde --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/strategy/AggressiveStrategy.java @@ -0,0 +1,9 @@ +package strategy; + +public class AggressiveStrategy implements Strategy { + + @Override + public void actionCommand() { + System.out.println("Aggressive strategy. Find and kill opponent"); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/strategy/CounterStrike.java b/AlexSubbotin/lesson_26/src/main/java/strategy/CounterStrike.java new file mode 100644 index 0000000..905aba1 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/strategy/CounterStrike.java @@ -0,0 +1,24 @@ +package strategy; + +public class CounterStrike { + public static void main(String[] args) { + Player terrorist = new Player("Terrorist"); + Player counter_Terrorist = new Player("Counter-Terrorist"); + + System.out.println("Before bomb is planted"); + + terrorist.setStrategy(new AggressiveStrategy()); + counter_Terrorist.setStrategy(new DefensiveStrategy()); + + terrorist.action(); + counter_Terrorist.action(); + + System.out.println("After bomb is planted"); + + terrorist.setStrategy(new DefensiveStrategy()); + counter_Terrorist.setStrategy(new AggressiveStrategy()); + + terrorist.action(); + counter_Terrorist.action(); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/strategy/DefensiveStrategy.java b/AlexSubbotin/lesson_26/src/main/java/strategy/DefensiveStrategy.java new file mode 100644 index 0000000..13562e0 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/strategy/DefensiveStrategy.java @@ -0,0 +1,9 @@ +package strategy; + +public class DefensiveStrategy implements Strategy { + + @Override + public void actionCommand() { + System.out.println("Defensive strategy. Protect self and teammates"); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/strategy/Player.java b/AlexSubbotin/lesson_26/src/main/java/strategy/Player.java new file mode 100644 index 0000000..e4784b3 --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/strategy/Player.java @@ -0,0 +1,20 @@ +package strategy; + +public class Player { + + Strategy behavior; + String type; + + public Player(String type) { + this.type = type; + } + + public void setStrategy(Strategy behavior) { + this.behavior = behavior; + } + + public void action() { + System.out.println("Player: " + this.type); + this.behavior.actionCommand(); + } +} diff --git a/AlexSubbotin/lesson_26/src/main/java/strategy/Strategy.java b/AlexSubbotin/lesson_26/src/main/java/strategy/Strategy.java new file mode 100644 index 0000000..811deeb --- /dev/null +++ b/AlexSubbotin/lesson_26/src/main/java/strategy/Strategy.java @@ -0,0 +1,6 @@ +package strategy; + +public interface Strategy { + + void actionCommand(); +}