From 2c3711779a95940ba42ab93b15124b6815b13334 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Thu, 12 Nov 2020 19:44:28 +0800 Subject: [PATCH 01/23] Cui Xinyu's first commit Three design patterns - FlyweightPattern,PrototypePattern,TemplatePattern --- AnimalGames/Java_test.iml | 11 ++ .../AniamlGames/Audience/Audience.class | Bin 0 -> 1300 bytes .../AniamlGames/Audience/AudienceCache.class | Bin 0 -> 1770 bytes .../AudienceAttribute/AttributeFactory.class | Bin 0 -> 2543 bytes .../DetailAudience/BirdAudience.class | Bin 0 -> 1291 bytes .../Audience/DetailAudience/CatAudience.class | Bin 0 -> 1286 bytes .../Audience/DetailAudience/DogAudience.class | Bin 0 -> 1286 bytes .../FourHundredMetersSwimming.class | Bin 0 -> 1309 bytes .../DetailGame/OneHundredMetersRunning.class | Bin 0 -> 1295 bytes .../DetailGame/OneThousandMetersRunning.class | Bin 0 -> 1302 bytes .../Java_test/AniamlGames/Games/Games.class | Bin 0 -> 458 bytes .../DesignPattern/FlyweightPattern.class | Bin 0 -> 4921 bytes .../DesignPattern/PrototypePattern.class | Bin 0 -> 3017 bytes .../DesignPattern/TemplatePattern.class | Bin 0 -> 1822 bytes .../src/AniamlGames/Audience/Audience.java | 49 ++++++++ .../AniamlGames/Audience/AudienceCache.java | 36 ++++++ .../AudienceAttribute/AttributeFactory.java | 57 +++++++++ .../Audience/DetailAudience/BirdAudience.java | 23 ++++ .../Audience/DetailAudience/CatAudience.java | 23 ++++ .../Audience/DetailAudience/DogAudience.java | 24 ++++ .../DetailGame/FourHundredMetersSwimming.java | 41 ++++++ .../DetailGame/OneHundredMetersRunning.java | 41 ++++++ .../DetailGame/OneThousandMetersRunning.java | 41 ++++++ AnimalGames/src/AniamlGames/Games/Games.java | 24 ++++ .../src/DesignPattern/FlyweightPattern.java | 118 ++++++++++++++++++ .../src/DesignPattern/PrototypePattern.java | 66 ++++++++++ .../src/DesignPattern/TemplatePattern.java | 48 +++++++ 27 files changed, 602 insertions(+) create mode 100644 AnimalGames/Java_test.iml create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Audience/Audience.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Audience/AudienceCache.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Audience/DetailAudience/AudienceAttribute/AttributeFactory.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Audience/DetailAudience/BirdAudience.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Audience/DetailAudience/CatAudience.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Audience/DetailAudience/DogAudience.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Games/DetailGame/FourHundredMetersSwimming.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Games/DetailGame/OneHundredMetersRunning.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Games/DetailGame/OneThousandMetersRunning.class create mode 100644 AnimalGames/out/production/Java_test/AniamlGames/Games/Games.class create mode 100644 AnimalGames/out/production/Java_test/DesignPattern/FlyweightPattern.class create mode 100644 AnimalGames/out/production/Java_test/DesignPattern/PrototypePattern.class create mode 100644 AnimalGames/out/production/Java_test/DesignPattern/TemplatePattern.class create mode 100644 AnimalGames/src/AniamlGames/Audience/Audience.java create mode 100644 AnimalGames/src/AniamlGames/Audience/AudienceCache.java create mode 100644 AnimalGames/src/AniamlGames/Audience/DetailAudience/AudienceAttribute/AttributeFactory.java create mode 100644 AnimalGames/src/AniamlGames/Audience/DetailAudience/BirdAudience.java create mode 100644 AnimalGames/src/AniamlGames/Audience/DetailAudience/CatAudience.java create mode 100644 AnimalGames/src/AniamlGames/Audience/DetailAudience/DogAudience.java create mode 100644 AnimalGames/src/AniamlGames/Games/DetailGame/FourHundredMetersSwimming.java create mode 100644 AnimalGames/src/AniamlGames/Games/DetailGame/OneHundredMetersRunning.java create mode 100644 AnimalGames/src/AniamlGames/Games/DetailGame/OneThousandMetersRunning.java create mode 100644 AnimalGames/src/AniamlGames/Games/Games.java create mode 100644 AnimalGames/src/DesignPattern/FlyweightPattern.java create mode 100644 AnimalGames/src/DesignPattern/PrototypePattern.java create mode 100644 AnimalGames/src/DesignPattern/TemplatePattern.java diff --git a/AnimalGames/Java_test.iml b/AnimalGames/Java_test.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/AnimalGames/Java_test.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/AnimalGames/out/production/Java_test/AniamlGames/Audience/Audience.class b/AnimalGames/out/production/Java_test/AniamlGames/Audience/Audience.class new file mode 100644 index 0000000000000000000000000000000000000000..ea721ab89a6b0b215bc923ff07765f9e66de60d7 GIT binary patch literal 1300 zcmaJ>T~E_s6n@^WtYZ|%$3VUmP#oJp<|ig%NC*)_GBk07`_eVDxV1~y8NBzuc&mwM z;)OrJAEiF0EieXn^Pcvc^FHS}&pGYyKR8J3?*3#3XJi4A@QIV_Lpg>OqSsZWx$W zSUNAVExE7#u-0w2{UCJeFOO}f9lE}k#S~^u%t@=cHmQWQ(6Zm}OF09#6~_BetivX& z>fy&WO{(J@3l+cV2Xt=xbvkoZm&LlRLnqjev&X8wZ8Z<9z?JvJsfX{}j>3HPzlv=r z3`Vrxk`PNZoN$*4UhF#2kl{`oo+$Qcl0-`foE+m@BCcNCJ$GG_}0Q5!ff(Gsv(zIMPE~}3D z#4aS3>l698GPDYdk4`VZVy| zm#}6}Fx-zdMXc#-utY1tT8k8srq=l;478R0j^=tWv@<>$M0de>aHTM#{V)qx3d7Ht z5JKP+ZHjhORXLn|^)oVitKTt0KEjND8Gfy)Xk0VVNS5d=&|hL?nd%hz11U#E7MM50 p4S9%1QBR`@YmFI`cuc$}EHn=7FRy9_G6vI>fhnD#ry>H@{{dmF*n0o~ literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/AniamlGames/Audience/AudienceCache.class b/AnimalGames/out/production/Java_test/AniamlGames/Audience/AudienceCache.class new file mode 100644 index 0000000000000000000000000000000000000000..eea17f11edf65fd542034266e5760b3b21d063eb GIT binary patch literal 1770 zcma)6X-^YT6g{s6TBajQS!Cae2xTb+RJ0X^vPuE92I9wIIw?bj8PZOTKT9+zi6q9) z{wU*l-3=8<)3@F^_ndq0yT5*a{{i3yQVKlq`p~4J87%@G=h`PNVrh0Ja&&rb=&nFZ z+_X)1O~5-nbKD9)T76Jd1fU8`tlOq`VeM!aMlQ0RPn(9V8`VWZ)6WcnPOW^gtL4sI z?bPB~PqOGJ@0wPmdK^>GhISu1RCFRJ(AB_(G%^NRO-+{&>ZrzMZXfy3Eiim1O9fr% zRq+sg0?oSR*reAz-4JU)Akq+P({MG@ss>=w$yC+~`r-9sSU^POdQ`<2#_1_%xO-^^ zqFzVJ&6;*5Hgha3Ln3tYR8749sPofmy8wEafnEJ1!07&E8X9 zLUU{K!cyJ>qxiTZ*ghCi-b<@TneoP1U{woTcef|bM-^)AQ&VVu3s!>-A!$nMAaId>j* z(I&3hJ~_sC65%X3H;1nwu8Jmcj`A94#Y>LzV;W!$uZm}{u}&cQ@jhqir0Xku;Q}7~ zL|1aQfF90Ycv;d)D-U;_!B2gq|1TXeC_o#eJdw|iB7SMc%&9NnP* z<245N!@;2fMoJDR=ydAj24UXJC1->41w?p53XA;9n<#IV59Wd^1w7@=TmjGcpE{{2 z4U-@hkVZF2_F#a`bpn0tQvF!LASDcu>M#y5QlvjdI)0LTL-nBLJd!vd?Km+GaYS)` gysgp?6~$8K4cbU$^&5QBwKT5;S>f&-cOJa|10$)uPXGV_ literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/AniamlGames/Audience/DetailAudience/AudienceAttribute/AttributeFactory.class b/AnimalGames/out/production/Java_test/AniamlGames/Audience/DetailAudience/AudienceAttribute/AttributeFactory.class new file mode 100644 index 0000000000000000000000000000000000000000..85fde4886eb1b881af874d1a824afa643f2059cb GIT binary patch literal 2543 zcmb7_|4ti65XZmEud|N}4nGspCYV4Hz{N*MY15dJf+-=bNz$4^Y5HqzZ{foE&bn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ID26jSd*UA&ln<^>~;(>275#L)lo(ScSK2= zNF(7kE}A;1Asb5RK>NJ$M(ABt4Uz-6pTGk=wD8EN`j}znylK)qQ2V0O?zYe+?r7y7 zF?Z+u0M2E`%G`K@_>`R-_h% z7*-e-wn))5eR(=8!+g4Eex|EzKD}NOW~+$9RYo(j>3PC0x;zL(U}246wo8Uy)mfm) zyZ&!en$fltq^}un^ND~)1_SiW(&;JPGTH}oKfrP+>lpDbbnHWpo#4x1swsnU@erBAB#jtpmUWq(RdXry~ z%6&tU)+DWKC%6H8$L;e7?ec~(L6q}6Cp+{A@rN9v6vzKVOShMm)*?3*tqR(fO2s=AFIZD0sh3!SAN(|ICuL!~)9g+Oyos-& z5l#5u1NczJGu;AcFnbU+j+&? z!Y{9No3?N*aq_|tTeV$VJ!OdG3!8Do8B$fQjvW(7B4xldaSme)<)N^bLUG$U4k?Gi z8KNGy1VgsI!}oaE;clzkP@e6!DjJIe!N9V*}Bd#YvPK|5%I--mL$rVxQ6QtQ*FL0s?xQ% z`e>_ddh-=`mCvx8AFOtL&{P;SB{7G212;|FLY`r~*TLC38H|pu+Ht9oA&Cl`BwAHA zss41`cE#IndrNp5e9P&{C@t=6a?jT1zA>t{ZK`^y{-49CFeG}VeCUlR*^ph&5;a>V z%7livsJkH33n`VaJl=UD)V6H;=@{-MaUTy1Jk**#VwgJ}neFb$UC|$QAajjdN_qzj zpTm9k9RuiV?lv9a&()>e?RF}I3WqFb0yhpiVu<^vkpH`_9bu_Tcx-({l{-$uR-zKe zGDB&D^vuzh=Rzu!a#j5sU16o%T1)7yA@)}ogSqay!mB#m_l0j@m0^BBg<;JZpi6h< z->!5$10_gaeXsQ=0=h4V(X&9OCuC)`r;0zoido|ji7#{+%t<0^f1tG(*r{22(^it#i6hkDyGH5!}HN?Qvq>rS+Kp?{r><3JLKHGk*Xa CJUJTx literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/AniamlGames/Audience/DetailAudience/DogAudience.class b/AnimalGames/out/production/Java_test/AniamlGames/Audience/DetailAudience/DogAudience.class new file mode 100644 index 0000000000000000000000000000000000000000..e471c357d3150db9d86a1159bb2ea7e97fc8a594 GIT binary patch literal 1286 zcmb7^>rN9v6vzKVq1($sp~y`ItAe(rQt=MO3zk$#>Lr%o2R{wlNmzjMz2?Ch`KCqDtK;za@jh!_|&F@z|??7D07rt^w7 zgHn(}P7QPSv96Jwe?WJyPQag5`Vfe90nm|_?Wg&g@xG^s|} zRtyszm@SL%iKK`pcr)P5n7E89HUQI@X7 z)kjat9*u)Y;U!jy{25RDS>$`7`SEPHnI%kK?fJ>WH4H~YR9EU`XtJ2lW1jG zr}|S>+ZAuy%^l%w@f|0SQCi&D=ANzhUE`qIwW;dm>VFQW#1Ick`4EgKQIl=Y5*1q~ z8VwC`Nq0e}mr^QUdA#*Ts9jn2Q&HSc-~k>Qc%(Ib%rJjGGTS|n`=UGSj?5KqDd`J5`El1h5X;`>kXlonmAl#4Cbcm3a{*N-xt1tHHL*A75X)2fDYZ< zzg_8gc9bA_^|{u+2mghjz!v; z9d{IPhjtp3?V>6arBfsV)Z#Hxf0L3#GKn)BkS06cT@uCVvrH_8rL*!X6rszT{)%+| z8&Y&l({=R(*MRT1d7h!u-WaBk4%Io`rAJUC$^hK0kB4NNvVh~Azk>~QIEH$OmC{^BceAVKvcGnjeF9$1j zyR_rkj$iRTC0pwz&Iv4Uw!7Zru2c6^eOvj;>r`IZt(NUHa#}ZMcXF<$T*-5dyoC{r z8b~EEhP1%g2~h+5LT~F4OiFtv- z8R_}-%I^a`O*%GUpiHnm-3)p zS4^{PJL+k-wWqvYx!0s8Rc_a0v&xd`dFYJ!`*ufQt^9v->lA9RA9jLXkov9#1jTYk zN_c}q;~$ZE2eZ6% z*z?ZOd%#2dbTGj**SIKfs(u=+Oy cg+CBv86Z!BSrX((Fh_#h($ literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/AniamlGames/Games/DetailGame/OneHundredMetersRunning.class b/AnimalGames/out/production/Java_test/AniamlGames/Games/DetailGame/OneHundredMetersRunning.class new file mode 100644 index 0000000000000000000000000000000000000000..09e1a6653f51dfb2ba307a3c3c90909d29004604 GIT binary patch literal 1295 zcmbW0T~8B16o%jF2fJO0K=~*jloo`vpsXK=9~cv(pqQd)N$;0-QdZk-v%58V=fCk9 zFVJ}55Ae#L;jb{hv)$Bc3np&U*_|_U&ikBmX1@LW@)f{c+%XVAR6{I@IEDn$4;6tyFz|cM0vHkl3(R`ttfR2O)BZ*-o1;$=kZ!EKJIW@EN&hur1yP9oZV5%6b z*iG}mwH?3YyV7cG>$o7W_S}(A+D_G#)qUwp*L&G^9NVd7m1@@ZvMpD(EPB;)2F5V1 zA(g}gCIu!2#1zn4N}=vhG~ZF}@c1gkcA*?+zI?Rr24*m;VJ?Y_nE!+Q@R)d2fw)(f zvLz79KP{9sWCSw56WntM>$Y3ItnR$6$d+$69Rmx1zEydB=vo!2V_9JJ z++;hM%4$x>ionXbdl}fJbS_LM`a?(IU-5U@Iq#TG8rB6i`&;}-`j#Cu-8@5_#dz4P zN~Tw|9r>)?IFjz6byTM%RcuzQdYP?K^UxUck8Mw2tN1@++mxyC6dVL6z)}?!5R}UH zGoE5`rdKaVWZS+yA`=>s|4oH$azCGolRZi6;V$NJQ^6{ zc$qVkZ^3tb?GwZaKO(roQ7zMm4UWn1+r(AQ1g>?R-*dMLy7&=VYUC87lbHI9^atq0 z_0x`ZiPjT3@v>l?=PMe7&p@M_&Ywa12v>%YqR=#F8H@(9(+r&=?RDG;02axr05pjqvq>8F^ZD|i`oOi_1+6w_2pbDSMWkRD91)lV>qUS-9T q59^>xo9Nb|Ly(~@N9!W1ktN9z36{GAMo$g?BG?OSaEoa~aQhd{EEI$Q literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/AniamlGames/Games/DetailGame/OneThousandMetersRunning.class b/AnimalGames/out/production/Java_test/AniamlGames/Games/DetailGame/OneThousandMetersRunning.class new file mode 100644 index 0000000000000000000000000000000000000000..6111505f9c9995be1f2fcbb97fdd9c1c740f216a GIT binary patch literal 1302 zcmbW0T~8B16o%jF2iq=-Kq(YZN(%;BQ0f<=VoZ#J!4yT?^nPe3?P|MicDF|F{5M|X z1sX5>0bcnt{1wJ`woL^E{Me>vXU@zy?{ntNe)<0CGk`m|Z6buQfry1Dh6Gag9b2}V zk7P@Eg(FsA=&tS9{yl+kE?u@~}{EHtH4FO=SRzG`t-yXy-~7K0VL zUD$JN$1nM=lC8}c&IznObyT_0?t0Rx?J8fn-t(^G*iJp8Wiz&y>A0#R8CK7l7{j=M zgoOzt1tv~NDqwW9MAM;at|!|A@^y;Md?m_)`50eKOk>8ttcCNqa16fOAYV-&>NS<> z2t;y^^A!VWf%MM`cO1gH-HxwnTd%9C<1~(g66t(Li>JsS~8VhU)>qJXtls4gL*; zo*9_arK}HV{60-8iHpBbEcGdLVetXQEN4KHHbw6wS+xE%?aY9{JVKBwg3PC literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/AniamlGames/Games/Games.class b/AnimalGames/out/production/Java_test/AniamlGames/Games/Games.class new file mode 100644 index 0000000000000000000000000000000000000000..4c6cb090b492b5e3772d5e769e1a382ee5e5e387 GIT binary patch literal 458 zcmZ`#%TB^T6g|^cDy0QlABa15%7X6Im>8mN8a2VNpOy&@>4TJF;%B+h#DyQ=M;Y%e zB(iZa=gyot_uR+#&*v9_a~wM`VA`-;?4Tjgoy!*)rZS&}5Aj?jl|bWC=eoKQFi+1W z4tCMB;kanAymy^znWc9!Q_FA*1v)e09!s^5rL1(3bE4;>%~?(U8&|TdnC-gonYEd{ z$)^I=sF*6Uh;***S6QseCmE;21W}R5bRtX5?+s~H&w44)kN)Z9f(#d_d=+rU#i~ry zt!6K$Zgh&Q?z*dyd`z{EbGyB6R8hkzw`Ep?

qw)K%15uxV$;#a)Em6RrsLA-{Fw)^NYo;1Q&&C}2(}7&>q2C4L@ERQUtr5kSO5S3 literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/DesignPattern/FlyweightPattern.class b/AnimalGames/out/production/Java_test/DesignPattern/FlyweightPattern.class new file mode 100644 index 0000000000000000000000000000000000000000..a90f170490379e176483e9a826323fa6f2d32c9f GIT binary patch literal 4921 zcma)AYjhjM75-*d(yrz8ONmWH0+CG;Y~x2_gGuC&*s){B;3Q6DoH*f;jl8iH%aS9l zk{H@j+O&|;(o%YOwxzUyd6p1blbTohZYh1x_v2@O_IFP?Er<4-T}hT@mlK^cJ9F>M z-22U)d+*HXoe$^V0uaXE{7|53@EGvICs29ZJZZMZ&BS=?-lNB@s4d{z8cW3NZ31e2 z!$=8qlxXl9D21_Tcw{DRTT>jB%y3fmpd%=jY#mC)5_ZH+S>{xyj&gwwLvhPYTOli9 zTd9yeVTDp=)Cwh!Ic+mD7PAsjtJaT7RA~qpSb>!SE0&QbpiN8Z@dOptyBZznR2NH( zcQ%aZs1ev$x2Z1Nn;h@XiVoGa)rEUZdx37R3-5@f#&QfDs|0EX64MzwRCh9FovI7j z$&hR~5TnVAgkG!Ta)E2I!^SMzjKvoZba|otl60&Q2xKShbH<*?#B2(>QUDr40#(j3 zGj=TA8i|^Tgq4yOuQPBJ)(I#vxzfC89Z6Z!`mq)p2|LRWC?B`%{bph;In|SlCsR6h33zwJ&FG|#8`(TC z5wk5FgVZ=`#p6lp*&|1!lBW_nhN!$hWzP7q9}x}125!cPKwozvW=_TX%_%G0nsb)c zUT5d?WUkR|(@aM*w$++%^_fvSnVKQGv}G4Kq(J*}-aELgx}5w@4F?5UmmO0CsX&#q z;~@iw<(3+G8+DIcejLE925!UcGzsC6MI+P?NT=z6Y2c`|`@)onby`jtGhpGEJB2Jp z_p&Ql$ST>;lyfHx#AMDXae{b1lYq4Mq=C3JwzN?}kZPdoU(#v|CiyXiTjgg=ekP>& zv;kX+ub}wCnAdQUnc`BcSvbp&j8u@33Nn}oFsI&W;A8l>z-3eBq}7v5L{0lZ%x0V< z(zcnf84SVt0r^`d<^mA7Gr)|@kBYmcq)*A zCUaNQw3}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=&@i7X8m$d{h+8zQmF)`oGd6sHYEqSzm1X}%{RgNa zQB_q{UQGN4hpzR$4^81p_#}37Gp=^B5M)li_X0l8?_2jw-rshPFhoI$H#vzUszH$_H$f!&c&EwDH8D(;mrRJd4!IOU&R3f{&=)=k{2?{maY jo$t?`?=PJ1FP-nNo$q_j_jmXMXZSh#kN7kGis1hMWnsyC literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/DesignPattern/PrototypePattern.class b/AnimalGames/out/production/Java_test/DesignPattern/PrototypePattern.class new file mode 100644 index 0000000000000000000000000000000000000000..ed6bada85d6bcadcf20f23892b156135cf08bad1 GIT binary patch literal 3017 zcmai0ZF3vd6@HE-d)KnSi5xqa#K~GDegT90(l|j%fJBLj!3hp_?GpOJwX~5pUhOK< z%EY`CN=hl^rL=U0d~65CGw_MbU>GygAJCb8>Yw3L+UKq$N5+o3GxzQ}cb|LCz2`jV z?)}%@&3^(&wb(C+#wAIj}`01q1IjAI}6Z*w-cRtfAP zefU+n?4Aji;rOZ9vf~AFLD^QtjEOG6z^rSlif!3mV3)06*|y3mXIuWYP*(LN^vBSR z9s>vCcnH0Mu3hX2jFPtQdUQBc^B8WN?i{a>8D21PNHCflOQz5Jg~slzrf1&_W*m>%IxsZ6GZrz7V$8sJ925B2_QZw3qJ?EuS+6L$W^qMuu&7q-tncMiu;>H~lUE6p7cdqByDsQn5!ShAVs6jfH}R1K`nh26{*h|t zYJUQPMZL;j=)6qtlKKP>h{XgVx{G4b#IFQLr@d9>I(f^{EFUS=N-`*~S*oBMuiwCL z1V_%>6{q0Ms(^I&Sjm3i2Wus}KEU+W=+dcqcez?zvdi;o$t8gjGk#9F3##mBy*?NX zmK_Gnn%UcIhIWfwgP>>V<()(xUJyJO@@A`Ext;&R0M=S1$3vuMuDKqyH&rfhU0u64 zBN^(|P6kg4VtK!it(89&l3`2fSmFV)r9~=1Sw~?94e0Hfs|vJsRq()EpmHmhR4ELQ z0hcx}+|1dfz#+d3ye2qy&q7w$%4I*8tCmWBIk59vP)?iktL2=sd|1?ogXd|ro zbG{#NVXAb=4wn6VrLzscjp1#)W8in1LGNz!=Xk6Bik+(Qw?_Rbl?(jxn&9(h($|4C zqZgHzckRlt8Q)*2mNGjd&@{4b;yj793%ofgjgw}liL7$nIVZ6Bhxxsr^P*k0EvHgH zSj5C1c#6*RPveCo)&H8t5tQcFKMD?Q|JrmGX~3U$0Gi5G13nTQ-fp3}M$;mQPwUe^ z>#9n{W@`T|IDRj++XAsYf(HJ=Lfjk5lerdd^yAkocKx*QSm1qt{VUW`eDj}#)OSn1a2WLtOJZF&0#BwxCNW8YyYZS)!&cr4x8+nP38Cfj?>4Wz!Nzqi<0 z*~aQ^obR)26Kq%N?FLS!zoe{s&BTcfoV<;x$YlFEo}r!z^~tE#N2#9)^?_EcThyNp z^`17Z@1uS;)Z2{7_U`ttX!Ad8`iZjjvrV(zV7txsZ@t+pHJ%XC0SMQG`bp56UO-DYbB2AJLk}9goNd%%{ivj>>x|qe8Y# z$h!zoWfiP){^RKUFSl$Mcvbiq1Oj(4Zy>4VPCoJE;Najy>yI#6aFbJ_bhbw0uTyTp l8+em%i-zCg_^q&iFYMnB`wznYLwrnBjEGP0DgKJy{{fSk@mT-> literal 0 HcmV?d00001 diff --git a/AnimalGames/out/production/Java_test/DesignPattern/TemplatePattern.class b/AnimalGames/out/production/Java_test/DesignPattern/TemplatePattern.class new file mode 100644 index 0000000000000000000000000000000000000000..296a7f31d8dae66ab4764c8c1cdde4d8583409e9 GIT binary patch literal 1822 zcmaJ>TW=dh6#mAybzCP-oU5DL#=T%SY24flb<&i!Y1$O$RtM9hr~$O96*@c=?dND#hRThLtEmCnq5Gv}N+bG|d@n}5Fi3P1`n z02kaEJVAKj6KH)RpUFf)TKUBC<`W}l3;1SC%d}?&+_8Ap55EAK5WpD?!62H^a>OXJ zQ?-pEbxSpxcBUP7W+|~!F)ce|R}5L4_M=rGx>7J?)zA&gHY&QkZRqw++0aXmo&UTn z8bbku(XOE*h)#3~w4dTjKr1WH1&fEp>Zduu^C;8GPpg1?1hUbwXlmIq?$)fWim|n5 z@XYG{nq^T(kB&QgYulw-Ra(b4C!(qOQmt~tGV_U9EYj4EvjX7-t6a17=xS8AOZwBA zX%A`W6KHe7t=VQFk;zHRGAb%-13?Tz7jT&>;{Vd)_-LdjfL=ru9p?mk8h2s_Usj1{ zmC}VEF5(RVzh!)Cr%lTc=!nHnCLw@0E@>DJVg#3uvgKrn9=2t5`&Ma-9!T&Qz<64dh3c^^*GptNzTw9dEyn$LlhcGBS2?X}m=>74VVSa6xI;p#iTXHa z*wS=X60hJSz{+$7FpKLN-VWl1s?6?_jvRLao^nC%Xt*UXbyDZ(VW*NDz)kf8<^__k zwSQ$D1aKQ}KNbWA7p!NpU~cKADvFVEy~gdzjxO`kv{)JM2=vbxRWom`NSkG7CDx20 zFJK!D%=^@t2q{XJYQ;^XvL-hRQPmvJ_bj2Q? zERlGY`|8mNMA9dd;3S$ZT-6-kVcq=Y%2wWGCC@P0PjSwos@fG5{{PLT@jhwyxFGYa zmJNaCj4g8?FUqoWGYt;}0vW!&oH1{z>vtT>)TnZYA>3mNQ=bb$H8GB9q6BBQDtIsL zLww%>V1cX<_VC4S4nK3~$;>HCa6mMQ9UQ~D|DtZB-<1EkjX zF|%}e57%}vdVrgRa}79nfZK$38nD$(l{4zHcX`R(!(Np=H&pgE(ZjKgD9lv1v;B9l zId}4`E)vm=bKFlLf+?KE*XYBy-1!~@_yIb8q{dH(;%A)4uegBU*uDNh41coC{DooR z!l>}lS}`-J+8-@4SmRjA;1L{sm1auP6Wj literal 0 HcmV?d00001 diff --git a/AnimalGames/src/AniamlGames/Audience/Audience.java b/AnimalGames/src/AniamlGames/Audience/Audience.java new file mode 100644 index 0000000..ad5c67d --- /dev/null +++ b/AnimalGames/src/AniamlGames/Audience/Audience.java @@ -0,0 +1,49 @@ +package AniamlGames.Audience; + +// @program: AnimalGame +// @description: A basic class about audience +// @author: Xinyu Cui +// @create: 2020/11/12 + +public abstract class Audience implements Cloneable { + + private String id; + protected String type; + + protected abstract void printRace(); + + protected String sex; //Sex of Audience + protected int age; //Age of Audience + protected String race; //Race of Audience + public String color; //Color of Audience + + public String getId(){ + return id; + } + + public void setId(String id) { + this.id = id; + } + + public void setAge(int age) { + this.age = age; + } + + public String setSex(String sex) { + return sex; + } + + public String getRace(){ + return race; + } + + public Object clone(){ + Object clone = null; + try{ + clone = super.clone(); + }catch (CloneNotSupportedException e){ + e.printStackTrace(); + } + return clone; + } +} diff --git a/AnimalGames/src/AniamlGames/Audience/AudienceCache.java b/AnimalGames/src/AniamlGames/Audience/AudienceCache.java new file mode 100644 index 0000000..3ae5b45 --- /dev/null +++ b/AnimalGames/src/AniamlGames/Audience/AudienceCache.java @@ -0,0 +1,36 @@ +package AniamlGames.Audience; + +import AniamlGames.Audience.DetailAudience.BirdAudience; +import AniamlGames.Audience.DetailAudience.CatAudience; +import AniamlGames.Audience.DetailAudience.DogAudience; + +import java.util.Hashtable; + +// @program: AnimalGame +// @description: A basic class for prototypePattern +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class AudienceCache { + private static Hashtable audienceHashtable + = new Hashtable(); + + public static Audience getAudience(String audienceId) throws CloneNotSupportedException { + Audience cachedAudience = audienceHashtable.get(audienceId); + return (Audience) cachedAudience.clone(); + } + + public static void loadCache(){ + DogAudience dogAudience = new DogAudience(); + dogAudience.setId("1"); + audienceHashtable.put(dogAudience.getId(),dogAudience); + + CatAudience catAudience = new CatAudience(); + catAudience.setId("2"); + audienceHashtable.put(catAudience.getId(),catAudience); + + BirdAudience birdAudience = new BirdAudience(); + birdAudience.setId("3"); + audienceHashtable.put(birdAudience.getId(),birdAudience); + } +} diff --git a/AnimalGames/src/AniamlGames/Audience/DetailAudience/AudienceAttribute/AttributeFactory.java b/AnimalGames/src/AniamlGames/Audience/DetailAudience/AudienceAttribute/AttributeFactory.java new file mode 100644 index 0000000..31513ed --- /dev/null +++ b/AnimalGames/src/AniamlGames/Audience/DetailAudience/AudienceAttribute/AttributeFactory.java @@ -0,0 +1,57 @@ +package AniamlGames.Audience.DetailAudience.AudienceAttribute; + +import AniamlGames.Audience.Audience; +import AniamlGames.Audience.DetailAudience.BirdAudience; +import AniamlGames.Audience.DetailAudience.CatAudience; +import AniamlGames.Audience.DetailAudience.DogAudience; + +import java.util.HashMap; + +// @program: AnimalGame +// @description: A basic class for FlyweightPattern +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class AttributeFactory { + private static final HashMap dogAudienceMap + = new HashMap<>(); + + public static Audience setDogAudience(String color) { + DogAudience dogAudience = (DogAudience) dogAudienceMap.get(color); + + if (dogAudience == null) { + dogAudience = new DogAudience(color); + dogAudienceMap.put(color, dogAudience); + System.out.println("Here is the first " + color + " DogAudience"); + } + return dogAudience; + } + + private static final HashMap catAudienceMap + = new HashMap<>(); + + public static Audience setCatAudience(String color) { + CatAudience catAudience = (CatAudience) catAudienceMap.get(color); + + if (catAudience == null) { + catAudience = new CatAudience(color); + catAudienceMap.put(color, catAudience); + System.out.println("Here is the first " + color + " CatAudience"); + } + return catAudience; + } + + private static final HashMap birdAudienceMap + = new HashMap<>(); + + public static Audience setBirdAudience(String color){ + BirdAudience birdAudience = (BirdAudience)birdAudienceMap.get(color); + + if(birdAudience == null){ + birdAudience = new BirdAudience(color); + birdAudienceMap.put(color, birdAudience); + System.out.println("Here is the first " + color + " BirdAudience"); + } + return birdAudience; + } +} \ No newline at end of file diff --git a/AnimalGames/src/AniamlGames/Audience/DetailAudience/BirdAudience.java b/AnimalGames/src/AniamlGames/Audience/DetailAudience/BirdAudience.java new file mode 100644 index 0000000..9970832 --- /dev/null +++ b/AnimalGames/src/AniamlGames/Audience/DetailAudience/BirdAudience.java @@ -0,0 +1,23 @@ +package AniamlGames.Audience.DetailAudience; + +import AniamlGames.Audience.Audience; + +// @program: AnimalGame +// @description: A basic class about detail audience +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class BirdAudience extends Audience { + public BirdAudience(){ + race = "BirdAudience"; + } + + public BirdAudience(String color){ + this.color=color; + } + + @Override + public void printRace(){ + System.out.println("This is a BirdAudience" + ", Color:" + color +", Age:" + age + ", Sex:" + sex); + } +} diff --git a/AnimalGames/src/AniamlGames/Audience/DetailAudience/CatAudience.java b/AnimalGames/src/AniamlGames/Audience/DetailAudience/CatAudience.java new file mode 100644 index 0000000..8b26e68 --- /dev/null +++ b/AnimalGames/src/AniamlGames/Audience/DetailAudience/CatAudience.java @@ -0,0 +1,23 @@ +package AniamlGames.Audience.DetailAudience; + +import AniamlGames.Audience.Audience; + +// @program: AnimalGame +// @description: A basic class about detail audience +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class CatAudience extends Audience { + public CatAudience(){ + race = "CatAudience"; + } + + public CatAudience(String color){ + this.color=color; + } + + @Override + public void printRace(){ + System.out.println("This is a CatAudience" + ", Color:" + color +", Age:" + age + ", Sex:" + sex); + } +} diff --git a/AnimalGames/src/AniamlGames/Audience/DetailAudience/DogAudience.java b/AnimalGames/src/AniamlGames/Audience/DetailAudience/DogAudience.java new file mode 100644 index 0000000..b0f8924 --- /dev/null +++ b/AnimalGames/src/AniamlGames/Audience/DetailAudience/DogAudience.java @@ -0,0 +1,24 @@ +package AniamlGames.Audience.DetailAudience; + +import AniamlGames.Audience.Audience; + +// @program: AnimalGame +// @description: A basic class about detail audience +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class DogAudience extends Audience { + + public DogAudience(){ + race = "DogAudience"; + } + + public DogAudience(String color){ + this.color=color; + } + + @Override + public void printRace(){ + System.out.println("This is a DogAudience" + ", Color:" + color +", Age:" + age + ", Sex:" + sex); + } +} diff --git a/AnimalGames/src/AniamlGames/Games/DetailGame/FourHundredMetersSwimming.java b/AnimalGames/src/AniamlGames/Games/DetailGame/FourHundredMetersSwimming.java new file mode 100644 index 0000000..f380b1b --- /dev/null +++ b/AnimalGames/src/AniamlGames/Games/DetailGame/FourHundredMetersSwimming.java @@ -0,0 +1,41 @@ +package AniamlGames.Games.DetailGame; + +import AniamlGames.Games.Games; + +// @program: AnimalGame +// @description: A basic class about detail game +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class FourHundredMetersSwimming extends Games { + @Override + public void gamePreparation(){ + System.out.println("FourHundredMetersSwimming Game is preparing!"); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("FourHundredMetersSwimming Game prepared!"); + } + + @Override + public void gameStart() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("FourHundredMetersSwimming Game Started!"); + } + + @Override + public void gameEnd() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("FourHundredMetersSwimming Game Finished!"); + } +} diff --git a/AnimalGames/src/AniamlGames/Games/DetailGame/OneHundredMetersRunning.java b/AnimalGames/src/AniamlGames/Games/DetailGame/OneHundredMetersRunning.java new file mode 100644 index 0000000..ef9834f --- /dev/null +++ b/AnimalGames/src/AniamlGames/Games/DetailGame/OneHundredMetersRunning.java @@ -0,0 +1,41 @@ +package AniamlGames.Games.DetailGame; + +import AniamlGames.Games.Games; + +// @program: AnimalGame +// @description: A basic class about detail game +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class OneHundredMetersRunning extends Games { + @Override + public void gamePreparation(){ + System.out.println("OneHundredMetersRunning Game is preparing!"); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("OneHundredMetersRunning Game prepared!"); + } + + @Override + public void gameStart() { + System.out.println("OneHundredMetersRunning Game Started!"); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Override + public void gameEnd() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("OneHundredMetersRunning Game Finished!"); + } +} diff --git a/AnimalGames/src/AniamlGames/Games/DetailGame/OneThousandMetersRunning.java b/AnimalGames/src/AniamlGames/Games/DetailGame/OneThousandMetersRunning.java new file mode 100644 index 0000000..4261037 --- /dev/null +++ b/AnimalGames/src/AniamlGames/Games/DetailGame/OneThousandMetersRunning.java @@ -0,0 +1,41 @@ +package AniamlGames.Games.DetailGame; + +import AniamlGames.Games.Games; + +// @program: AnimalGame +// @description: A basic class about detail game +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class OneThousandMetersRunning extends Games { + @Override + public void gamePreparation(){ + System.out.println("OneThousandMetersRunning Game is preparing!"); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("OneThousandMetersRunning Game prepared!"); + } + + @Override + public void gameStart() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("OneThousandMetersRunning Game Started!"); + } + + @Override + public void gameEnd() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("OneThousandMetersRunning Game Finished!"); + } +} diff --git a/AnimalGames/src/AniamlGames/Games/Games.java b/AnimalGames/src/AniamlGames/Games/Games.java new file mode 100644 index 0000000..a655d1e --- /dev/null +++ b/AnimalGames/src/AniamlGames/Games/Games.java @@ -0,0 +1,24 @@ +package AniamlGames.Games; + +// @program: AnimalGame +// @description: A basic class about games +// @author: Xinyu Cui +// @create: 2020/11/12 + +public abstract class Games { + public abstract void gamePreparation(); + public abstract void gameStart(); + public abstract void gameEnd(); + + //Games template + public final void play(){ + //Game preparation + gamePreparation(); + + //Game begin + gameStart(); + + //Game end + gameEnd(); + } +} diff --git a/AnimalGames/src/DesignPattern/FlyweightPattern.java b/AnimalGames/src/DesignPattern/FlyweightPattern.java new file mode 100644 index 0000000..901db4e --- /dev/null +++ b/AnimalGames/src/DesignPattern/FlyweightPattern.java @@ -0,0 +1,118 @@ +package DesignPattern; + +import AniamlGames.Audience.Audience; +import AniamlGames.Audience.DetailAudience.AudienceAttribute.AttributeFactory; +import AniamlGames.Audience.DetailAudience.BirdAudience; +import AniamlGames.Audience.DetailAudience.CatAudience; +import AniamlGames.Audience.DetailAudience.DogAudience; + +import java.util.Scanner; + +// @program: AnimalGame +// @description: The test class for FlyweightPattern +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class FlyweightPattern { + private static final String colors[] = + {"Black", "White", "Yellow", "Brown", "Gray"}; + + public static void main(String[] args) { + System.out.println("Please enter the race of the audience!"); + System.out.println("\"1\":DogAudience \"2\":CatAudience \"3\":BirdAudience"); + System.out.println("Input \"view\" to view the counter!"); + System.out.println("Input \"detail\" to view the detail audience!"); + System.out.println("Input \"Q\" to quit!"); + int counter = 0; + int dogCounter = 0; + int[] dogsCounter = new int[5]; + int catCounter = 0; + int[] catsCounter = new int[5]; + int birdCounter = 0; + int[] birdsCounter = new int[5]; + String str = ""; + boolean flag = true; + while (flag) { + Scanner sc = new Scanner(System.in); + str = sc.nextLine(); + switch (str) { + case "1": { + String color = getRandomColor(); + if(color == "Black"){ dogsCounter[0]++;} + else if (color == "White"){dogsCounter[1]++;} + else if (color == "Yellow"){dogsCounter[2]++;} + else if (color == "Brown"){dogsCounter[3]++;} + else if (color == "Gray"){dogsCounter[4]++;} + DogAudience dogAudience = (DogAudience) AttributeFactory.setDogAudience(color); + dogAudience.setAge(getRandomAge()); + dogAudience.setSex(getRandomSex()); + dogAudience.printRace(); + dogCounter++;counter++; + };break; + case "2": { + String color = getRandomColor(); + if(color == "Black"){ catsCounter[0]++;} + else if (color == "White"){catsCounter[1]++;} + else if (color == "Yellow"){catsCounter[2]++;} + else if (color == "Brown"){catsCounter[3]++;} + else if (color == "Gray"){catsCounter[4]++;} + CatAudience catAudience = (CatAudience) AttributeFactory.setCatAudience(color); + catAudience.setAge(getRandomAge()); + catAudience.setSex(getRandomSex()); + catAudience.printRace(); + catCounter++;counter++; + };break; + case "3": { + String color = getRandomColor(); + if(color == "Black"){ birdsCounter[0]++;} + else if (color == "White"){birdsCounter[1]++;} + else if (color == "Yellow"){birdsCounter[2]++;} + else if (color == "Brown"){birdsCounter[3]++;} + else if (color == "Gray"){birdsCounter[4]++;} + BirdAudience birdAudience = (BirdAudience) AttributeFactory.setBirdAudience(color); + birdAudience.setAge(getRandomAge()); + birdAudience.setSex(getRandomSex()); + birdAudience.printRace(); + birdCounter++;counter++; + };break; + case "detail": { + System.out.println("Black DogAudience:" + dogsCounter[0] + ", White DogAudience:" + dogsCounter[1] + + ", Yellow DogAudience:" + dogsCounter[2] + ", Brown DogAudience:" + dogsCounter[3] + ", Gray DogAudience:" + dogsCounter[4]); + System.out.println("Black CatAudience:" + catsCounter[0] + ", White CatAudience:" + catsCounter[1] + + ", Yellow CatAudience:" + catsCounter[2] + ", Brown CatAudience:" + catsCounter[3] + ", Gray CatAudience:" + catsCounter[4]); + System.out.println("Black BirdAudience:" + birdsCounter[0] + ", White BirdAudience:" + birdsCounter[1] + + ", Yellow BirdAudience:" + birdsCounter[2] + ", Brown BirdAudience:" + birdsCounter[3] + ", Gray BirdAudience:" + birdsCounter[4]); + };break; + case "view": { + System.out.println("The number of Audience:" + counter); + System.out.println("The number of DogAudience:" + dogCounter); + System.out.println("The number of CatAudience:" + catCounter); + System.out.println("The number of BirdAudience:" + birdCounter); + };break; + case "Q":{ + flag = false; + };break; + default:{ + System.out.println("Invalid input,please try again!"); + };break; + } + } + } + private static String getRandomColor(){ + return colors[(int)(Math.random()*colors.length)]; + } + + private static int getRandomAge() { + int maxAge = 60; + int minAge = 1; + return minAge + (int) (Math.random() * maxAge); + } + + public static String getRandomSex() { + if (((Math.random() * 100) % 2) == 1) { + return "MALE"; + } else { + return "FEMALE"; + } + } +} diff --git a/AnimalGames/src/DesignPattern/PrototypePattern.java b/AnimalGames/src/DesignPattern/PrototypePattern.java new file mode 100644 index 0000000..a4d271e --- /dev/null +++ b/AnimalGames/src/DesignPattern/PrototypePattern.java @@ -0,0 +1,66 @@ +package DesignPattern; + +import AniamlGames.Audience.Audience; +import AniamlGames.Audience.AudienceCache; + +import java.util.Scanner; + + +// @program: AnimalGame +// @description: The test class for PrototypePattern +// @author: Xinyu Cui +// @create: 2020/11/12 + + +public class PrototypePattern { + public static void main(String[] args) throws CloneNotSupportedException { + AudienceCache.loadCache(); + + System.out.println("Please enter the race of the audience!"); + System.out.println("\"1\":DogAudience \"2\":CatAudience \"3\":BirdAudience"); + System.out.println("Input \"view\" to view the counter!"); + System.out.println("Input \"Q\" to quit!"); + int counter = 0; + int dogCounter = 0; + int catCounter = 0; + int birdCounter = 0; + String str = ""; + boolean flag = true; + while (flag) { + Scanner sc = new Scanner(System.in); + str = sc.nextLine(); + switch (str) { + case "1": { + System.out.println("From Audience clone a new DogAudience!"); + Audience clonedAudience = AudienceCache.getAudience("1"); + System.out.println("Here is a new " + clonedAudience.getRace()); + counter++;dogCounter++; + };break; + case "2": { + System.out.println("From Audience clone a new CatAudience!"); + Audience clonedAudience = AudienceCache.getAudience("2"); + System.out.println("Here is a new " + clonedAudience.getRace()); + counter++;catCounter++; + };break; + case "3": { + System.out.println("From Audience clone a new BirdAudience!"); + Audience clonedAudience = AudienceCache.getAudience("3"); + System.out.println("Here is a new " + clonedAudience.getRace()); + counter++;birdCounter++; + };break; + case "view": { + System.out.println("The number of Audience:" + counter); + System.out.println("The number of DogAudience:" + dogCounter); + System.out.println("The number of CatAudience:" + catCounter); + System.out.println("The number of BirdAudience:" + birdCounter); + };break; + case "Q":{ + flag = false; + };break; + default: { + System.out.println("Invalid input,please try again!"); + }break; + } + } + } +} diff --git a/AnimalGames/src/DesignPattern/TemplatePattern.java b/AnimalGames/src/DesignPattern/TemplatePattern.java new file mode 100644 index 0000000..5a07166 --- /dev/null +++ b/AnimalGames/src/DesignPattern/TemplatePattern.java @@ -0,0 +1,48 @@ +package DesignPattern; + +import AniamlGames.Games.DetailGame.FourHundredMetersSwimming; +import AniamlGames.Games.DetailGame.OneHundredMetersRunning; +import AniamlGames.Games.DetailGame.OneThousandMetersRunning; +import AniamlGames.Games.Games; + +import java.util.Scanner; + +// @program: AnimalGame +// @description: The test class for TemplatePattern +// @author: Xinyu Cui +// @create: 2020/11/12 + +public class TemplatePattern { + public static void main(String[] args) { + String str = ""; + boolean flag = true; + System.out.println("Please enter the type of the game!"); + System.out.println("\"1\":OneHundredMetersRunning \"2\":OneThousandMetersRunning \"3\":FourHundredMetersSwimming"); + System.out.println("Input \"Q\" to quit!"); + while (flag) { + Games game = null; + Scanner sc = new Scanner(System.in); + str = sc.nextLine(); + switch (str){ + case "1":{ + game = new OneHundredMetersRunning(); + game.play(); + };break; + case "2":{ + game = new OneThousandMetersRunning(); + game.play(); + };break; + case "3":{ + game = new FourHundredMetersSwimming(); + game.play(); + };break; + case "Q":{ + flag = false; + };break; + default:{ + System.out.println("Invalid input,please try again!"); + };break; + } + } + } +} From 4a619606e7218988ff45b70e8f5bc362d5fe4d51 Mon Sep 17 00:00:00 2001 From: cxy592394546 Date: Sun, 15 Nov 2020 17:48:44 +0800 Subject: [PATCH 02/23] little fix --- AnimalGames/src/AniamlGames/Audience/Audience.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AnimalGames/src/AniamlGames/Audience/Audience.java b/AnimalGames/src/AniamlGames/Audience/Audience.java index ad5c67d..e7dd312 100644 --- a/AnimalGames/src/AniamlGames/Audience/Audience.java +++ b/AnimalGames/src/AniamlGames/Audience/Audience.java @@ -29,8 +29,8 @@ public void setAge(int age) { this.age = age; } - public String setSex(String sex) { - return sex; + public void setSex(String sex) { + this.sex = sex; } public String getRace(){ From a2192af82fe3cc26502f40ad2ab517fde7ebefe9 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Mon, 16 Nov 2020 14:03:38 +0800 Subject: [PATCH 03/23] Update Audience.java --- AnimalGames/src/AniamlGames/Audience/Audience.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnimalGames/src/AniamlGames/Audience/Audience.java b/AnimalGames/src/AniamlGames/Audience/Audience.java index ad5c67d..57756d9 100644 --- a/AnimalGames/src/AniamlGames/Audience/Audience.java +++ b/AnimalGames/src/AniamlGames/Audience/Audience.java @@ -30,7 +30,7 @@ public void setAge(int age) { } public String setSex(String sex) { - return sex; + this.sex = sex; } public String getRace(){ From 76c49a355e5d81edf9d49159291e53f799e7ff5c Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Mon, 16 Nov 2020 19:16:45 +0800 Subject: [PATCH 04/23] Update Audience.java --- AnimalGames/src/AniamlGames/Audience/Audience.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnimalGames/src/AniamlGames/Audience/Audience.java b/AnimalGames/src/AniamlGames/Audience/Audience.java index ad5c67d..57756d9 100644 --- a/AnimalGames/src/AniamlGames/Audience/Audience.java +++ b/AnimalGames/src/AniamlGames/Audience/Audience.java @@ -30,7 +30,7 @@ public void setAge(int age) { } public String setSex(String sex) { - return sex; + this.sex = sex; } public String getRace(){ From 93c49f940e1085d7afc1addada3238907b73e2a1 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Fri, 20 Nov 2020 14:06:26 +0800 Subject: [PATCH 05/23] Added PrototypePattern --- AnimalGames/PrototypePattern | 1 + 1 file changed, 1 insertion(+) create mode 100644 AnimalGames/PrototypePattern diff --git a/AnimalGames/PrototypePattern b/AnimalGames/PrototypePattern new file mode 100644 index 0000000..8937ccc --- /dev/null +++ b/AnimalGames/PrototypePattern @@ -0,0 +1 @@ +7VvZcuI4FP0aHpPywpZHIEt3TzpDN5lkXgUWoEG2GFmE0F/fV7a8KoCd4HZCqEpVrGtZtnSOro6OTcMeuM83HC3n35mDacMynOeGfdmwLNOybPgnI5sw0u2YYWDGiaMqJYER+YVV0FDRFXGwn6koGKOCLLPBCfM8PBGZGOKcrbPVpoxm77pEM6wFRhNE9egjccRc9cLqJPEvmMzm0Z3N9kV4xkVRZdUTf44ctk6F7KuGPeCMifDIfR5gKgcvGpfHr5tHerto33z74f+P/un/dX/3cBY2dl3mkrgLHHvi1U3/Wkyvvzw0//t3Obz+sTZueuNvZ+oS4wnRlRqvIeY+81SPxSYaRn9NXIo8KPWnzBMjdQYGoY8omXlwPIGnwxwCT5gLAg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rVk0Z3Gbe8pT4KlesHSMroZOhT+EsYydywy2xVLq/WBvoTRjdSR4Bjrb28+i2LpFKbXu1Esujk6IOL4NOdBLfDyONfugVu6XwpJWxzfd2s1A1371y+WbpmCsperuGUMmHMC/MCAF/4ypjrEdUN1AGMijtA5qBtr+5Vi7HBY64amBvKnNxjK49oqKMOqchgs3ft7AIicY1ygq0OxXXsm1u2/v1diuZL2Qk++q7yV8+CEaGFEL2rPt+WsP7YMxrqcuRf7gmb9Vp8a271OX4TlXqtP4SyplLY1muqB3uj6xe9zYsJY2SaKun6t5p6Gtrh+WkNn+TdOuXbYdOrjSoxDSzcOjfPzCPiEroEZl0oEe9LOWFly4RreR5PFLODvgFHG4bzHEgNSud1W8ZwQzS/1m0v1WI3492fFjbqzNzIqIuYfg0s3z4pjFemnjwrWYWZ/9FHuH4dO98wo9EIu8Gir95mS43lUdRVcxMGPNfpurEu56G8khkaAbVwpvk5cHIYpdtbFj5L0W7gCxeQX12H15Hfr9tVv \ No newline at end of file From dfd84017435191c665cde7233e1951433f327463 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Fri, 20 Nov 2020 14:29:02 +0800 Subject: [PATCH 06/23] Update PrototypePattern --- AnimalGames/PrototypePattern | 145 ++++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/AnimalGames/PrototypePattern b/AnimalGames/PrototypePattern index 8937ccc..19503f5 100644 --- a/AnimalGames/PrototypePattern +++ b/AnimalGames/PrototypePattern @@ -1 +1,144 @@ -7VvZcuI4FP0aHpPywpZHIEt3TzpDN5lkXgUWoEG2GFmE0F/fV7a8KoCd4HZCqEpVrGtZtnSOro6OTcMeuM83HC3n35mDacMynOeGfdmwLNOybPgnI5sw0u2YYWDGiaMqJYER+YVV0FDRFXGwn6koGKOCLLPBCfM8PBGZGOKcrbPVpoxm77pEM6wFRhNE9egjccRc9cLqJPEvmMzm0Z3N9kV4xkVRZdUTf44ctk6F7KuGPeCMifDIfR5gKgcv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OphXr5t/Q86m2PeZrtdPW8zqt5h2fstXdIvZMfaS+IUdpt0ssMPsvI8dpqn7liNEkcq4n3Btiyfvx9lZmrpNqaH32bca5WEtuoGsbK+h25SfSrFEiL1ryWLmMn3nlZLFzjVkdXLPUrVk0Z3Gbe8pT4KlesHSMroZOhT+EsYydywy2xVLq/WBvoTRjdSR4Bjrb28+i2LpFKbXu1Esujk6IOL4NOdBLfDyONfugVu6XwpJWxzfd2s1A1371y+WbpmCsperuGUMmHMC/MCAF/4ypjrEdUN1AGMijtA5qBtr+5Vi7HBY64amBvKnNxjK49oqKMOqchgs3ft7AIicY1ygq0OxXXsm1u2/v1diuZL2Qk++q7yV8+CEaGFEL2rPt+WsP7YMxrqcuRf7gmb9Vp8a271OX4TlXqtP4SyplLY1muqB3uj6xe9zYsJY2SaKun6t5p6Gtrh+WkNn+TdOuXbYdOrjSoxDSzcOjfPzCPiEroEZl0oEe9LOWFly4RreR5PFLODvgFHG4bzHEgNSud1W8ZwQzS/1m0v1WI3492fFjbqzNzIqIuYfg0s3z4pjFemnjwrWYWZ/9FHuH4dO98wo9EIu8Gir95mS43lUdRVcxMGPNfpurEu56G8khkaAbVwpvk5cHIYpdtbFj5L0W7gCxeQX12H15Hfr9tVv \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 83548dd1a1344d7e118a8216a587c10bdd6134d7 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Fri, 20 Nov 2020 14:35:37 +0800 Subject: [PATCH 07/23] Added TemplatePattern --- AnimalGames/TemplatePattern | 1 + 1 file changed, 1 insertion(+) create mode 100644 AnimalGames/TemplatePattern diff --git a/AnimalGames/TemplatePattern b/AnimalGames/TemplatePattern new file mode 100644 index 0000000..99fa8d9 --- /dev/null +++ b/AnimalGames/TemplatePattern @@ -0,0 +1 @@ +UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA== \ No newline at end of file From 1fc2f4f6304db9928fdb9135e8bba8d3c3480b78 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Fri, 20 Nov 2020 14:49:30 +0800 Subject: [PATCH 08/23] Update TemplatePattern --- AnimalGames/TemplatePattern | 95 ++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/AnimalGames/TemplatePattern b/AnimalGames/TemplatePattern index 99fa8d9..90c7237 100644 --- a/AnimalGames/TemplatePattern +++ b/AnimalGames/TemplatePattern @@ -1 +1,94 @@ -UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA== \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From d6935b42676da23d030106e903283005cd2182a8 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Fri, 20 Nov 2020 14:50:28 +0800 Subject: [PATCH 09/23] Added FlyweightPattern --- AnimalGames/FlyweightPattern | 1 + 1 file changed, 1 insertion(+) create mode 100644 AnimalGames/FlyweightPattern diff --git a/AnimalGames/FlyweightPattern b/AnimalGames/FlyweightPattern new file mode 100644 index 0000000..eee7bf8 --- /dev/null +++ b/AnimalGames/FlyweightPattern @@ -0,0 +1 @@ +UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA== \ No newline at end of file From c689a8df568abfa57ef5f3b9abed744444d9f931 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Fri, 20 Nov 2020 15:27:13 +0800 Subject: [PATCH 10/23] Update FlyweightPattern --- AnimalGames/FlyweightPattern | 141 ++++++++++++++++++++++++++++++++++- 1 file changed, 140 insertions(+), 1 deletion(-) diff --git a/AnimalGames/FlyweightPattern b/AnimalGames/FlyweightPattern index eee7bf8..868869f 100644 --- a/AnimalGames/FlyweightPattern +++ b/AnimalGames/FlyweightPattern @@ -1 +1,140 @@ -UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA== \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From aa974499a68d6d2961ce3800a25e3fb3c4614f63 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Fri, 20 Nov 2020 15:27:52 +0800 Subject: [PATCH 11/23] Update FlyweightPattern --- AnimalGames/FlyweightPattern | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AnimalGames/FlyweightPattern b/AnimalGames/FlyweightPattern index 868869f..ea604f2 100644 --- a/AnimalGames/FlyweightPattern +++ b/AnimalGames/FlyweightPattern @@ -1,11 +1,11 @@ - + - + - + From d061cc3961d20f7b45936af1ad0d4903e81b6326 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Sat, 21 Nov 2020 19:07:12 +0800 Subject: [PATCH 12/23] Update TemplatePattern --- AnimalGames/TemplatePattern | 71 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/AnimalGames/TemplatePattern b/AnimalGames/TemplatePattern index 90c7237..0cfc46b 100644 --- a/AnimalGames/TemplatePattern +++ b/AnimalGames/TemplatePattern @@ -1,89 +1,88 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - - + + - - - - - + + + + - - + + - - - - - + + + + + From fc24d942f057400d463468b3b3c47f5537ddd94d Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Sat, 21 Nov 2020 19:07:26 +0800 Subject: [PATCH 13/23] Update PrototypePattern --- AnimalGames/PrototypePattern | 97 ++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/AnimalGames/PrototypePattern b/AnimalGames/PrototypePattern index 19503f5..4362367 100644 --- a/AnimalGames/PrototypePattern +++ b/AnimalGames/PrototypePattern @@ -1,31 +1,31 @@ - + - + - + - + - + - + - + - + - + - + @@ -34,107 +34,96 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + + + + - - - - - - - + + - + - - - - - - - - - + + + + - + - - - - From c9b1295c7e3a9e402029b866fdbc1087e4e271fe Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Sat, 21 Nov 2020 19:09:56 +0800 Subject: [PATCH 14/23] Update FlyweightPattern --- AnimalGames/FlyweightPattern | 103 +++++++++++++++-------------------- 1 file changed, 45 insertions(+), 58 deletions(-) diff --git a/AnimalGames/FlyweightPattern b/AnimalGames/FlyweightPattern index ea604f2..4d228ec 100644 --- a/AnimalGames/FlyweightPattern +++ b/AnimalGames/FlyweightPattern @@ -1,49 +1,49 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -54,83 +54,70 @@ - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - - + + - - - - - - - - - + + + + - - + + - - - - - - - - - + + + + - + + - - - - From b0adcd50c549280c3e1e135499c9010cd93cffb4 Mon Sep 17 00:00:00 2001 From: cxy592394546 Date: Sun, 22 Nov 2020 14:46:19 +0800 Subject: [PATCH 15/23] ttle fix --- .idea/.gitignore | 3 +++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ AnimalGames/src/DesignPattern/FlyweightPattern.java | 2 +- DesignPattern.iml | 11 +++++++++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 DesignPattern.iml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..35fb8b9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2fbbd78 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AnimalGames/src/DesignPattern/FlyweightPattern.java b/AnimalGames/src/DesignPattern/FlyweightPattern.java index 901db4e..bdbe254 100644 --- a/AnimalGames/src/DesignPattern/FlyweightPattern.java +++ b/AnimalGames/src/DesignPattern/FlyweightPattern.java @@ -108,7 +108,7 @@ private static int getRandomAge() { return minAge + (int) (Math.random() * maxAge); } - public static String getRandomSex() { + private static String getRandomSex() { if (((Math.random() * 100) % 2) == 1) { return "MALE"; } else { diff --git a/DesignPattern.iml b/DesignPattern.iml new file mode 100644 index 0000000..d8dc033 --- /dev/null +++ b/DesignPattern.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From a54c079629736b126a74125a503f2984c398e9e4 Mon Sep 17 00:00:00 2001 From: cxy592394546 Date: Sun, 22 Nov 2020 15:55:30 +0800 Subject: [PATCH 16/23] Fix package name --- AnimalGames/src/{DesignPattern => Test}/FlyweightPattern.java | 3 +-- AnimalGames/src/{DesignPattern => Test}/PrototypePattern.java | 2 +- AnimalGames/src/{DesignPattern => Test}/TemplatePattern.java | 2 +- README.md | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) rename AnimalGames/src/{DesignPattern => Test}/FlyweightPattern.java (98%) rename AnimalGames/src/{DesignPattern => Test}/PrototypePattern.java (99%) rename AnimalGames/src/{DesignPattern => Test}/TemplatePattern.java (98%) diff --git a/AnimalGames/src/DesignPattern/FlyweightPattern.java b/AnimalGames/src/Test/FlyweightPattern.java similarity index 98% rename from AnimalGames/src/DesignPattern/FlyweightPattern.java rename to AnimalGames/src/Test/FlyweightPattern.java index bdbe254..c882d48 100644 --- a/AnimalGames/src/DesignPattern/FlyweightPattern.java +++ b/AnimalGames/src/Test/FlyweightPattern.java @@ -1,6 +1,5 @@ -package DesignPattern; +package Test; -import AniamlGames.Audience.Audience; import AniamlGames.Audience.DetailAudience.AudienceAttribute.AttributeFactory; import AniamlGames.Audience.DetailAudience.BirdAudience; import AniamlGames.Audience.DetailAudience.CatAudience; diff --git a/AnimalGames/src/DesignPattern/PrototypePattern.java b/AnimalGames/src/Test/PrototypePattern.java similarity index 99% rename from AnimalGames/src/DesignPattern/PrototypePattern.java rename to AnimalGames/src/Test/PrototypePattern.java index a4d271e..e414e3e 100644 --- a/AnimalGames/src/DesignPattern/PrototypePattern.java +++ b/AnimalGames/src/Test/PrototypePattern.java @@ -1,4 +1,4 @@ -package DesignPattern; +package Test; import AniamlGames.Audience.Audience; import AniamlGames.Audience.AudienceCache; diff --git a/AnimalGames/src/DesignPattern/TemplatePattern.java b/AnimalGames/src/Test/TemplatePattern.java similarity index 98% rename from AnimalGames/src/DesignPattern/TemplatePattern.java rename to AnimalGames/src/Test/TemplatePattern.java index 5a07166..66a42be 100644 --- a/AnimalGames/src/DesignPattern/TemplatePattern.java +++ b/AnimalGames/src/Test/TemplatePattern.java @@ -1,4 +1,4 @@ -package DesignPattern; +package Test; import AniamlGames.Games.DetailGame.FourHundredMetersSwimming; import AniamlGames.Games.DetailGame.OneHundredMetersRunning; diff --git a/README.md b/README.md index 3cf910a..55ffea3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# DesignPattern +# Test 同济大学18级软件架构与设计模式期末项目--动物运动会 From a4ec0e2a399bbbceb51237682f1ced2684a6e60d Mon Sep 17 00:00:00 2001 From: cxy592394546 Date: Sun, 22 Nov 2020 15:57:35 +0800 Subject: [PATCH 17/23] fix --- AnimalGames/src/AniamlGames/Audience/Audience.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnimalGames/src/AniamlGames/Audience/Audience.java b/AnimalGames/src/AniamlGames/Audience/Audience.java index ad5c67d..57756d9 100644 --- a/AnimalGames/src/AniamlGames/Audience/Audience.java +++ b/AnimalGames/src/AniamlGames/Audience/Audience.java @@ -30,7 +30,7 @@ public void setAge(int age) { } public String setSex(String sex) { - return sex; + this.sex = sex; } public String getRace(){ From 53229ca07a0e2e043f8bd620c6b1ab7d6c32f546 Mon Sep 17 00:00:00 2001 From: cxy592394546 Date: Tue, 24 Nov 2020 15:01:56 +0800 Subject: [PATCH 18/23] bug fix --- AnimalGames/src/AniamlGames/Audience/Audience.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnimalGames/src/AniamlGames/Audience/Audience.java b/AnimalGames/src/AniamlGames/Audience/Audience.java index 57756d9..e7dd312 100644 --- a/AnimalGames/src/AniamlGames/Audience/Audience.java +++ b/AnimalGames/src/AniamlGames/Audience/Audience.java @@ -29,7 +29,7 @@ public void setAge(int age) { this.age = age; } - public String setSex(String sex) { + public void setSex(String sex) { this.sex = sex; } From 37209205b29c754fe3ebe269fdb6b3d8474a016d Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Wed, 25 Nov 2020 09:50:30 +0800 Subject: [PATCH 19/23] Added MVCPattern --- AnimalGames/MVCPattern | 1 + 1 file changed, 1 insertion(+) create mode 100644 AnimalGames/MVCPattern diff --git a/AnimalGames/MVCPattern b/AnimalGames/MVCPattern new file mode 100644 index 0000000..674569f --- /dev/null +++ b/AnimalGames/MVCPattern @@ -0,0 +1 @@ +7VvZcuI4FP0aHpPywpZHIEt3TzpDN5lkXgUWoEG2GFmE0F/fV7a8KoCd4HZCqEpVrGtZtnSOro6OTcMeuM83HC3n35mDacMynOeGfdmwLNOybPgnI5sw0u2YYWDGiaMqJYER+YVV0FDRFXGwn6koGKOCLLPBCfM8PBGZGOKcrbPVpoxm77pEM6wFRhNE9egjccRc9cLqJPEvmMzm0Z3N9kV4xkVRZdUTf44ctk6F7KuGPeCMifDIfR5gKgcvGpfHr5tHerto33z74f+P/un/dX/3cBY2dl3mkrgLHHvi1U3/Wkyvvzw0//t3Obz+sTZueuNvZ+oS4wnRlRqvIeY+81SPxSYaRn9NXIo8KPWnzBMjdQYGoY8omXlwPIGnwxwCT5gLAgj01AnBlhCdzAl1btGGrWQffIEmi6jUnzNOfkGziMIpEwJwmgtFJqudqTGSV0LYgCjHPtQZRgNjxqFb5AtVZ8IoRUufjIMHllVcxGfE6zMhmBs1xFaegx1VipEOCoKzRcwdeX1BOBRscjTwc4qMCp4bzFws+AaqqLMx0zbR5FPldUJcs61i8zRp7a6aMGqyzOK249v9hMmFvBkMQnI/O3e/ZsH7ASKZ2yEKwHtI4L4cRj9NQzhIdTUJBeQsQVRTI+odcrFGUxhpkaIkxVOxlZD+Ek2IN7sN6lw2k8hP1VMZYnDtlAZkmBPHwV5AFoEECvkkGbJkxBPBULT68AcDNjDOW40WPNAAymZShj9ZnYsB84BXiAQEwkDWNZaEfYFaO6ftfmptsoiVRTZNpAykZfGz9EQzZ54k493KHUPaODYkd2SUuXCpOqwK75ZVM962hveVi4i8rOc4kKP9E+AHBbzTrRnwpga4hjAlgX5Qo2G+uLbugd8FIGVzEd73kg6XZ6bGCVvnhP0C/hSNMR0ynwjCZPs8rJvjRV1Z2zSaxVDdsfy/CdSWnrVXfDJHvkzcILsWMLzB0RHO58p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001 From: cxy592394546 Date: Wed, 25 Nov 2020 09:56:54 +0800 Subject: [PATCH 20/23] fix --- .idea/uiDesigner.xml | 124 ++++++++++++++++++ .../src/AniamlGames/MVC/Animal/Animal.java | 95 ++++++++++++++ .../MVC/Animal/AnimalIngredientFactory.java | 9 ++ .../AniamlGames/MVC/Animal/AnimalStore.java | 37 ++++++ .../src/AniamlGames/MVC/Animal/Cat.java | 9 ++ .../src/AniamlGames/MVC/Animal/Color.java | 5 + .../src/AniamlGames/MVC/Animal/Dog.java | 8 ++ .../src/AniamlGames/MVC/Animal/GCFactory.java | 13 ++ .../src/AniamlGames/MVC/Animal/GDFactory.java | 13 ++ .../src/AniamlGames/MVC/Animal/Green.java | 8 ++ .../src/AniamlGames/MVC/Animal/Main.java | 21 +++ .../src/AniamlGames/MVC/Animal/RCFactory.java | 13 ++ .../src/AniamlGames/MVC/Animal/RDFactory.java | 13 ++ .../src/AniamlGames/MVC/Animal/Race.java | 5 + .../src/AniamlGames/MVC/Animal/Red.java | 8 ++ .../src/AniamlGames/MVC/AnimalController.java | 25 ++++ .../src/AniamlGames/MVC/AnimalViews.java | 7 + .../{ => DetailTest}/FlyweightPattern.java | 2 +- .../src/Test/DetailTest/MVCPattern.java | 34 +++++ .../{ => DetailTest}/PrototypePattern.java | 2 +- .../{ => DetailTest}/TemplatePattern.java | 2 +- AnimalGames/src/Test/MainTest.java | 33 +++++ 22 files changed, 483 insertions(+), 3 deletions(-) create mode 100644 .idea/uiDesigner.xml create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/Animal.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/AnimalIngredientFactory.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/AnimalStore.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/Cat.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/Color.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/Dog.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/GCFactory.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/GDFactory.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/Green.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/Main.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/RCFactory.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/RDFactory.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/Race.java create mode 100644 AnimalGames/src/AniamlGames/MVC/Animal/Red.java create mode 100644 AnimalGames/src/AniamlGames/MVC/AnimalController.java create mode 100644 AnimalGames/src/AniamlGames/MVC/AnimalViews.java rename AnimalGames/src/Test/{ => DetailTest}/FlyweightPattern.java (99%) create mode 100644 AnimalGames/src/Test/DetailTest/MVCPattern.java rename AnimalGames/src/Test/{ => DetailTest}/PrototypePattern.java (99%) rename AnimalGames/src/Test/{ => DetailTest}/TemplatePattern.java (98%) create mode 100644 AnimalGames/src/Test/MainTest.java diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/Animal.java b/AnimalGames/src/AniamlGames/MVC/Animal/Animal.java new file mode 100644 index 0000000..8f9685d --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/Animal.java @@ -0,0 +1,95 @@ +package AniamlGames.MVC.Animal; + +public class Animal { + String AnimalName; + Race AnimalRace; + Color AnimalColor; + int speed,power,skill,HP=5; + + AnimalIngredientFactory factory;// factory interface + + public Animal(){// do nothing + + } + + public void setFactory(AnimalIngredientFactory factory) {//bind product factory + this.factory = factory; + } + + public void makeAnimal(){ + + prepare(); + setAnimalName(AnimalColor.toString()+AnimalRace.toString()); + //default use color&race + + } + + private void prepare(){// bind Animal attribute + AnimalRace=factory.CreateRace(); + AnimalColor=factory.CreateColor(); + if (AnimalRace.toString().equals("cat")){ + skill+=3; + } + else if (AnimalRace.toString().equals("dog")){ + HP+=5; + } + if (AnimalColor.toString().equals("green")){ + speed+=2; + } + else if (AnimalColor.toString().equals("red")){ + power+=4; + } + + System.out.println("Preparing "+AnimalColor.toString()+'_'+AnimalRace.toString()); + } + public void setAnimalName(String animalName) { + this.AnimalName = animalName; + } + + public String getAnimalName() { + return AnimalName; + } + + public Color getAnimalColor() { + return AnimalColor; + } + + public Race getAnimalRace() { + return AnimalRace; + } + + public int getHP() { + return HP; + } + + public int getPower() { + return power; + } + + public int getSkill() { + return skill; + } + + public int getSpeed() { + return speed; + } + + @Override + public String toString() {// to print test + + StringBuffer result=new StringBuffer(); + result.append("----"+AnimalName+"----\n"); + if (AnimalColor!=null){ + + result.append("color is "); + result.append(AnimalColor); + + } + result.append(" "); + if (AnimalRace!=null){ + result.append("race is "); + result.append(AnimalRace); + } + return result.toString(); + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/AnimalIngredientFactory.java b/AnimalGames/src/AniamlGames/MVC/Animal/AnimalIngredientFactory.java new file mode 100644 index 0000000..cbb3c88 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/AnimalIngredientFactory.java @@ -0,0 +1,9 @@ +package AniamlGames.MVC.Animal; + +public interface AnimalIngredientFactory { + + public abstract Race CreateRace(); // Race product + public abstract Color CreateColor(); // Color product + + +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/AnimalStore.java b/AnimalGames/src/AniamlGames/MVC/Animal/AnimalStore.java new file mode 100644 index 0000000..7a596bc --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/AnimalStore.java @@ -0,0 +1,37 @@ +package AniamlGames.MVC.Animal; + +public class AnimalStore { + + protected Animal createAnimal(String AnimalName){ + Animal animal=new Animal(); + AnimalIngredientFactory factory=null; + + if (AnimalName.equals("GreenDog")){ + factory=new GDFactory(); + animal.setFactory(factory); + } + else if (AnimalName.equals("GreenCat")){ + factory=new GCFactory(); + animal.setFactory(factory); + } + else if (AnimalName.equals("RedDog")){ + factory=new RDFactory(); + animal.setFactory(factory); + } + else if (AnimalName.equals("RedCat")){ + factory=new RCFactory(); + animal.setFactory(factory); + } + + + return animal; + } + + public Animal orderAnimal(String AnimalName){ + Animal animal=createAnimal(AnimalName); + animal.makeAnimal(); + return animal; + } + + +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/Cat.java b/AnimalGames/src/AniamlGames/MVC/Animal/Cat.java new file mode 100644 index 0000000..c2fbfd7 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/Cat.java @@ -0,0 +1,9 @@ +package AniamlGames.MVC.Animal; + +public class Cat implements Race{ + + @Override + public String toString() { + return "cat"; + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/Color.java b/AnimalGames/src/AniamlGames/MVC/Animal/Color.java new file mode 100644 index 0000000..656e122 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/Color.java @@ -0,0 +1,5 @@ +package AniamlGames.MVC.Animal; + +public interface Color { + public String toString(); +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/Dog.java b/AnimalGames/src/AniamlGames/MVC/Animal/Dog.java new file mode 100644 index 0000000..831f753 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/Dog.java @@ -0,0 +1,8 @@ +package AniamlGames.MVC.Animal; + +public class Dog implements Race{ + @Override + public String toString() { + return "dog"; + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/GCFactory.java b/AnimalGames/src/AniamlGames/MVC/Animal/GCFactory.java new file mode 100644 index 0000000..7ac8f2d --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/GCFactory.java @@ -0,0 +1,13 @@ +package AniamlGames.MVC.Animal; + +public class GCFactory implements AnimalIngredientFactory{ + @Override + public Race CreateRace() { + return new Cat(); + } + + @Override + public Color CreateColor() { + return new Green(); + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/GDFactory.java b/AnimalGames/src/AniamlGames/MVC/Animal/GDFactory.java new file mode 100644 index 0000000..4f17938 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/GDFactory.java @@ -0,0 +1,13 @@ +package AniamlGames.MVC.Animal; + +public class GDFactory implements AnimalIngredientFactory { + @Override + public Race CreateRace() { + return new Dog(); + } + + @Override + public Color CreateColor() { + return new Green(); + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/Green.java b/AnimalGames/src/AniamlGames/MVC/Animal/Green.java new file mode 100644 index 0000000..061878f --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/Green.java @@ -0,0 +1,8 @@ +package AniamlGames.MVC.Animal; + +public class Green implements Color { + @Override + public String toString() { + return "green"; + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/Main.java b/AnimalGames/src/AniamlGames/MVC/Animal/Main.java new file mode 100644 index 0000000..67157d6 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/Main.java @@ -0,0 +1,21 @@ +package AniamlGames.MVC.Animal; + +public class Main { + public static void main(String[] args) { + AnimalStore animalStore=new AnimalStore(); + Animal animal=null; + + animal=animalStore.orderAnimal("GreenDog"); + System.out.println(animal); + + animal=animalStore.orderAnimal("RedDog"); + System.out.println(animal); + + animal=animalStore.orderAnimal("GreenCat"); + System.out.println(animal); + + animal=animalStore.orderAnimal("RedCat"); + System.out.println(animal); + + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/RCFactory.java b/AnimalGames/src/AniamlGames/MVC/Animal/RCFactory.java new file mode 100644 index 0000000..afcf475 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/RCFactory.java @@ -0,0 +1,13 @@ +package AniamlGames.MVC.Animal; + +public class RCFactory implements AnimalIngredientFactory{ + @Override + public Race CreateRace() { + return new Cat(); + } + + @Override + public Color CreateColor() { + return new Red(); + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/RDFactory.java b/AnimalGames/src/AniamlGames/MVC/Animal/RDFactory.java new file mode 100644 index 0000000..437b1ae --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/RDFactory.java @@ -0,0 +1,13 @@ +package AniamlGames.MVC.Animal; + +public class RDFactory implements AnimalIngredientFactory { + @Override + public Race CreateRace() { + return new Dog(); + } + + @Override + public Color CreateColor() { + return new Red(); + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/Race.java b/AnimalGames/src/AniamlGames/MVC/Animal/Race.java new file mode 100644 index 0000000..0a1faf7 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/Race.java @@ -0,0 +1,5 @@ +package AniamlGames.MVC.Animal; + +public interface Race { + public String toString(); +} diff --git a/AnimalGames/src/AniamlGames/MVC/Animal/Red.java b/AnimalGames/src/AniamlGames/MVC/Animal/Red.java new file mode 100644 index 0000000..f2446dc --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/Animal/Red.java @@ -0,0 +1,8 @@ +package AniamlGames.MVC.Animal; + +public class Red implements Color { + @Override + public String toString() { + return "red"; + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/AnimalController.java b/AnimalGames/src/AniamlGames/MVC/AnimalController.java new file mode 100644 index 0000000..6824a9f --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/AnimalController.java @@ -0,0 +1,25 @@ +package AniamlGames.MVC; + +import AniamlGames.MVC.Animal.Animal; + +public class AnimalController { + private Animal model; + private AnimalViews view; + + public AnimalController(Animal model,AnimalViews view) { + this.model = model; + this.view = view; + } + + public void setAnimalName(String name){ + model.setAnimalName(name); + } + + public String getAnimalName(){ + return model.getAnimalName(); + } + + public void updateView(){ + view.printAnimalDetails(model.getAnimalName()); + } +} diff --git a/AnimalGames/src/AniamlGames/MVC/AnimalViews.java b/AnimalGames/src/AniamlGames/MVC/AnimalViews.java new file mode 100644 index 0000000..8d0f9d2 --- /dev/null +++ b/AnimalGames/src/AniamlGames/MVC/AnimalViews.java @@ -0,0 +1,7 @@ +package AniamlGames.MVC; + +public class AnimalViews { + public void printAnimalDetails(String AnimalName){ + System.out.println("Animal name:" + AnimalName); + } +} diff --git a/AnimalGames/src/Test/FlyweightPattern.java b/AnimalGames/src/Test/DetailTest/FlyweightPattern.java similarity index 99% rename from AnimalGames/src/Test/FlyweightPattern.java rename to AnimalGames/src/Test/DetailTest/FlyweightPattern.java index c882d48..8c9c1a5 100644 --- a/AnimalGames/src/Test/FlyweightPattern.java +++ b/AnimalGames/src/Test/DetailTest/FlyweightPattern.java @@ -1,4 +1,4 @@ -package Test; +package Test.DetailTest; import AniamlGames.Audience.DetailAudience.AudienceAttribute.AttributeFactory; import AniamlGames.Audience.DetailAudience.BirdAudience; diff --git a/AnimalGames/src/Test/DetailTest/MVCPattern.java b/AnimalGames/src/Test/DetailTest/MVCPattern.java new file mode 100644 index 0000000..808dbfe --- /dev/null +++ b/AnimalGames/src/Test/DetailTest/MVCPattern.java @@ -0,0 +1,34 @@ +package Test.DetailTest; + +import AniamlGames.MVC.Animal.Animal; +import AniamlGames.MVC.Animal.AnimalStore; +import AniamlGames.MVC.AnimalController; +import AniamlGames.MVC.AnimalViews; + +import java.util.Scanner; + +public class MVCPattern { + public static void main(String[] args) { + Animal model = getAniaml(); + + AnimalViews views = new AnimalViews(); + + AnimalController controller = new AnimalController(model,views); + + controller.updateView(); + + String str; + System.out.println("plz input new name:"); + Scanner sc = new Scanner(System.in); + str = sc.nextLine(); + controller.setAnimalName(str); + + controller.updateView(); + } + + private static Animal getAniaml(){ + AnimalStore animalStore=new AnimalStore(); + Animal animal=animalStore.orderAnimal("GreenDog"); + return animal; + } +} diff --git a/AnimalGames/src/Test/PrototypePattern.java b/AnimalGames/src/Test/DetailTest/PrototypePattern.java similarity index 99% rename from AnimalGames/src/Test/PrototypePattern.java rename to AnimalGames/src/Test/DetailTest/PrototypePattern.java index e414e3e..c20ca95 100644 --- a/AnimalGames/src/Test/PrototypePattern.java +++ b/AnimalGames/src/Test/DetailTest/PrototypePattern.java @@ -1,4 +1,4 @@ -package Test; +package Test.DetailTest; import AniamlGames.Audience.Audience; import AniamlGames.Audience.AudienceCache; diff --git a/AnimalGames/src/Test/TemplatePattern.java b/AnimalGames/src/Test/DetailTest/TemplatePattern.java similarity index 98% rename from AnimalGames/src/Test/TemplatePattern.java rename to AnimalGames/src/Test/DetailTest/TemplatePattern.java index 66a42be..3a2631a 100644 --- a/AnimalGames/src/Test/TemplatePattern.java +++ b/AnimalGames/src/Test/DetailTest/TemplatePattern.java @@ -1,4 +1,4 @@ -package Test; +package Test.DetailTest; import AniamlGames.Games.DetailGame.FourHundredMetersSwimming; import AniamlGames.Games.DetailGame.OneHundredMetersRunning; diff --git a/AnimalGames/src/Test/MainTest.java b/AnimalGames/src/Test/MainTest.java new file mode 100644 index 0000000..4a91c20 --- /dev/null +++ b/AnimalGames/src/Test/MainTest.java @@ -0,0 +1,33 @@ +package Test; + +import Test.DetailTest.FlyweightPattern; +import Test.DetailTest.MVCPattern; +import Test.DetailTest.PrototypePattern; +import Test.DetailTest.TemplatePattern; + +import java.util.Scanner; + +public class MainTest { + public static void main(String[] args) throws CloneNotSupportedException { + Boolean flag = true; + String str; + while (flag){ + System.out.println("plz input the number of patterns."); + System.out.println("1.flyweight 2.prototype 3.template 4.MVC Q.quit"); + Scanner sc = new Scanner(System.in); + str = sc.nextLine(); + switch (str){ + case "1": + FlyweightPattern.main(new String[]{});break; + case "2": + PrototypePattern.main(new String[]{});break; + case "3": + TemplatePattern.main(new String[]{});break; + case "4": + MVCPattern.main(new String[]{});break; + case "Q": + flag=false;break; + } + } + } +} From 892b9e29b806bd0f0e2cc617bf7e5b1c0542246e Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Wed, 25 Nov 2020 10:13:19 +0800 Subject: [PATCH 21/23] Update MVCPattern --- AnimalGames/MVCPattern | 91 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/AnimalGames/MVCPattern b/AnimalGames/MVCPattern index 674569f..36f9209 100644 --- a/AnimalGames/MVCPattern +++ b/AnimalGames/MVCPattern @@ -1 +1,90 @@ -7VvZcuI4FP0aHpPywpZHIEt3TzpDN5lkXgUWoEG2GFmE0F/fV7a8KoCd4HZCqEpVrGtZtnSOro6OTcMeuM83HC3n35mDacMynOeGfdmwLNOybPgnI5sw0u2YYWDGiaMqJYER+YVV0FDRFXGwn6koGKOCLLPBCfM8PBGZGOKcrbPVpoxm77pEM6wFRhNE9egjccRc9cLqJPEvmMzm0Z3N9kV4xkVRZdUTf44ctk6F7KuGPeCMifDIfR5gKgcvGpfHr5tHerto33z74f+P/un/dX/3cBY2dl3mkrgLHHvi1U3/Wkyvvzw0//t3Obz+sTZueuNvZ+oS4wnRlRqvIeY+81SPxSYaRn9NXIo8KPWnzBMjdQYGoY8omXlwPIGnwxwCT5gLAgj01AnBlhCdzAl1btGGrWQffIEmi6jUnzNOfkGziMIpEwJwmgtFJqudqTGSV0LYgCjHPtQZRgNjxqFb5AtVZ8IoRUufjIMHllVcxGfE6zMhmBs1xFaegx1VipEOCoKzRcwdeX1BOBRscjTwc4qMCp4bzFws+AaqqLMx0zbR5FPldUJcs61i8zRp7a6aMGqyzOK249v9hMmFvBkMQnI/O3e/ZsH7ASKZ2yEKwHtI4L4cRj9NQzhIdTUJBeQsQVRTI+odcrFGUxhpkaIkxVOxlZD+Ek2IN7sN6lw2k8hP1VMZYnDtlAZkmBPHwV5AFoEECvkkGbJkxBPBULT68AcDNjDOW40WPNAAymZShj9ZnYsB84BXiAQEwkDWNZaEfYFaO6ftfmptsoiVRTZNpAykZfGz9EQzZ54k493KHUPaODYkd2SUuXCpOqwK75ZVM962hveVi4i8rOc4kKP9E+AHBbzTrRnwpga4hjAlgX5Qo2G+uLbugd8FIGVzEd73kg6XZ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Fj5L0W7gCxeQX12H15Hfr9tVv \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 506b42587f5ee2df708a62762694b655a6c285ff Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Wed, 25 Nov 2020 10:23:17 +0800 Subject: [PATCH 22/23] Update MVCPattern --- AnimalGames/MVCPattern | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AnimalGames/MVCPattern b/AnimalGames/MVCPattern index 36f9209..38f8167 100644 --- a/AnimalGames/MVCPattern +++ b/AnimalGames/MVCPattern @@ -1,4 +1,4 @@ - + @@ -22,7 +22,7 @@ - + From 3a4c88cdbde882b4b7a51bcfdf2934a9282f0c25 Mon Sep 17 00:00:00 2001 From: Xinyu Cui Date: Thu, 26 Nov 2020 00:04:48 +0800 Subject: [PATCH 23/23] Update Audience.java --- AnimalGames/src/AniamlGames/Audience/Audience.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnimalGames/src/AniamlGames/Audience/Audience.java b/AnimalGames/src/AniamlGames/Audience/Audience.java index 57756d9..e7dd312 100644 --- a/AnimalGames/src/AniamlGames/Audience/Audience.java +++ b/AnimalGames/src/AniamlGames/Audience/Audience.java @@ -29,7 +29,7 @@ public void setAge(int age) { this.age = age; } - public String setSex(String sex) { + public void setSex(String sex) { this.sex = sex; }