From 8794cffdfef25ffc1179793071ba7b8954bd8c10 Mon Sep 17 00:00:00 2001 From: Elena Date: Thu, 2 Feb 2023 19:14:26 +0300 Subject: [PATCH 1/7] update ignore file and 1 file with OOP --- .gitignore | 1 - OOP/Children.class | Bin 0 -> 1321 bytes OOP/Family.class | Bin 0 -> 1414 bytes OOP/Father.class | Bin 0 -> 1002 bytes OOP/Human.class | Bin 0 -> 2289 bytes OOP/Mother.class | Bin 0 -> 1571 bytes 6 files changed, 1 deletion(-) create mode 100644 OOP/Children.class create mode 100644 OOP/Family.class create mode 100644 OOP/Father.class create mode 100644 OOP/Human.class create mode 100644 OOP/Mother.class diff --git a/.gitignore b/.gitignore index a1c2a23..3004d02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Compiled class file -*.class # Log file *.log diff --git a/OOP/Children.class b/OOP/Children.class new file mode 100644 index 0000000000000000000000000000000000000000..abb094b09ef4444ee8c415734357d0d022f13d2e GIT binary patch literal 1321 zcmZuxOHUI~6#g!KOgoII6;NJ+?{?Hy1)t@msF9>735NYh$9ANhA!Taf&UaiGAK9t469|*tyh%Te9q2Ix!hV1W^U5hDK-tnv5OETZL@N zv;~wIgKu|MAhtSKhBj$fFXMu?Q8ZO-L`=aZ4b5l~Xj)D;X1IBBDH(RwDGCJQiPPcX z?PSki6m4i%(4nCdT>=}Hqb9D+x~6n@%C105je+H)#>w4f1*TCHPO$q0G{ zI{pXy;Z>^F8CLNY1x~ENbB%VcRSbJG;$%&M^%=`H&zFmr%+f{UQh}CO#+fn-lSavs z=ejZI<}LQSDYJ4C(qwAn7$QcgM9#FcQia6LG|Cu8-x8l$oPpqcQ0iJNmr782QB}uC1%0qF_>OEqekFf<$(2l3*#xwGMjuc+d?FFMV|IeXsE=XuX_^6HQDd@#v80&RRJgL4g+a zLal{WNv+YxlDDA45ICe(R8>{HpVhLr$nF(YQA?_GxaOt?8aI}`hV7Ut5v#bv~)aXGMsAj~k;CShkz zn>r2&9Ps9eN2$i8$kbGoATH|oK)_H%Z;?*FQ21I9ZIBv1Br^|cVAf7g=d7%bFbDp@ ztkg@Y|3b%cf#zBtV!S~`pX)dwuwVT~F~zW253Ap4qVsBOZz{~ zrZcIdliU8PHr2Yf;1{R1X9SM;ZL8F3U9JARxsGnSwcg#gw!x6v5H)ZX=LGiUEqB_b4ynDT!N%EVy8OmyXkDFfVJ^xMa6lGOY z(Z-Cg?`?Zc?PPCCZAp`6-t6PpzPR1aUZRHW@lD_tW{HJY2?+kqVAZ%8rmBkI9e9I63N{BOys=>V2|5&?UP{=;@NZ zCG>TdaPdqD{Y89U!T{Nacd+$f5A}Qui9c}yf1wXgFo>sw=oukf!q-^FB#O9;6{N80 ubLgw##8*gAuB3f};soViMH1i8Q2OX;d`o%tRI3Bu(N}={cPP3J-@gU~p{)i0 literal 0 HcmV?d00001 diff --git a/OOP/Father.class b/OOP/Father.class new file mode 100644 index 0000000000000000000000000000000000000000..db23c76f24c1cc92b54a8fb61b10f07ac2dfb157 GIT binary patch literal 1002 zcma))eQVQD6vm(1rs&twljW7KGlY$n<24S6aR6#-R+So?Y1k!Xc@Ixu+ z1pn{@_@Tt--j+?479=G1+>>*D=iKMq-+zAo0?@)E3pwPAFl-cH3Y0pX!{**}EF%H) zc@PC@OQ2rg_ddxJ*$ibgYgjq!W(gr#04u|iB=ZcLAt_rO5&!LqpQ$=pt*iw<# zM@w)5-v6C2%g=fmJprQ~4|vFRFNpku>G;@Bj^uGjPsNM-GVIADQ2V*lNJqg$!1gZW z+7ZahArr(te|(hVAUy4+GMzGRZFY?ICdkxf;)@K+nxjJs`N!9oP;XXY>(XAHFu=`tqXx@Pr~&MG zCoSD8V7iaLW8y6C_gM!(fHxAfjTuW4#N6<6195zD#EdPmm#B`npKV%^2PIjgDn o)Xn{djW29vCW%Qm@Ihl#StaaD27&tvlby@S{e{U7bcu(50jd(Xp#T5? literal 0 HcmV?d00001 diff --git a/OOP/Human.class b/OOP/Human.class new file mode 100644 index 0000000000000000000000000000000000000000..363c1f28290bb9e796f9850f36ec21f2f0de43d9 GIT binary patch literal 2289 zcmZ`)T~ixn6n-}3qe+(pLZB^(rnP7i0@2!53lybTN|X|uI5><~3v83^gv3cUIK9)3 zKfyoXl{a2g#sF5S_q|&FP{-%&Zu7a!z`pOEJ6{X)(&Y~EgO~nx?Yt} z<0>ZPQ?R60_w{;&rmGU_H3g|uevod^;>0|q;vL}$@6{@``nqP=RPU;I4@sNdT#@K` z#Jp(SQ1L!)Du|VIbFJqHiBx(}Lm(fh_)s9Dgsk_SBaKW5vnsNf>q&9(S;N#1C|heX z(c=!WQOj*HH6|0JYX^&$kW-*rzgsQqAM2HM#Pwy;I^rMSPR@U_UY!4Y{@iLUBxm-M zbZMPGpHEu9(d}RU|81Sot(CO?<0AND8qcg#+rL4_Uj<;D65W`O;A7kh;S&|Nafc`A z6f0jf^^#s!5IWQaYN zpWZecrKPvaC`4PA&`6_P`>_`lY`7QEw^vpWDb||xJ$=oPj798QJTK)!lI`r{cnI*x zYtEfdZlS&MTH7lxtiAG9agFkymlCWfcNO~kxh66vP%=|3gfiI{hBI?5jQ&Zx5BK?; zAOhs~Qz49Dazr@>VjN09#=+xre8D#|*>NcLP9l)#5;8O}#9aU@uJR7Qh$Yseoal(g zZQ@Zr;}jjEWWp9qISa=7l0>+S_ya&x3`d2g=a{QcV;Z9~i zHgk;WB|fe{=3{2_2&wpd@C?44p{Y}RRNV1ri#vh2;xX=i*U5x48y-?|4G~r$#u#Ur k!Om>Ry44EsS65~fCm3$vG2`&jdm5YE4bfU)3_fiA4{7L<^Z)<= literal 0 HcmV?d00001 diff --git a/OOP/Mother.class b/OOP/Mother.class new file mode 100644 index 0000000000000000000000000000000000000000..65b19df3d4162f68a96cf72c564e80f214f0f96c GIT binary patch literal 1571 zcma)6T~8B16g>lNm)3<=6cj(8Dkv1Set%FzrO`lAgam^RJ`L^I4s3VG?vzNP59+Hw zz@MQ;#rUA_K9xUYytCW1#WseA-MMr3-gC~qcV>V8`SBCL9Oe_~L9c~~jVNLa@#W=} z>_V-|U541KbfunSn3-HGZ18QKb+}v3u4+%Z<=jC$Q)_YbA#NdI;}C3ygn?gDx*|N{ z5~W&^YpIB9uoKQG8!)nx48z?N81%y!v~a}6Q4BGp+C=X7T2vW&RZTMth3HacS4g|2 z3Iwm_2B`zbY#hf3!?7yg6nW*6o@Y{5$nrIJwa;*VvQyerrz?SzIA!6qjZus-90{cC zCuFd;482434s}CaV<>bhw3F>1o+*Nhq!+?n$$6 zI3v0usbag(no^Eh$jg+#7U{zaUX{+ys^+>zaRU{;O(!8=kxt1IR8+jE9OW%=NyCkm zgCp zb??pI+r9T`THe)vQHK{@S9p1c`@Zlk(1o4osJL4p79KE+{y&rk8CH!n-Q*s+F^t}H zm&u9-PntYu$kOHqLTf5>^5UhD$SzoBB>ENBC-U{+EWHQNOK*udHju<7&e3iz%)vM& zXh+#Nj|+rotVv=qj44c!WpY!PuhfSsdklOM}W?<*%nHD%WV)Zs9yi5d&qL^lVQaJhk%rPUM{&3u9N zk&Li2vB3E1nS2X`bPH|R|Dc} XxK3*yd2Y}%gIU@o$hwF7c!-g|A>?VD literal 0 HcmV?d00001 From 7b06cc5ef531d86cd0bf36c31583a5baf8dc67a0 Mon Sep 17 00:00:00 2001 From: Elena Date: Thu, 2 Feb 2023 20:44:45 +0300 Subject: [PATCH 2/7] added true oop dz --- Human.java | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 Human.java diff --git a/Human.java b/Human.java new file mode 100644 index 0000000..b5ac5ed --- /dev/null +++ b/Human.java @@ -0,0 +1,125 @@ +package Family; + +class Human{ + private int age; + private String gender; + private String familyStatus; + private String havingChildren; + private String colorHair; + + Human(int age, String familyStatus, String havingChildren) { + this.age = age; + this.familyStatus = familyStatus; + this.havingChildren = havingChildren; + } + + Human(int age, String gender) { + this.age = age; + this.gender = gender; + } + + Human(int age, String familyStatus, String havingChildren, String colorHair) { + this(age,familyStatus, havingChildren); + this.colorHair = colorHair; + + } + + public int getAge() {return age;} + public String getGender() {return gender;} + public String getFamilyStatus() {return familyStatus;} + public String getHavingChildren() {return havingChildren;} + public String getColorHair() {return colorHair;} + public void setAge(int age) {this.age = age;} + public void setGender(String gender) {this.gender = gender;} + public void setFamilyStatus(String familyStatus) {this.familyStatus = familyStatus;} + public void setHavingChildren(String havingChildren) {this.havingChildren = havingChildren;} + public void setColorHair(String colorHair) {this.colorHair = colorHair;} + void showFamilyStatus() { + int age = getAge(); + String status = getFamilyStatus(); + String ch = getHavingChildren(); + System.out.printf("Человек в возрасте: %d лет. Семейное положение: %s. Дети: %s", age, status, ch); + } +} + +class Father extends Human { + Father(int age, String familyStatus, String colorEye, String havingChildren, String havingBrothersAndSisters) { + super(age, familyStatus, havingChildren); + setColorEye(colorEye); + setHavingBrothersAndSisters(havingBrothersAndSisters); + } + private String colorEye; + private String havingBrothersAndSisters; + + public void setColorEye(String colorEye) {this.colorEye = colorEye;} + public void setHavingBrothersAndSisters(String havingBrothersAndSisters) {this.havingBrothersAndSisters = havingBrothersAndSisters;} + + public String getColorEye() {return colorEye;} + public String getHavingBrothersAndSisters() {return havingBrothersAndSisters;} +} + +class Mother extends Human { + Mother(int age, String familyStatus, String havingChildren, String colorHair, String education){ + super(age, familyStatus, havingChildren, colorHair); + this.education = education; + } + Mother(int age, String gender) { + super(age, gender); + } + private String education; + + public void setEducation(String education) {this.education = education;} + public String getEducation() {return education;} + + void voice(String name) { + System.out.println(name + " иди есть суп"); + } + +} + +class Children extends Mother { + Children(String name, int age, String gender, String parents) { + super(age, gender); + this.parents = parents; + this.name = name; + } + private String parents; + private String name; + int hunger() { + return (int)(Math.random() * 9); + } + void goEat() { + System.out.println("Ест..."); + int food = (int)(Math.random() * 3); + int hunger = hunger() - food; + int trueLevelFood = 5; + if (hunger == trueLevelFood) + System.out.println("Ребенок больше не голоден"); + else if (hunger < trueLevelFood) { + goEat(); + } + else { + System.out.println("Ребенок переел"); + } + } + public void setParents(String parents) {this.parents = parents;} + public String getParents() {return parents;} + +} + + +class Family { + public static void main(String[] args) { + Father father = new Father(45, "не женат", "голубые глаза", "1 ребенок", "нет сестер"); + Mother mother = new Mother(34, "не замужем", "1 ребенок", "рыжые волосы", "высшее"); + Children children1 = new Children("Степан", 12, "мужской", "Лев и Марина"); + Children children2 = new Children("Дмитрий", 18, "мужской", "Леонид и Марина"); + + mother.setHavingChildren("2 ребенка"); + + mother.voice("Степан,"); + children1.goEat(); + father.showFamilyStatus(); + } + +} \ No newline at end of file From 32f906735c64443b2ed2ef02c9046ee844f8028d Mon Sep 17 00:00:00 2001 From: Elena Date: Thu, 2 Feb 2023 20:48:11 +0300 Subject: [PATCH 3/7] delete useless files --- OOP/Children.class | Bin 1321 -> 0 bytes OOP/Family.class | Bin 1414 -> 0 bytes OOP/Father.class | Bin 1002 -> 0 bytes OOP/Human.class | Bin 2289 -> 0 bytes OOP/Mother.class | Bin 1571 -> 0 bytes 5 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 OOP/Children.class delete mode 100644 OOP/Family.class delete mode 100644 OOP/Father.class delete mode 100644 OOP/Human.class delete mode 100644 OOP/Mother.class diff --git a/OOP/Children.class b/OOP/Children.class deleted file mode 100644 index abb094b09ef4444ee8c415734357d0d022f13d2e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1321 zcmZuxOHUI~6#g!KOgoII6;NJ+?{?Hy1)t@msF9>735NYh$9ANhA!Taf&UaiGAK9t469|*tyh%Te9q2Ix!hV1W^U5hDK-tnv5OETZL@N zv;~wIgKu|MAhtSKhBj$fFXMu?Q8ZO-L`=aZ4b5l~Xj)D;X1IBBDH(RwDGCJQiPPcX z?PSki6m4i%(4nCdT>=}Hqb9D+x~6n@%C105je+H)#>w4f1*TCHPO$q0G{ zI{pXy;Z>^F8CLNY1x~ENbB%VcRSbJG;$%&M^%=`H&zFmr%+f{UQh}CO#+fn-lSavs z=ejZI<}LQSDYJ4C(qwAn7$QcgM9#FcQia6LG|Cu8-x8l$oPpqcQ0iJNmr782QB}uC1%0qF_>OEqekFf<$(2l3*#xwGMjuc+d?FFMV|IeXsE=XuX_^6HQDd@#v80&RRJgL4g+a zLal{WNv+YxlDDA45ICe(R8>{HpVhLr$nF(YQA?_GxaOt?8aI}`hV7Ut5v#bv~)aXGMsAj~k;CShkz zn>r2&9Ps9eN2$i8$kbGoATH|oK)_H%Z;?*FQ21I9ZIBv1Br^|cVAf7g=d7%bFbDp@ ztkg@Y|3b%cf#zBtV!S~`pX)dwuwVT~F~zW253Ap4qVsBOZz{~ zrZcIdliU8PHr2Yf;1{R1X9SM;ZL8F3U9JARxsGnSwcg#gw!x6v5H)ZX=LGiUEqB_b4ynDT!N%EVy8OmyXkDFfVJ^xMa6lGOY z(Z-Cg?`?Zc?PPCCZAp`6-t6PpzPR1aUZRHW@lD_tW{HJY2?+kqVAZ%8rmBkI9e9I63N{BOys=>V2|5&?UP{=;@NZ zCG>TdaPdqD{Y89U!T{Nacd+$f5A}Qui9c}yf1wXgFo>sw=oukf!q-^FB#O9;6{N80 ubLgw##8*gAuB3f};soViMH1i8Q2OX;d`o%tRI3Bu(N}={cPP3J-@gU~p{)i0 diff --git a/OOP/Father.class b/OOP/Father.class deleted file mode 100644 index db23c76f24c1cc92b54a8fb61b10f07ac2dfb157..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1002 zcma))eQVQD6vm(1rs&twljW7KGlY$n<24S6aR6#-R+So?Y1k!Xc@Ixu+ z1pn{@_@Tt--j+?479=G1+>>*D=iKMq-+zAo0?@)E3pwPAFl-cH3Y0pX!{**}EF%H) zc@PC@OQ2rg_ddxJ*$ibgYgjq!W(gr#04u|iB=ZcLAt_rO5&!LqpQ$=pt*iw<# zM@w)5-v6C2%g=fmJprQ~4|vFRFNpku>G;@Bj^uGjPsNM-GVIADQ2V*lNJqg$!1gZW z+7ZahArr(te|(hVAUy4+GMzGRZFY?ICdkxf;)@K+nxjJs`N!9oP;XXY>(XAHFu=`tqXx@Pr~&MG zCoSD8V7iaLW8y6C_gM!(fHxAfjTuW4#N6<6195zD#EdPmm#B`npKV%^2PIjgDn o)Xn{djW29vCW%Qm@Ihl#StaaD27&tvlby@S{e{U7bcu(50jd(Xp#T5? diff --git a/OOP/Human.class b/OOP/Human.class deleted file mode 100644 index 363c1f28290bb9e796f9850f36ec21f2f0de43d9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2289 zcmZ`)T~ixn6n-}3qe+(pLZB^(rnP7i0@2!53lybTN|X|uI5><~3v83^gv3cUIK9)3 zKfyoXl{a2g#sF5S_q|&FP{-%&Zu7a!z`pOEJ6{X)(&Y~EgO~nx?Yt} z<0>ZPQ?R60_w{;&rmGU_H3g|uevod^;>0|q;vL}$@6{@``nqP=RPU;I4@sNdT#@K` z#Jp(SQ1L!)Du|VIbFJqHiBx(}Lm(fh_)s9Dgsk_SBaKW5vnsNf>q&9(S;N#1C|heX z(c=!WQOj*HH6|0JYX^&$kW-*rzgsQqAM2HM#Pwy;I^rMSPR@U_UY!4Y{@iLUBxm-M zbZMPGpHEu9(d}RU|81Sot(CO?<0AND8qcg#+rL4_Uj<;D65W`O;A7kh;S&|Nafc`A z6f0jf^^#s!5IWQaYN zpWZecrKPvaC`4PA&`6_P`>_`lY`7QEw^vpWDb||xJ$=oPj798QJTK)!lI`r{cnI*x zYtEfdZlS&MTH7lxtiAG9agFkymlCWfcNO~kxh66vP%=|3gfiI{hBI?5jQ&Zx5BK?; zAOhs~Qz49Dazr@>VjN09#=+xre8D#|*>NcLP9l)#5;8O}#9aU@uJR7Qh$Yseoal(g zZQ@Zr;}jjEWWp9qISa=7l0>+S_ya&x3`d2g=a{QcV;Z9~i zHgk;WB|fe{=3{2_2&wpd@C?44p{Y}RRNV1ri#vh2;xX=i*U5x48y-?|4G~r$#u#Ur k!Om>Ry44EsS65~fCm3$vG2`&jdm5YE4bfU)3_fiA4{7L<^Z)<= diff --git a/OOP/Mother.class b/OOP/Mother.class deleted file mode 100644 index 65b19df3d4162f68a96cf72c564e80f214f0f96c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1571 zcma)6T~8B16g>lNm)3<=6cj(8Dkv1Set%FzrO`lAgam^RJ`L^I4s3VG?vzNP59+Hw zz@MQ;#rUA_K9xUYytCW1#WseA-MMr3-gC~qcV>V8`SBCL9Oe_~L9c~~jVNLa@#W=} z>_V-|U541KbfunSn3-HGZ18QKb+}v3u4+%Z<=jC$Q)_YbA#NdI;}C3ygn?gDx*|N{ z5~W&^YpIB9uoKQG8!)nx48z?N81%y!v~a}6Q4BGp+C=X7T2vW&RZTMth3HacS4g|2 z3Iwm_2B`zbY#hf3!?7yg6nW*6o@Y{5$nrIJwa;*VvQyerrz?SzIA!6qjZus-90{cC zCuFd;482434s}CaV<>bhw3F>1o+*Nhq!+?n$$6 zI3v0usbag(no^Eh$jg+#7U{zaUX{+ys^+>zaRU{;O(!8=kxt1IR8+jE9OW%=NyCkm zgCp zb??pI+r9T`THe)vQHK{@S9p1c`@Zlk(1o4osJL4p79KE+{y&rk8CH!n-Q*s+F^t}H zm&u9-PntYu$kOHqLTf5>^5UhD$SzoBB>ENBC-U{+EWHQNOK*udHju<7&e3iz%)vM& zXh+#Nj|+rotVv=qj44c!WpY!PuhfSsdklOM}W?<*%nHD%WV)Zs9yi5d&qL^lVQaJhk%rPUM{&3u9N zk&Li2vB3E1nS2X`bPH|R|Dc} XxK3*yd2Y}%gIU@o$hwF7c!-g|A>?VD From 9a22ae1968479ef91d494e66e37c10879219ec2e Mon Sep 17 00:00:00 2001 From: Elena Date: Fri, 17 Feb 2023 14:46:22 +0300 Subject: [PATCH 4/7] work on calculator --- MyCulc/Console/View.java | 23 +++++++++++ MyCulc/Main/Program.java | 20 ++++++++++ MyCulc/Menu/Menu.java | 24 ++++++++++++ MyCulc/Model/CalcModel.java | 11 ++++++ MyCulc/Model/Div.java | 8 ++++ MyCulc/Model/ICalcModel.java | 7 ++++ MyCulc/Model/Mult.java | 8 ++++ MyCulc/Model/SumCalc.java | 14 +++++++ MyCulc/Presenterrr/PresentOf.java | 65 +++++++++++++++++++++++++++++++ MyCulc/Presenterrr/Presenter.java | 26 +++++++++++++ 10 files changed, 206 insertions(+) create mode 100644 MyCulc/Console/View.java create mode 100644 MyCulc/Main/Program.java create mode 100644 MyCulc/Menu/Menu.java create mode 100644 MyCulc/Model/CalcModel.java create mode 100644 MyCulc/Model/Div.java create mode 100644 MyCulc/Model/ICalcModel.java create mode 100644 MyCulc/Model/Mult.java create mode 100644 MyCulc/Model/SumCalc.java create mode 100644 MyCulc/Presenterrr/PresentOf.java create mode 100644 MyCulc/Presenterrr/Presenter.java diff --git a/MyCulc/Console/View.java b/MyCulc/Console/View.java new file mode 100644 index 0000000..3a73a73 --- /dev/null +++ b/MyCulc/Console/View.java @@ -0,0 +1,23 @@ +package MyCulc.Console; + +import java.util.Scanner; + +public class View { + Scanner sc = new Scanner(System.in); + + public double getValue(String data) { + System.out.println(data); + return sc.nextDouble(); + } + public void show(double value, String data) { System.out.printf("%s %s", data, value); } + + + public int getChoice() { + System.out.println("Choice operation:"); + System.out.println("\t1. Sum "); + System.out.println("\t2. Mult "); + System.out.println("\t3. Div "); + return sc.nextInt(); + } + +} diff --git a/MyCulc/Main/Program.java b/MyCulc/Main/Program.java new file mode 100644 index 0000000..0882e36 --- /dev/null +++ b/MyCulc/Main/Program.java @@ -0,0 +1,20 @@ +package MyCulc.Main; + + +import MyCulc.Console.View; +import MyCulc.Model.Div; +import MyCulc.Model.Mult; +import MyCulc.Model.SumCalc; +import MyCulc.Presenterrr.PresentOf; + +public class Program { + + public static void main(String[] args) { + + PresentOf ps = new PresentOf<>(new SumCalc(),new View()); + ps.buttonClick(); + + } +} + + diff --git a/MyCulc/Menu/Menu.java b/MyCulc/Menu/Menu.java new file mode 100644 index 0000000..389bcef --- /dev/null +++ b/MyCulc/Menu/Menu.java @@ -0,0 +1,24 @@ +package MyCulc.Menu; + +import MyCulc.Console.View; +import MyCulc.Model.CalcModel; +import MyCulc.Presenterrr.Presenter; + +import java.util.Scanner; + +public class Menu { + Presenter presenter; + View view; + CalcModel calcModel; + + public Menu() { + presenter = new Presenter(calcModel, view); + } + + Scanner sc = new Scanner(System.in); + + public int val = sc.nextInt(); + + } + + diff --git a/MyCulc/Model/CalcModel.java b/MyCulc/Model/CalcModel.java new file mode 100644 index 0000000..e9cda79 --- /dev/null +++ b/MyCulc/Model/CalcModel.java @@ -0,0 +1,11 @@ +package MyCulc.Model; + +public abstract class CalcModel implements ICalcModel { + + public double x; + public double y; + + + +} + diff --git a/MyCulc/Model/Div.java b/MyCulc/Model/Div.java new file mode 100644 index 0000000..55237a3 --- /dev/null +++ b/MyCulc/Model/Div.java @@ -0,0 +1,8 @@ +package MyCulc.Model; + +public class Div extends SumCalc{ + @Override + public double result() { + return x / y; + } +} diff --git a/MyCulc/Model/ICalcModel.java b/MyCulc/Model/ICalcModel.java new file mode 100644 index 0000000..d79dc5a --- /dev/null +++ b/MyCulc/Model/ICalcModel.java @@ -0,0 +1,7 @@ +package MyCulc.Model; + +public interface ICalcModel { + double result(); + void setX(double value); + void setY(double value); +} diff --git a/MyCulc/Model/Mult.java b/MyCulc/Model/Mult.java new file mode 100644 index 0000000..32310a4 --- /dev/null +++ b/MyCulc/Model/Mult.java @@ -0,0 +1,8 @@ +package MyCulc.Model; + +public class Mult extends SumCalc { + @Override + public double result() { + return x * y; + } +} diff --git a/MyCulc/Model/SumCalc.java b/MyCulc/Model/SumCalc.java new file mode 100644 index 0000000..283da3e --- /dev/null +++ b/MyCulc/Model/SumCalc.java @@ -0,0 +1,14 @@ +package MyCulc.Model; + +public class SumCalc extends CalcModel { + + public double result() { + return x + y; + } + public void setX(double value) { + super.x = value; + } + public void setY(double value) { + super.y = value; + } +} diff --git a/MyCulc/Presenterrr/PresentOf.java b/MyCulc/Presenterrr/PresentOf.java new file mode 100644 index 0000000..4ae14f1 --- /dev/null +++ b/MyCulc/Presenterrr/PresentOf.java @@ -0,0 +1,65 @@ +package MyCulc.Presenterrr; + +import MyCulc.Console.View; +import MyCulc.Model.*; + +public class PresentOf { + View view; + CalcModel model; + SumCalc sumCalc; + Mult mult; + Div div;; + + public PresentOf(T m , View view) { + this.model = m; + this.view = view; + } + + + public void runOperation1() { + double a = view.getValue("a: "); + double b = view.getValue("b: "); + model.setX(a); + model.setY(b); + double res = sumCalc.result(); + view.show(res, "Sum: "); + } + + public void runOperation2() { + double a = view.getValue("a: "); + double b = view.getValue("b: "); + model.setX(a); + model.setY(b); + double res = mult.result(); + view.show(res, "Mult: "); + } + + public void runOperation3() { + double a = view.getValue("a: "); + double b = view.getValue("b: "); + model.setX(a); + model.setY(b); + double res = div.result(); + view.show(res, "Div: "); + } + + public void buttonClick() { + int choice = view.getChoice(); + switch (choice) { + case 1 -> runOperation1(); + case 2 -> runOperation2(); + case 3 -> runOperation3(); + } + } + +} + +//class Class{ +// +// PresentOf ps = new PresentOf<>(new SumCalc(), new View()); +// PresentOf pm = new PresentOf<>(new Mult(), new View()); +// PresentOf
pd = new PresentOf<>(new Div(), new View()); +// +//} +// + diff --git a/MyCulc/Presenterrr/Presenter.java b/MyCulc/Presenterrr/Presenter.java new file mode 100644 index 0000000..489c44a --- /dev/null +++ b/MyCulc/Presenterrr/Presenter.java @@ -0,0 +1,26 @@ +package MyCulc.Presenterrr; + +import MyCulc.Console.View; +import MyCulc.Model.CalcModel; +import MyCulc.Model.Div; +import MyCulc.Model.Mult; + +public class Presenter { + View view; + CalcModel model; + Mult mult; + Div dv; + + public Presenter(CalcModel m, View v) { + this.model = m; + this.view = v; + } + public void buttonClick() { + double x = view.getValue("Введите x: "); + double y = view.getValue("Введите y: "); + model.setX(x); + model.setY(y); + double res = model.result(); + view.show(res, "Sum = "); + } +} From aa7a7d1d8e17ff69675822f0f30cce90e75ba89e Mon Sep 17 00:00:00 2001 From: Elena Date: Fri, 17 Feb 2023 15:05:17 +0300 Subject: [PATCH 5/7] delete random file --- Human.java | 125 ----------------------------------------------------- 1 file changed, 125 deletions(-) delete mode 100644 Human.java diff --git a/Human.java b/Human.java deleted file mode 100644 index b5ac5ed..0000000 --- a/Human.java +++ /dev/null @@ -1,125 +0,0 @@ -package Family; - -class Human{ - private int age; - private String gender; - private String familyStatus; - private String havingChildren; - private String colorHair; - - Human(int age, String familyStatus, String havingChildren) { - this.age = age; - this.familyStatus = familyStatus; - this.havingChildren = havingChildren; - } - - Human(int age, String gender) { - this.age = age; - this.gender = gender; - } - - Human(int age, String familyStatus, String havingChildren, String colorHair) { - this(age,familyStatus, havingChildren); - this.colorHair = colorHair; - - } - - public int getAge() {return age;} - public String getGender() {return gender;} - public String getFamilyStatus() {return familyStatus;} - public String getHavingChildren() {return havingChildren;} - public String getColorHair() {return colorHair;} - public void setAge(int age) {this.age = age;} - public void setGender(String gender) {this.gender = gender;} - public void setFamilyStatus(String familyStatus) {this.familyStatus = familyStatus;} - public void setHavingChildren(String havingChildren) {this.havingChildren = havingChildren;} - public void setColorHair(String colorHair) {this.colorHair = colorHair;} - void showFamilyStatus() { - int age = getAge(); - String status = getFamilyStatus(); - String ch = getHavingChildren(); - System.out.printf("Человек в возрасте: %d лет. Семейное положение: %s. Дети: %s", age, status, ch); - } -} - -class Father extends Human { - Father(int age, String familyStatus, String colorEye, String havingChildren, String havingBrothersAndSisters) { - super(age, familyStatus, havingChildren); - setColorEye(colorEye); - setHavingBrothersAndSisters(havingBrothersAndSisters); - } - private String colorEye; - private String havingBrothersAndSisters; - - public void setColorEye(String colorEye) {this.colorEye = colorEye;} - public void setHavingBrothersAndSisters(String havingBrothersAndSisters) {this.havingBrothersAndSisters = havingBrothersAndSisters;} - - public String getColorEye() {return colorEye;} - public String getHavingBrothersAndSisters() {return havingBrothersAndSisters;} -} - -class Mother extends Human { - Mother(int age, String familyStatus, String havingChildren, String colorHair, String education){ - super(age, familyStatus, havingChildren, colorHair); - this.education = education; - } - Mother(int age, String gender) { - super(age, gender); - } - private String education; - - public void setEducation(String education) {this.education = education;} - public String getEducation() {return education;} - - void voice(String name) { - System.out.println(name + " иди есть суп"); - } - -} - -class Children extends Mother { - Children(String name, int age, String gender, String parents) { - super(age, gender); - this.parents = parents; - this.name = name; - } - private String parents; - private String name; - int hunger() { - return (int)(Math.random() * 9); - } - void goEat() { - System.out.println("Ест..."); - int food = (int)(Math.random() * 3); - int hunger = hunger() - food; - int trueLevelFood = 5; - if (hunger == trueLevelFood) - System.out.println("Ребенок больше не голоден"); - else if (hunger < trueLevelFood) { - goEat(); - } - else { - System.out.println("Ребенок переел"); - } - } - public void setParents(String parents) {this.parents = parents;} - public String getParents() {return parents;} - -} - - -class Family { - public static void main(String[] args) { - Father father = new Father(45, "не женат", "голубые глаза", "1 ребенок", "нет сестер"); - Mother mother = new Mother(34, "не замужем", "1 ребенок", "рыжые волосы", "высшее"); - Children children1 = new Children("Степан", 12, "мужской", "Лев и Марина"); - Children children2 = new Children("Дмитрий", 18, "мужской", "Леонид и Марина"); - - mother.setHavingChildren("2 ребенка"); - - mother.voice("Степан,"); - children1.goEat(); - father.showFamilyStatus(); - } - -} \ No newline at end of file From 2305663dccad000b316cbb8b6a8922a8fa0c961b Mon Sep 17 00:00:00 2001 From: Elena Date: Mon, 20 Feb 2023 23:59:17 +0300 Subject: [PATCH 6/7] made some edits, added menu and logging --- Calculator/Choice.java | 17 +++++++ Calculator/IResult.java | 6 +++ Calculator/Logger/Log.java | 20 +++++++++ Calculator/Logger/log.txt | 1 + Calculator/MVP/Model.java | 25 +++++++++++ Calculator/MVP/Presenter.java | 15 +++++++ Calculator/MVP/View.java | 19 ++++++++ Calculator/OperationsInitialization/Div.java | 10 +++++ Calculator/OperationsInitialization/Mult.java | 11 +++++ Calculator/OperationsInitialization/Sum.java | 12 +++++ Calculator/OperationsRun/IRun.java | 7 +++ Calculator/OperationsRun/RunDiv.java | 42 +++++++++++++++++ Calculator/OperationsRun/RunMult.java | 45 +++++++++++++++++++ Calculator/OperationsRun/RunSum.java | 44 ++++++++++++++++++ Calculator/Program.java | 14 ++++++ 15 files changed, 288 insertions(+) create mode 100644 Calculator/Choice.java create mode 100644 Calculator/IResult.java create mode 100644 Calculator/Logger/Log.java create mode 100644 Calculator/Logger/log.txt create mode 100644 Calculator/MVP/Model.java create mode 100644 Calculator/MVP/Presenter.java create mode 100644 Calculator/MVP/View.java create mode 100644 Calculator/OperationsInitialization/Div.java create mode 100644 Calculator/OperationsInitialization/Mult.java create mode 100644 Calculator/OperationsInitialization/Sum.java create mode 100644 Calculator/OperationsRun/IRun.java create mode 100644 Calculator/OperationsRun/RunDiv.java create mode 100644 Calculator/OperationsRun/RunMult.java create mode 100644 Calculator/OperationsRun/RunSum.java create mode 100644 Calculator/Program.java diff --git a/Calculator/Choice.java b/Calculator/Choice.java new file mode 100644 index 0000000..0b8b3c5 --- /dev/null +++ b/Calculator/Choice.java @@ -0,0 +1,17 @@ +package Calculator; + +import java.util.Scanner; + +/**В классе происходит считывание варианта операции от пользователя.*/ +public class Choice { + + Scanner sc = new Scanner(System.in); + + public int getChoice() { + System.out.println("Choice operation:"); + System.out.println("\t1. Sum "); + System.out.println("\t2. Mult "); + System.out.println("\t3. Div "); + return sc.nextInt(); + } +} diff --git a/Calculator/IResult.java b/Calculator/IResult.java new file mode 100644 index 0000000..19febdd --- /dev/null +++ b/Calculator/IResult.java @@ -0,0 +1,6 @@ +package Calculator; + +/**В интерфейсе находится метод, принимающий в себя два аргумента, с котор будут производиться арифметические действия; метод возвращает результат. */ +public interface IResult { + double result(double x, double y); +} diff --git a/Calculator/Logger/Log.java b/Calculator/Logger/Log.java new file mode 100644 index 0000000..5765ad8 --- /dev/null +++ b/Calculator/Logger/Log.java @@ -0,0 +1,20 @@ +package Calculator.Logger; + +import java.io.FileWriter; +import java.io.IOException; + +public class Log { + public void logInfo(double x, double y, double result) { + try ( + FileWriter writer = new FileWriter("C:\\Users\\Operator\\IdeaProjects\\java_project\\src\\Calculator\\Logger\\log.txt", true)) + + + { + String text = String.format("", x, y, result); + writer.write(text); + writer.flush(); + } catch (IOException ex) { + System.out.println(ex.getMessage()); + } + } +} diff --git a/Calculator/Logger/log.txt b/Calculator/Logger/log.txt new file mode 100644 index 0000000..105acae --- /dev/null +++ b/Calculator/Logger/log.txt @@ -0,0 +1 @@ +54.0 + 6.0 = 60.0 diff --git a/Calculator/MVP/Model.java b/Calculator/MVP/Model.java new file mode 100644 index 0000000..09b581e --- /dev/null +++ b/Calculator/MVP/Model.java @@ -0,0 +1,25 @@ +package Calculator.MVP; + +import Calculator.Choice; +import Calculator.OperationsInitialization.Div; +import Calculator.OperationsInitialization.Mult; +import Calculator.OperationsInitialization.Sum; +import Calculator.OperationsRun.RunDiv; +import Calculator.OperationsRun.RunMult; +import Calculator.OperationsRun.RunSum; + +/**В классе производится основное действие калькулятора, выбирается пункт меню и далее от выбранной цифры воспроизводится нужная операция.*/ +public class Model { + Choice choice = new Choice(); + public void run() { + int getChoice = choice.getChoice(); + RunSum runSum = new RunSum(new View(), new Sum()); + RunMult runMult = new RunMult(new View(), new Mult()); + RunDiv runDiv = new RunDiv(new View(), new Div()); + switch (getChoice) { + case 1 -> runSum.runOperation(); + case 2 -> runMult.runOperation(); + case 3 -> runDiv.runOperation(); + } + } +} diff --git a/Calculator/MVP/Presenter.java b/Calculator/MVP/Presenter.java new file mode 100644 index 0000000..3604a8e --- /dev/null +++ b/Calculator/MVP/Presenter.java @@ -0,0 +1,15 @@ +package Calculator.MVP; + +/**Класс связывает Model и View */ +public class Presenter { + View view; + Model model; + + public Presenter(Model model, View view) { + this.model = model; + this.view = view; + } + public void buttonClick() { + model.run(); + } +} diff --git a/Calculator/MVP/View.java b/Calculator/MVP/View.java new file mode 100644 index 0000000..15c9548 --- /dev/null +++ b/Calculator/MVP/View.java @@ -0,0 +1,19 @@ +package Calculator.MVP; + +import java.util.Scanner; + +/**В классе происходит работа с интерфейсом, считываются и выводятся данные.*/ +public class View { + + Scanner sc = new Scanner(System.in); + + /**Метод позволяет считать данные, получить числа, с которыми можно работать в дальнейшем, складывать и т.д..*/ + public double getValue(String data) { + System.out.println(data); + return sc.nextDouble(); + } + + /**Метод выводит данные*/ + public void show(double value, String data) { System.out.printf("%s %s", data, value); } + +} diff --git a/Calculator/OperationsInitialization/Div.java b/Calculator/OperationsInitialization/Div.java new file mode 100644 index 0000000..c2639a6 --- /dev/null +++ b/Calculator/OperationsInitialization/Div.java @@ -0,0 +1,10 @@ +package Calculator.OperationsInitialization; + +import Calculator.IResult; + +public class Div implements IResult { + @Override + public double result(double x, double y) { + return x / y; + } +} diff --git a/Calculator/OperationsInitialization/Mult.java b/Calculator/OperationsInitialization/Mult.java new file mode 100644 index 0000000..e22df9d --- /dev/null +++ b/Calculator/OperationsInitialization/Mult.java @@ -0,0 +1,11 @@ +package Calculator.OperationsInitialization; + +import Calculator.IResult; + +public class Mult implements IResult { + + @Override + public double result(double x, double y) { + return x * y; + } +} diff --git a/Calculator/OperationsInitialization/Sum.java b/Calculator/OperationsInitialization/Sum.java new file mode 100644 index 0000000..7305dff --- /dev/null +++ b/Calculator/OperationsInitialization/Sum.java @@ -0,0 +1,12 @@ +package Calculator.OperationsInitialization; + +import Calculator.IResult; + +/**В классе находится метод, в котором происходит сложение двух чисел.*/ +public class Sum implements IResult { + + @Override + public double result(double x, double y) { + return x + y; + } +} diff --git a/Calculator/OperationsRun/IRun.java b/Calculator/OperationsRun/IRun.java new file mode 100644 index 0000000..13fefa3 --- /dev/null +++ b/Calculator/OperationsRun/IRun.java @@ -0,0 +1,7 @@ +package Calculator.OperationsRun; + +/**В интерфейсе находится метод, запускающий определенную операцию, в зависимости от выбранной цифры. */ +public interface IRun { + public void runOperation(); + +} diff --git a/Calculator/OperationsRun/RunDiv.java b/Calculator/OperationsRun/RunDiv.java new file mode 100644 index 0000000..d590348 --- /dev/null +++ b/Calculator/OperationsRun/RunDiv.java @@ -0,0 +1,42 @@ +package Calculator.OperationsRun; + +import Calculator.Logger.ILog; +import Calculator.Logger.Log; +import Calculator.OperationsInitialization.Div; +import Calculator.MVP.View; + +import java.io.FileWriter; +import java.io.IOException; + +/**В классе находится метод, запускающий операцию деления.*/ +public class RunDiv extends Log implements IRun { + View view; + Div div; + + public RunDiv(View view, Div div) { + this.view = view; + this.div = div; + } + @Override + public void runOperation() { + double x = view.getValue("Введите x: "); + double y = view.getValue("Введите y: "); + double res = div.result(x, y); + logInfo(x, y, res); + view.show(res, "Div = "); + } + + @Override + public void logInfo(double x, double y, double result) { + try(FileWriter writer = new FileWriter("C:\\Users\\Operator\\IdeaProjects\\java_project\\src\\Calculator\\Logger\\log.txt", true)) + { + String text = String.format("%s / %s = %s\n", x, y, result); + writer.write(text); + writer.flush(); + } + catch(IOException ex) { + System.out.println(ex.getMessage()); + } + } +} + diff --git a/Calculator/OperationsRun/RunMult.java b/Calculator/OperationsRun/RunMult.java new file mode 100644 index 0000000..13a704a --- /dev/null +++ b/Calculator/OperationsRun/RunMult.java @@ -0,0 +1,45 @@ +package Calculator.OperationsRun; + +import Calculator.Logger.Log; +import Calculator.OperationsInitialization.Mult; +import Calculator.MVP.View; + +import java.io.FileWriter; +import java.io.IOException; + +/** + * В классе находится метод, запускающий операцию умножения. + */ +public class RunMult extends Log implements IRun { + View view; + Mult mult; + + public RunMult(View view, Mult mult) { + this.view = view; + this.mult = mult; + } + + @Override + public void runOperation() { + double x = view.getValue("Введите x: "); + double y = view.getValue("Введите y: "); + double res = mult.result(x, y); + logInfo(x, y, res); + view.show(res, "Mult = "); + } + + @Override + public void logInfo(double x, double y, double result) { + { + try (FileWriter writer = new FileWriter("C:\\Users\\Operator\\IdeaProjects\\java_project\\src\\Calculator\\Logger\\log.txt", true)) { + String text = String.format("%s * %s = %s\n", x, y, result); + writer.write(text); + writer.flush(); + } catch (IOException ex) { + System.out.println(ex.getMessage()); + } + } + } +} + + diff --git a/Calculator/OperationsRun/RunSum.java b/Calculator/OperationsRun/RunSum.java new file mode 100644 index 0000000..7247428 --- /dev/null +++ b/Calculator/OperationsRun/RunSum.java @@ -0,0 +1,44 @@ +package Calculator.OperationsRun; + +import Calculator.Logger.Log; +import Calculator.OperationsInitialization.Sum; +import Calculator.MVP.View; + +import java.io.FileWriter; +import java.io.IOException; + +/** + * В классе реализован запуск выполнения сложения двух чисел. + */ +public class RunSum extends Log implements IRun { + View view; + Sum sum; + + public RunSum(View view, Sum sum) { + this.view = view; + this.sum = sum; + } + + @Override + public void runOperation() { + double x = view.getValue("Введите x: "); + double y = view.getValue("Введите y: "); + double res = sum.result(x, y); + logInfo(x, y, res); + view.show(res, "Sum = "); + } + + @Override + public void logInfo(double x, double y, double result) { + { + try (FileWriter writer = new FileWriter("C:\\Users\\Operator\\IdeaProjects\\java_project\\src\\Calculator\\Logger\\log.txt", true)) { + String text = String.format("%s + %s = %s\n", x, y, result); + writer.write(text); + writer.flush(); + } catch (IOException ex) { + System.out.println(ex.getMessage()); + } + } + } +} + diff --git a/Calculator/Program.java b/Calculator/Program.java new file mode 100644 index 0000000..7ad94c6 --- /dev/null +++ b/Calculator/Program.java @@ -0,0 +1,14 @@ +package Calculator; + +import Calculator.MVP.Model; +import Calculator.MVP.Presenter; +import Calculator.MVP.View; + +public class Program { + + public static void main(String[] args) { + + Presenter p = new Presenter(new Model(), new View()); + p.buttonClick(); + } +} From e90e0953f1f7c14bb8bc3a76619150836859a48c Mon Sep 17 00:00:00 2001 From: Elena Date: Wed, 22 Feb 2023 20:53:36 +0300 Subject: [PATCH 7/7] added oop python calculator for an experiment --- Calculator/GoProgram/Choice.py | 8 ++++++++ Calculator/GoProgram/Program.py | 19 +++++++++++++++++++ Calculator/MVP/Model.py | 17 +++++++++++++++++ Calculator/MVP/Presenter.py | 14 ++++++++++++++ Calculator/MVP/View.py | 9 +++++++++ Calculator/OperationsInitializations/Div.py | 6 ++++++ Calculator/OperationsInitializations/Mult.py | 6 ++++++ Calculator/OperationsInitializations/Sum.py | 6 ++++++ Calculator/OperationsRun/ResultOperation.py | 4 ++++ Calculator/OperationsRun/Run.py | 4 ++++ Calculator/OperationsRun/RunDiv.py | 14 ++++++++++++++ Calculator/OperationsRun/RunMult.py | 14 ++++++++++++++ Calculator/OperationsRun/RunSum.py | 15 +++++++++++++++ 13 files changed, 136 insertions(+) create mode 100644 Calculator/GoProgram/Choice.py create mode 100644 Calculator/GoProgram/Program.py create mode 100644 Calculator/MVP/Model.py create mode 100644 Calculator/MVP/Presenter.py create mode 100644 Calculator/MVP/View.py create mode 100644 Calculator/OperationsInitializations/Div.py create mode 100644 Calculator/OperationsInitializations/Mult.py create mode 100644 Calculator/OperationsInitializations/Sum.py create mode 100644 Calculator/OperationsRun/ResultOperation.py create mode 100644 Calculator/OperationsRun/Run.py create mode 100644 Calculator/OperationsRun/RunDiv.py create mode 100644 Calculator/OperationsRun/RunMult.py create mode 100644 Calculator/OperationsRun/RunSum.py diff --git a/Calculator/GoProgram/Choice.py b/Calculator/GoProgram/Choice.py new file mode 100644 index 0000000..18a62fb --- /dev/null +++ b/Calculator/GoProgram/Choice.py @@ -0,0 +1,8 @@ +class Choice: + + def get_choice(self): + print("1 Sum ") + print("2 Mult ") + print("3 Div ") + user_choice = input("Choice operation: ") + return user_choice diff --git a/Calculator/GoProgram/Program.py b/Calculator/GoProgram/Program.py new file mode 100644 index 0000000..8367948 --- /dev/null +++ b/Calculator/GoProgram/Program.py @@ -0,0 +1,19 @@ +from Calculator.MVP.Model import Model +from Calculator.MVP.Presenter import Presenter +from Calculator.MVP.View import View + + +def main(): + presenter = Presenter(Model(), View()) + presenter.button_click() + + +class Program: + + main() + + + + + + diff --git a/Calculator/MVP/Model.py b/Calculator/MVP/Model.py new file mode 100644 index 0000000..0d54ad3 --- /dev/null +++ b/Calculator/MVP/Model.py @@ -0,0 +1,17 @@ +from Calculator.GoProgram.Choice import Choice +from Calculator.OperationsRun.RunDiv import RunDiv +from Calculator.OperationsRun.RunMult import RunMult +from Calculator.OperationsRun.RunSum import RunSum + + +class Model: + + def run(self, choice_user=Choice()): + user_choice = choice_user.get_choice() + run_sum = RunSum() + run_mult = RunMult() + run_div = RunDiv() + match user_choice: + case "1": run_sum.run_operation() + case "2": run_mult.run_operation() + case "3": run_div.run_operation() diff --git a/Calculator/MVP/Presenter.py b/Calculator/MVP/Presenter.py new file mode 100644 index 0000000..fd5d363 --- /dev/null +++ b/Calculator/MVP/Presenter.py @@ -0,0 +1,14 @@ +from Calculator.MVP.Model import Model +from Calculator.MVP.View import View + + +class Presenter: + view = View() + model = Model() + + def __init__(self, model, view): + self.model = model + self.view = view + + def button_click(self): + self.model.run() diff --git a/Calculator/MVP/View.py b/Calculator/MVP/View.py new file mode 100644 index 0000000..eca4d47 --- /dev/null +++ b/Calculator/MVP/View.py @@ -0,0 +1,9 @@ +class View: + + def get_value(self, data): + print(data) + user_inp = int(input()) + return user_inp + + def show(self, value, data): + print(f"{data}{value}") diff --git a/Calculator/OperationsInitializations/Div.py b/Calculator/OperationsInitializations/Div.py new file mode 100644 index 0000000..209d6ee --- /dev/null +++ b/Calculator/OperationsInitializations/Div.py @@ -0,0 +1,6 @@ +from Calculator.OperationsRun.ResultOperation import ResultOperation + + +class Div(ResultOperation): + def result(self, x, y): + return x / y diff --git a/Calculator/OperationsInitializations/Mult.py b/Calculator/OperationsInitializations/Mult.py new file mode 100644 index 0000000..0c71b52 --- /dev/null +++ b/Calculator/OperationsInitializations/Mult.py @@ -0,0 +1,6 @@ +from Calculator.OperationsRun.ResultOperation import ResultOperation + + +class Mult(ResultOperation): + def result(self, x, y): + return x * y diff --git a/Calculator/OperationsInitializations/Sum.py b/Calculator/OperationsInitializations/Sum.py new file mode 100644 index 0000000..b38fa7f --- /dev/null +++ b/Calculator/OperationsInitializations/Sum.py @@ -0,0 +1,6 @@ +from Calculator.OperationsRun.ResultOperation import ResultOperation + + +class Sum(ResultOperation): + def result(self, x, y): + return x + y diff --git a/Calculator/OperationsRun/ResultOperation.py b/Calculator/OperationsRun/ResultOperation.py new file mode 100644 index 0000000..3d96d5b --- /dev/null +++ b/Calculator/OperationsRun/ResultOperation.py @@ -0,0 +1,4 @@ +class ResultOperation: + + def result(self, x, y): + pass diff --git a/Calculator/OperationsRun/Run.py b/Calculator/OperationsRun/Run.py new file mode 100644 index 0000000..e7c05eb --- /dev/null +++ b/Calculator/OperationsRun/Run.py @@ -0,0 +1,4 @@ +class Run: + + def run_operation(self): + pass diff --git a/Calculator/OperationsRun/RunDiv.py b/Calculator/OperationsRun/RunDiv.py new file mode 100644 index 0000000..eeccf14 --- /dev/null +++ b/Calculator/OperationsRun/RunDiv.py @@ -0,0 +1,14 @@ +from Calculator.OperationsInitializations.Div import Div +from Calculator.OperationsRun.Run import Run +from Calculator.MVP.View import View + + +class RunDiv(Run): + + def run_operation(self): + view = View() + div = Div() + x = view.get_value("Введите x: ") + y = view.get_value("Введите y: ") + res = div.result(x, y) + view.show(res, "Div : ") diff --git a/Calculator/OperationsRun/RunMult.py b/Calculator/OperationsRun/RunMult.py new file mode 100644 index 0000000..f141793 --- /dev/null +++ b/Calculator/OperationsRun/RunMult.py @@ -0,0 +1,14 @@ +from Calculator.OperationsInitializations.Mult import Mult +from Calculator.OperationsRun.Run import Run +from Calculator.MVP.View import View + + +class RunMult(Run): + + def run_operation(self): + view = View() + mult = Mult() + x = view.get_value("Введите x: ") + y = view.get_value("Введите y: ") + res = mult.result(x, y) + view.show(res, "Mult : ") diff --git a/Calculator/OperationsRun/RunSum.py b/Calculator/OperationsRun/RunSum.py new file mode 100644 index 0000000..2339ecc --- /dev/null +++ b/Calculator/OperationsRun/RunSum.py @@ -0,0 +1,15 @@ +from Calculator.OperationsRun.Run import Run +from Calculator.OperationsInitializations.Sum import Sum +from Calculator.MVP.View import View + + +class RunSum(Run): + + def run_operation(self): + view = View() + sum = Sum() + x = view.get_value("Введите x: ") + y = view.get_value("Введите y: ") + res = sum.result(x, y) + view.show(res, "Sum : ") +