From 4cda692beb962a5786fe29c092b0dcacb84e54b5 Mon Sep 17 00:00:00 2001 From: eunbb Date: Sat, 10 Aug 2024 19:21:08 +0900 Subject: [PATCH 1/3] test --- .DS_Store | Bin 0 -> 6148 bytes .idea/workspace.xml | 146 ++++++++++++++++++ second/.DS_Store | Bin 0 -> 6148 bytes second/out/.DS_Store | Bin 0 -> 6148 bytes second/out/production/.DS_Store | Bin 0 -> 6148 bytes .../out/production/second/Information.class | Bin 0 -> 636 bytes .../production/second/Spaceshipmanned.class | Bin 0 -> 1981 bytes .../production/second/Spaceshipunmanned.class | Bin 0 -> 1220 bytes third/.gitignore | 29 ++++ third/src/Main.java | 7 + 10 files changed, 182 insertions(+) create mode 100644 .DS_Store create mode 100644 .idea/workspace.xml create mode 100644 second/.DS_Store create mode 100644 second/out/.DS_Store create mode 100644 second/out/production/.DS_Store create mode 100644 second/out/production/second/Information.class create mode 100644 second/out/production/second/Spaceshipmanned.class create mode 100644 second/out/production/second/Spaceshipunmanned.class create mode 100644 third/.gitignore create mode 100644 third/src/Main.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..26b9337f3532234d8b1fb0d370eafb250f1e250a GIT binary patch literal 6148 zcmeHK%}T>S5Z-NTn^J@v6nb3nS}@k2h?h|73mDOZN^MNgV9b^#wTDv3SzpK}@p+ut z-5i1eZz6UEcE8#A+0A^A{b7vp(IPxx%w~*P&=5H)HG<|^SHlD&ay3WF!eE)rfx1Pjb>}B-LX1W&${!UU74{$}o>vxqQ5EwK~{^3TNEYNIfw?3{)9t>Y + + + + + + + + + + + + + + + + + + + + + + + { + "lastFilter": { + "state": "OPEN", + "assignee": "fakesilverpark" + } +} + { + "selectedUrlAndAccountId": { + "url": "https://github.com/fakesilverpark/SPACE_BE_COPILOT_gaeun", + "accountId": "fac8d3f0-ce2c-4627-bc74-0a36e7257d23" + } +} + { + "associatedIndex": 7 +} + + + + { + "keyToString": { + "Application.Main.executor": "Run", + "RunOnceActivity.ShowReadmeOnStart": "true", + "git-widget-placeholder": "gaeun2", + "kotlin-language-version-configured": "true", + "last_opened_file_path": "/Users/exn199/Desktop/space", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "settings.sync", + "vue.rearranger.settings.migration": "true", + "애플리케이션.Main.executor": "Coverage" + } +} + + + + + + + + + 1722514752769 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/second/.DS_Store b/second/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..97f30f26793a3590160aa789dba7587fd9e52f9b GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8rWBzE#U2;D7VJ-G5igV9b^#wTDp1Red0R5}(JJ z-L3S;LQh3>24=t6*_nj-5_WeOW4tx&Rv9ZY#w<|8Odf_G1lLg)Bx5`|K#tFd`d%PC zn0D) zT*|X z2JCLC#&@s3<{I~sq*||+Me`6#Y}huMjkywEbS+CuL<&qXb0z9T8i@g7fEZYT0kex* zg%x5cgcu+O{ucwdKL}7n$6%^aZ5=SE761^hkxIbEUIKH3LC0XK5mrFBP6gDd+_V^6 zr-NUZILBbBQKvI*nh$Q?%uR>F)!X6uLWMK#Xrz%CAO>a`$m(ek&;Qfq{r_wd&4>YF z;7>8Yb0_Xe3raF)>q2pO)(X&DP!x{(yPC-Hfl zNm8-29=wRy8JK*@{A|dVC6fSv@JG=eKotNSRKkLb%@QF$>4Frjg;3~kjNlG3h(STR z5Y2|a$N=r#2J~Todltc${R_v#ewe5b{cmAEiHBLE@h%F*(%O32DLWPCCU{WeAnRtM zq2C=`(db;MB%JlT;YHjVcdA<_D$Tla+8gMEIO<`@^<|t!YV4~~8Vz-BU>uI?xSeWk zGHJD%b-91onAYXwsM)B?)DlC@Q$P6$8KVpE+2Z>7PSNO zOAtznp2gfCdQgN(MKr0xJ~4zzN4vCfp2ggtNe7{4#_!mfg?*t2Jv-W^4hP{GS5Z-NTn^J@v6nb3nS}@k2h?h|73mDOZN^MNgV9b^#wTDv3SzpK}@p+ut z-5i1eZz6UEcE8#A+0A^A{b7vp(IPxx%w~*P&=5H)HG<|^SHlD&ay3WF!eE)rfx1Pjb>}B-LX1W&${!UU74{$}o>vxqQ5EwK~{^3TNEYNIfw?3{)9t>Y}F^7pMSoce*b)a0XWBzff(W%6cY)k4A~KX&UG%>^_YH z%b`BrgxVIOQsLFFsV<;ui#rVi8z^Wfn%G2%As^bWY8bQ!Sz!}Vq4FP~+G9{Iyj#M{ zw1sPRCQje-Z+PDhfxQ8@d)yZ?o+g#xUW^%1?WNZ?sLjv{qGxL3*~#d76MtZ}gfz=8 z=}#mn$~3+h4W7}W0n#3)l|YFyTXbsCt-LpCA7HiPH)zik#js6#I@BsqNUuZ14&{oG z8oSt|i0VRD>Ap{j$n%smVZRroYOm1Vkzbg~-w(1g=#z%#6m4dBFh^^WQfk#dSdl}D Tpwdf7>KsX(A~76NbqwWS)lzak literal 0 HcmV?d00001 diff --git a/second/out/production/second/Spaceshipmanned.class b/second/out/production/second/Spaceshipmanned.class new file mode 100644 index 0000000000000000000000000000000000000000..96e5ebd8f3136c997da29d07e8944b7ffa2b2336 GIT binary patch literal 1981 zcma)7TW=dh6#m9evi4@1G}kuGrEW=!ois6bXq*PpgwTMU790}VaGTiEcoTcq+8sya z4MBP1p)W{9P${ZZc;N*IDJ>G>nKym{&oO@hA>fR6eMu88mb^1__RKfueBU{JTi0!;z@=$h3@wwUWy&dro@jENZ}NDaTWj&ObWCe45nIv_ zV(6;8C`mIPpLQI+l{8(cLxZjmTN#4U*islr(59i?z)^HCw5N+aBix)>EO5&bSq7cE z(y=XGk}kth@2m=>LQAxw3*8!e4D{j{LtFhs^_q_0S;E*CqK@CF&P9j3bHDtEsN>Ly{yF{=(UL2+!zd{L1N?Y(kB81ZnQGM)x{d66} zIHTdLfkzd+9$EVl8MLCp&s!nH7&?CY@MiggugW*JBjxQ+_P*VjQ0$EwIEOK!&aCUR zzzc$*^Pn=FByHTlV|bk5Sb=Yd8QaQmxopZD&0NVXMf2IiG(89w!jlaB;ju{h&PRK9 zZ%stXpKq6Me;=uZ8N$;P1vz+@$lk~Amp{8X5mC%PYv4JYX9$^6I9%EeLvJ+JpzpkI zCyf)B)NsMT6rLx%y2e!(;wi`71@WFzJgSsUVA{Y%%rG=r6?1nLyHclq4QP0gAv|3z zun=A%|1ia?w3#>XvJ$4bB7u%sBn_lg-D+z>dJKot=9+HaLY-q+$s(voL3QoQJgq^IqYlM!>K3cCBDxW<(#)G-%r zTN0nVm=ZE)XWjM|ysLv_RYOMA9d+Yyy{k-X)7}vNwc(ZG9M4cOY%$zwEJEMW1HHtp zY+ks-N!#8i6%z*wv%#`&R?7sx-My4pj7~u(L^KN z(qy?pvlN0AzmAd7dtf6!K)ZSm;qPF4U2%Vvo^9j;glJPUL51-et$MvpNMn&!pabY) zAxPkLEcwv0D(?}`SPz{tI#Uv7(sE`b@3RycK~za9%^=ciIrdn`8>$Exb)*h!TB={sL>X(rK2%I`ZiI E8)`1*4gdfE literal 0 HcmV?d00001 diff --git a/second/out/production/second/Spaceshipunmanned.class b/second/out/production/second/Spaceshipunmanned.class new file mode 100644 index 0000000000000000000000000000000000000000..a1f4e874fb3959251f1879e0202cb1ad0489c5db GIT binary patch literal 1220 zcma)6T~E_s6n?88J3#PtWOdp7ZgZ(;vSMzXQ09Ss5(|NC+xu zMTnto-h5)&MJ{y9WC+dbrY`0fdg9qNzQL0QH&>I3!q&~zbYeMzFd`CU1#M6mIvXIH zj?jt>0jn&?yY8%8$%o`A$Y0~dbQm2Bae3;$E?Gt=x+KIDbbEPr*J2%KWROZ8zhQ>a z!_f8f#g6;@z}?zc-Tl|q&y`dJedw1kpx`tH39wk=In62PrLtM%rm5u_qWV$&3%sZ? z#F{IQQR~hs7{V|^Uy-kC8OzLZ@kkd1dUFIfg~Kp@QqP*n!Wdx~j7+KSyO-7XyD7DL zP;vLZseiK%<2*w@0qPdDy8X<3yOUDgH?Q2iZH8dR%2S@vtZr%x<>HEFFYy(lmbsPV z#xl2cPxp;MQP3&5?rc->X@&vkPe*D8b!-*_@x(HNyl9o}oOW0D0`xX!kO% znKv|NG;3MwQ51s0)q8_d0{(o!efe z`e7@jGE(PhitLQR9Y=E{%rJ~KRe4hK5>gC9|Ax{w)+@ybjd2T&AZkxqTTnMin}v60^+0*-dhLa01}w+xtZM4D)hS5%uJCH;aH_75Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + System.out.println("adf"); + } +} \ No newline at end of file From 72eaee691ea06b6209371424d1aabceebd95d723 Mon Sep 17 00:00:00 2001 From: eunbb Date: Mon, 12 Aug 2024 00:41:35 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat=20::=20=EC=9E=90=EC=9B=90=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EC=8B=9C=EC=8A=A4=ED=85=9C,=20=EC=83=9D=EB=AA=85?= =?UTF-8?q?=EC=B2=B4=20=EA=B4=80=EB=A6=AC=EC=8B=9C=EC=8A=A4=ED=85=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes second/.DS_Store | Bin 6148 -> 0 bytes second/out/.DS_Store | Bin 6148 -> 0 bytes second/out/production/.DS_Store | Bin 6148 -> 0 bytes .../out/production/second/Information.class | Bin 636 -> 0 bytes .../production/second/Spaceshipmanned.class | Bin 1981 -> 0 bytes .../production/second/Spaceshipunmanned.class | Bin 1220 -> 0 bytes third/.idea/.gitignore | 3 + third/.idea/misc.xml | 6 + third/.idea/modules.xml | 8 ++ third/.idea/vcs.xml | 6 + third/src/Creature.java | 34 ++++++ third/src/Main.java | 20 +++- third/src/Resource.java | 107 ++++++++++++++++++ third/third.iml | 11 ++ 15 files changed, 191 insertions(+), 4 deletions(-) delete mode 100644 second/.DS_Store delete mode 100644 second/out/.DS_Store delete mode 100644 second/out/production/.DS_Store delete mode 100644 second/out/production/second/Information.class delete mode 100644 second/out/production/second/Spaceshipmanned.class delete mode 100644 second/out/production/second/Spaceshipunmanned.class create mode 100644 third/.idea/.gitignore create mode 100644 third/.idea/misc.xml create mode 100644 third/.idea/modules.xml create mode 100644 third/.idea/vcs.xml create mode 100644 third/src/Creature.java create mode 100644 third/src/Resource.java create mode 100644 third/third.iml diff --git a/.DS_Store b/.DS_Store index 26b9337f3532234d8b1fb0d370eafb250f1e250a..66a747e3b2fea51305b3cc5be2d090d844468721 100644 GIT binary patch delta 90 zcmZoMXfc=|#>B)qu~2NHo+2a5#DLw41(+BaStj!^e&%FlC}GH8$Ydy*EX8;d!Q1?f kQI};iI|n}pQ0Hbwrti#?`9&-_7#SFVh=E~qfXEhR0OG3@Gynhq delta 68 zcmZoMXfc=|#>B`mu~2NHo+2aD#DLwC4MbQb^D}+e{F+&YWfRLA#?9;;{2V|vn?Evt XXP(S2V#&b(1dI#}Oq&BlwlD(#oo^A* diff --git a/second/.DS_Store b/second/.DS_Store deleted file mode 100644 index 97f30f26793a3590160aa789dba7587fd9e52f9b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z-O8rWBzE#U2;D7VJ-G5igV9b^#wTDp1Red0R5}(JJ z-L3S;LQh3>24=t6*_nj-5_WeOW4tx&Rv9ZY#w<|8Odf_G1lLg)Bx5`|K#tFd`d%PC zn0D) zT*|X z2JCLC#&@s3<{I~sq*||+Me`6#Y}huMjkywEbS+CuL<&qXb0z9T8i@g7fEZYT0kex* zg%x5cgcu+O{ucwdKL}7n$6%^aZ5=SE761^hkxIbEUIKH3LC0XK5mrFBP6gDd+_V^6 zr-NUZILBbBQKvI*nh$Q?%uR>F)!X6uLWMK#Xrz%CAO>a`$m(ek&;Qfq{r_wd&4>YF z;7>8Yb0_Xe3raF)>q2pO)(X&DP!x{(yPC-Hfl zNm8-29=wRy8JK*@{A|dVC6fSv@JG=eKotNSRKkLb%@QF$>4Frjg;3~kjNlG3h(STR z5Y2|a$N=r#2J~Todltc${R_v#ewe5b{cmAEiHBLE@h%F*(%O32DLWPCCU{WeAnRtM zq2C=`(db;MB%JlT;YHjVcdA<_D$Tla+8gMEIO<`@^<|t!YV4~~8Vz-BU>uI?xSeWk zGHJD%b-91onAYXwsM)B?)DlC@Q$P6$8KVpE+2Z>7PSNO zOAtznp2gfCdQgN(MKr0xJ~4zzN4vCfp2ggtNe7{4#_!mfg?*t2Jv-W^4hP{GS5Z-NTn^J@v6nb3nS}@k2h?h|73mDOZN^MNgV9b^#wTDv3SzpK}@p+ut z-5i1eZz6UEcE8#A+0A^A{b7vp(IPxx%w~*P&=5H)HG<|^SHlD&ay3WF!eE)rfx1Pjb>}B-LX1W&${!UU74{$}o>vxqQ5EwK~{^3TNEYNIfw?3{)9t>Y}F^7pMSoce*b)a0XWBzff(W%6cY)k4A~KX&UG%>^_YH z%b`BrgxVIOQsLFFsV<;ui#rVi8z^Wfn%G2%As^bWY8bQ!Sz!}Vq4FP~+G9{Iyj#M{ zw1sPRCQje-Z+PDhfxQ8@d)yZ?o+g#xUW^%1?WNZ?sLjv{qGxL3*~#d76MtZ}gfz=8 z=}#mn$~3+h4W7}W0n#3)l|YFyTXbsCt-LpCA7HiPH)zik#js6#I@BsqNUuZ14&{oG z8oSt|i0VRD>Ap{j$n%smVZRroYOm1Vkzbg~-w(1g=#z%#6m4dBFh^^WQfk#dSdl}D Tpwdf7>KsX(A~76NbqwWS)lzak diff --git a/second/out/production/second/Spaceshipmanned.class b/second/out/production/second/Spaceshipmanned.class deleted file mode 100644 index 96e5ebd8f3136c997da29d07e8944b7ffa2b2336..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1981 zcma)7TW=dh6#m9evi4@1G}kuGrEW=!ois6bXq*PpgwTMU790}VaGTiEcoTcq+8sya z4MBP1p)W{9P${ZZc;N*IDJ>G>nKym{&oO@hA>fR6eMu88mb^1__RKfueBU{JTi0!;z@=$h3@wwUWy&dro@jENZ}NDaTWj&ObWCe45nIv_ zV(6;8C`mIPpLQI+l{8(cLxZjmTN#4U*islr(59i?z)^HCw5N+aBix)>EO5&bSq7cE z(y=XGk}kth@2m=>LQAxw3*8!e4D{j{LtFhs^_q_0S;E*CqK@CF&P9j3bHDtEsN>Ly{yF{=(UL2+!zd{L1N?Y(kB81ZnQGM)x{d66} zIHTdLfkzd+9$EVl8MLCp&s!nH7&?CY@MiggugW*JBjxQ+_P*VjQ0$EwIEOK!&aCUR zzzc$*^Pn=FByHTlV|bk5Sb=Yd8QaQmxopZD&0NVXMf2IiG(89w!jlaB;ju{h&PRK9 zZ%stXpKq6Me;=uZ8N$;P1vz+@$lk~Amp{8X5mC%PYv4JYX9$^6I9%EeLvJ+JpzpkI zCyf)B)NsMT6rLx%y2e!(;wi`71@WFzJgSsUVA{Y%%rG=r6?1nLyHclq4QP0gAv|3z zun=A%|1ia?w3#>XvJ$4bB7u%sBn_lg-D+z>dJKot=9+HaLY-q+$s(voL3QoQJgq^IqYlM!>K3cCBDxW<(#)G-%r zTN0nVm=ZE)XWjM|ysLv_RYOMA9d+Yyy{k-X)7}vNwc(ZG9M4cOY%$zwEJEMW1HHtp zY+ks-N!#8i6%z*wv%#`&R?7sx-My4pj7~u(L^KN z(qy?pvlN0AzmAd7dtf6!K)ZSm;qPF4U2%Vvo^9j;glJPUL51-et$MvpNMn&!pabY) zAxPkLEcwv0D(?}`SPz{tI#Uv7(sE`b@3RycK~za9%^=ciIrdn`8>$Exb)*h!TB={sL>X(rK2%I`ZiI E8)`1*4gdfE diff --git a/second/out/production/second/Spaceshipunmanned.class b/second/out/production/second/Spaceshipunmanned.class deleted file mode 100644 index a1f4e874fb3959251f1879e0202cb1ad0489c5db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1220 zcma)6T~E_s6n?88J3#PtWOdp7ZgZ(;vSMzXQ09Ss5(|NC+xu zMTnto-h5)&MJ{y9WC+dbrY`0fdg9qNzQL0QH&>I3!q&~zbYeMzFd`CU1#M6mIvXIH zj?jt>0jn&?yY8%8$%o`A$Y0~dbQm2Bae3;$E?Gt=x+KIDbbEPr*J2%KWROZ8zhQ>a z!_f8f#g6;@z}?zc-Tl|q&y`dJedw1kpx`tH39wk=In62PrLtM%rm5u_qWV$&3%sZ? z#F{IQQR~hs7{V|^Uy-kC8OzLZ@kkd1dUFIfg~Kp@QqP*n!Wdx~j7+KSyO-7XyD7DL zP;vLZseiK%<2*w@0qPdDy8X<3yOUDgH?Q2iZH8dR%2S@vtZr%x<>HEFFYy(lmbsPV z#xl2cPxp;MQP3&5?rc->X@&vkPe*D8b!-*_@x(HNyl9o}oOW0D0`xX!kO% znKv|NG;3MwQ51s0)q8_d0{(o!efe z`e7@jGE(PhitLQR9Y=E{%rJ~KRe4hK5>gC9|Ax{w)+@ybjd2T&AZkxqTTnMin}v60^+0*-dhLa01}w+xtZM4D)hS5%uJCH;aH_75 + + + + + \ No newline at end of file diff --git a/third/.idea/modules.xml b/third/.idea/modules.xml new file mode 100644 index 0000000..b7cfb07 --- /dev/null +++ b/third/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/third/.idea/vcs.xml b/third/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/third/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/third/src/Creature.java b/third/src/Creature.java new file mode 100644 index 0000000..b60d824 --- /dev/null +++ b/third/src/Creature.java @@ -0,0 +1,34 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + +public class Creature { + private Map creatures = new HashMap<>(); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + void addCreature(String creatureName) throws IOException { + System.out.println("생명체의 이름: "+creatureName); + System.out.print("생명체의 정보: "); + String creatureInformation = br.readLine(); + creatures.put(creatureName,creatureInformation); + } + + void printCreature(String creatureName){ + if (creatures.containsKey(creatureName)){ + System.out.println(); + System.out.println("-------------------------"); + System.out.println(); + System.out.println(" 생명체 정보"); + System.out.println("\t- 생명체 이름: "+creatureName); + System.out.println("\t- 정보: "+creatures.get(creatureName)); + System.out.println(); + System.out.println("-------------------------"); + } + else{ + System.out.println(); + System.out.println(creatureName+"라는 이름의 생명체 정보를 조회할 수 없습니다."); + } + } +} diff --git a/third/src/Main.java b/third/src/Main.java index 7960bf8..25cbaf3 100644 --- a/third/src/Main.java +++ b/third/src/Main.java @@ -1,7 +1,19 @@ -//TIP To Run code, press or -// click the icon in the gutter. +import java.io.IOException; + public class Main { - public static void main(String[] args) { - System.out.println("adf"); + public static void main(String[] args) throws IOException { + Resource resource = new Resource(); + resource.putResource("apple"); + resource.addResourceQuantity("apple"); + resource.addResourceQuantity("banana"); + resource.useResourceQuantity("apple"); + resource.useResourceQuantity("banana"); + resource.printResourceInformation("apple"); + resource.printResourceInformation("banana"); + + Creature creature = new Creature(); + creature.addCreature("tiger"); + creature.printCreature("tiger"); + creature.printCreature("lion"); } } \ No newline at end of file diff --git a/third/src/Resource.java b/third/src/Resource.java new file mode 100644 index 0000000..b260015 --- /dev/null +++ b/third/src/Resource.java @@ -0,0 +1,107 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + +public class Resource { + private Map resources = new HashMap<>(); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public Resource(){ + } + + void setResource(String resourceName){ + System.out.println("\n현재 자원의 양: "+resources.get(resourceName)); + } + + void putResource(String resourceName) throws IOException { + System.out.println(); + System.out.println("자원이름: "+resourceName); + System.out.print("자원의 양: "); + String resourceQuantity = br.readLine(); + int resourceQuantityToSet=Integer.parseInt(resourceQuantity); + + if (resourceQuantityToSet<=0){ + System.out.println(); + System.out.println("양수로 입력해주세요"); + putResource(resourceName); + } + + else{ + resources.put(resourceName, resourceQuantityToSet); + } + } + + void addResourceQuantity(String resourceName) throws IOException { + if (resources.containsKey(resourceName)){ + setResource(resourceName); + System.out.print("더할 자원의 양: "); + String resourceQuantity = br.readLine(); + int resourceQuantityToAdd = Integer.parseInt(resourceQuantity); + + if (resourceQuantityToAdd<=0){ + System.out.println(); + System.out.println("양수로 입력해주세요"); + addResourceQuantity(resourceName); + } + + else{ + resources.replace(resourceName, resources.get(resourceName)+resourceQuantityToAdd); + } + } + else{ + System.out.println(); + System.out.print(resourceName+"라는 이름의 자원이 존재하지 않습니다."); + System.out.println(); + } + } + + void useResourceQuantity(String resourceName) throws IOException { + if (resources.containsKey(resourceName)){ + setResource(resourceName); + System.out.print("사용할 자원의 양: "); + String resourceQuantity = br.readLine(); + int resourceQuantityToUse = Integer.parseInt(resourceQuantity); + + if (resources.get(resourceName)-resourceQuantityToUse<=0){ + System.out.println(); + System.out.println("사용할 자원의 양이 현재 존재하는 자원의 양보다 많습니다."); + System.out.println("다시 입력해주세요."); + useResourceQuantity(resourceName); + } + else if (resourceQuantityToUse<=0) { + System.out.println(); + System.out.println("양수로 입력해주세요"); + useResourceQuantity(resourceName); + + } + else{ + resources.replace(resourceName, resources.get(resourceName)-Integer.parseInt(resourceQuantity)); + } + } + else{ + System.out.println(); + System.out.print(resourceName+"라는 이름의 자원이 존재하지 않습니다."); + System.out.println(); + } + } + + void printResourceInformation(String resourceName){ + if (resources.containsKey(resourceName)){ + System.out.println(); + System.out.println("-------------------------"); + System.out.println(); + System.out.println(" 자원 정보"); + System.out.println("\t- 자원 이름: "+resourceName); + System.out.println("\t- 자원의 양: "+resources.get(resourceName)); + System.out.println(); + System.out.println("-------------------------"); + } + else{ + System.out.println(); + System.out.println(resourceName+"라는 이름의 자원 정보를 조회할 수 없습니다."); + System.out.println(); + } + } +} diff --git a/third/third.iml b/third/third.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/third/third.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From 560287896957a833bb5fc2a89827afd1c1527707 Mon Sep 17 00:00:00 2001 From: eunbb Date: Mon, 12 Aug 2024 16:07:27 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat=20::=20=EC=9E=90=EC=9B=90=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EC=8B=9C=EC=8A=A4=ED=85=9C,=20=EC=83=9D=EB=AA=85?= =?UTF-8?q?=EC=B2=B4=20=EA=B4=80=EB=A6=AC=EC=8B=9C=EC=8A=A4=ED=85=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third/src/Creature.java | 58 ++++++----- third/src/Main.java | 32 ++++-- third/src/Management.java | 7 ++ third/src/Resource.java | 201 ++++++++++++++++++++++++-------------- 4 files changed, 190 insertions(+), 108 deletions(-) create mode 100644 third/src/Management.java diff --git a/third/src/Creature.java b/third/src/Creature.java index b60d824..bf7f496 100644 --- a/third/src/Creature.java +++ b/third/src/Creature.java @@ -4,31 +4,45 @@ import java.util.HashMap; import java.util.Map; -public class Creature { - private Map creatures = new HashMap<>(); +public class Creature implements Management { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private Map creatures = new HashMap<>(); - void addCreature(String creatureName) throws IOException { - System.out.println("생명체의 이름: "+creatureName); - System.out.print("생명체의 정보: "); - String creatureInformation = br.readLine(); - creatures.put(creatureName,creatureInformation); - } - - void printCreature(String creatureName){ - if (creatures.containsKey(creatureName)){ - System.out.println(); - System.out.println("-------------------------"); - System.out.println(); - System.out.println(" 생명체 정보"); - System.out.println("\t- 생명체 이름: "+creatureName); - System.out.println("\t- 정보: "+creatures.get(creatureName)); - System.out.println(); - System.out.println("-------------------------"); + //새로운 자원을 생성하는 메소드 + @Override + public void createElement(String elementName) throws IOException{ + if (creatures.containsKey(elementName)){ + System.out.println(elementName+"라는 이름의 생명체 정보가 이미 존재합니다."); } else{ - System.out.println(); - System.out.println(creatureName+"라는 이름의 생명체 정보를 조회할 수 없습니다."); + System.out.println("생명체의 이름: " + elementName); + System.out.print("생명체의 설명: "); + + String elementInformation = br.readLine(); + + creatures.put(elementName, elementInformation); + } + } + //자원을 삭제하는 메소드 + @Override + public void deleteElement(String elementName) { + if (creatures.containsKey(elementName)){ + creatures.remove(elementName); + } + else { + System.out.println(elementName+"라는 이름의 생명체 정보를 조회할 수 없습니다."); + } + } + //자원 정보를 출력하는 메소드 + @Override + public void printElements(String elementName) { + if (creatures.containsKey(elementName)){ + System.out.println("생명체 정보"); + System.out.println("\t생명체의 이름: "+elementName); + System.out.println("\t생명체의 설명: "+creatures.get(elementName)); + } + else { + System.out.println(elementName+"라는 이름의 생명체 정보를 조회할 수 없습니다."); } } -} +} \ No newline at end of file diff --git a/third/src/Main.java b/third/src/Main.java index 25cbaf3..7853043 100644 --- a/third/src/Main.java +++ b/third/src/Main.java @@ -3,17 +3,29 @@ public class Main { public static void main(String[] args) throws IOException { Resource resource = new Resource(); - resource.putResource("apple"); - resource.addResourceQuantity("apple"); - resource.addResourceQuantity("banana"); - resource.useResourceQuantity("apple"); - resource.useResourceQuantity("banana"); - resource.printResourceInformation("apple"); - resource.printResourceInformation("banana"); + + //입력된 숫자가 음수, 정수를 제외한 실수, 문자열, 공백이 존재하는 숫자라면 예외처리 됩니다. + + resource.createElement("apple"); + //같은 이름의 자원을 추가할 수 없습니다. + resource.createElement("apple"); + resource.addElementQuantity("apple"); + //존재하지 않는 자원의 양은 추가되지 않습니다. + resource.addElementQuantity("banana"); + resource.useElementQuantity("apple"); + //존재하지 않는 자원은 사용할 수 없습니다. + resource.useElementQuantity("banana"); + resource.printElements("apple"); + resource.deleteElement("apple"); + //자원이 제거되면 (= 자원이 존재하지 않으면) 그 자원에 대한 정보를 출력할 수 없습니다. + resource.printElements("apple"); Creature creature = new Creature(); - creature.addCreature("tiger"); - creature.printCreature("tiger"); - creature.printCreature("lion"); + creature.createElement("tiger"); + creature.printElements("tiger"); + creature.deleteElement("tiger"); + creature.printElements("tiger"); + creature.deleteElement("lion"); + } } \ No newline at end of file diff --git a/third/src/Management.java b/third/src/Management.java new file mode 100644 index 0000000..e798f14 --- /dev/null +++ b/third/src/Management.java @@ -0,0 +1,7 @@ +import java.io.IOException; + +public interface Management { + void printElements(String elementName); + void createElement(String elementName) throws IOException; + void deleteElement(String elementName); +} \ No newline at end of file diff --git a/third/src/Resource.java b/third/src/Resource.java index b260015..230c135 100644 --- a/third/src/Resource.java +++ b/third/src/Resource.java @@ -3,105 +3,154 @@ import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; +import java.util.NoSuchElementException; -public class Resource { - private Map resources = new HashMap<>(); +public class Resource implements Management{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private Map resources = new HashMap<>(); + private String elementErrorMessage; - public Resource(){ - } + //새로운 자원을 생성하는 메소드 + @Override + public void createElement(String elementName) { + if (resources.containsKey(elementName)){ + System.out.println(elementName+"라는 이름의 자원이 이미 존재합니다."); + } + else{ + try { + System.out.println("자원의 이름: " + elementName); + System.out.print("자원의 양: "); - void setResource(String resourceName){ - System.out.println("\n현재 자원의 양: "+resources.get(resourceName)); - } + String elementQuantityToSet = br.readLine(); - void putResource(String resourceName) throws IOException { - System.out.println(); - System.out.println("자원이름: "+resourceName); - System.out.print("자원의 양: "); - String resourceQuantity = br.readLine(); - int resourceQuantityToSet=Integer.parseInt(resourceQuantity); + elementErrorMessage = "자원의 양은 양수로 입력 되어야 합니다."; + int elementQuantity = validateElement(elementQuantityToSet,elementErrorMessage); - if (resourceQuantityToSet<=0){ - System.out.println(); - System.out.println("양수로 입력해주세요"); - putResource(resourceName); + System.out.println("현재 자원의 양: " + elementQuantity); + resources.put(elementName, elementQuantity); + + } catch (Exception e) { + handleExceptions(e); + } } + } - else{ - resources.put(resourceName, resourceQuantityToSet); + //자원을 삭제하는 메소드 + @Override + public void deleteElement(String elementName) { + if (resources.containsKey(elementName)){ + resources.remove(elementName); + } + else { + System.out.println(elementName+"라는 이름의 자원은 존재하지 않습니다."); } } - void addResourceQuantity(String resourceName) throws IOException { - if (resources.containsKey(resourceName)){ - setResource(resourceName); - System.out.print("더할 자원의 양: "); - String resourceQuantity = br.readLine(); - int resourceQuantityToAdd = Integer.parseInt(resourceQuantity); - - if (resourceQuantityToAdd<=0){ - System.out.println(); - System.out.println("양수로 입력해주세요"); - addResourceQuantity(resourceName); - } + //자원 정보를 출력하는 메소드 + @Override + public void printElements(String elementName) { + if (resources.containsKey(elementName)){ + System.out.println("자원 정보"); + System.out.println("\t자원 이름: "+elementName); + System.out.println("\t자원 양: "+resources.get(elementName)); + } + else { + System.out.println(elementName+"라는 이름의 자원 정보를 조회할 수 없습니다."); + } + } + + //자원의 양을 더하는 메소드 + public void addElementQuantity(String elementName) { + if (resources.containsKey(elementName)){ + try { + System.out.println("자원의 이름: " + elementName); + System.out.print("추가할 자원의 양: "); - else{ - resources.replace(resourceName, resources.get(resourceName)+resourceQuantityToAdd); + String elementQuantityToAdd = br.readLine(); + + elementErrorMessage = "추가할 자원의 양은 양수로 입력 되어야 합니다."; + int elementQuantity = validateElement(elementQuantityToAdd,elementErrorMessage); + elementQuantity = validateElement(String.valueOf(elementQuantity+resources.get(elementName)),elementErrorMessage); + + System.out.println("현재 자원의 양: " + elementQuantity); + resources.put(elementName, elementQuantity); + + } catch (Exception e) { + handleExceptions(e); + addElementQuantity(elementName); } } - else{ - System.out.println(); - System.out.print(resourceName+"라는 이름의 자원이 존재하지 않습니다."); - System.out.println(); + else { + System.out.println(elementName+"라는 이름의 자원은 존재하지 않습니다."); } } - void useResourceQuantity(String resourceName) throws IOException { - if (resources.containsKey(resourceName)){ - setResource(resourceName); - System.out.print("사용할 자원의 양: "); - String resourceQuantity = br.readLine(); - int resourceQuantityToUse = Integer.parseInt(resourceQuantity); - - if (resources.get(resourceName)-resourceQuantityToUse<=0){ - System.out.println(); - System.out.println("사용할 자원의 양이 현재 존재하는 자원의 양보다 많습니다."); - System.out.println("다시 입력해주세요."); - useResourceQuantity(resourceName); - } - else if (resourceQuantityToUse<=0) { - System.out.println(); - System.out.println("양수로 입력해주세요"); - useResourceQuantity(resourceName); + //자원을 사용하는 메소드 + public void useElementQuantity(String elementName) { + if (resources.containsKey(elementName)){ + try { + System.out.println("자원의 이름: " + elementName); + System.out.print("사용할 자원의 양: "); - } - else{ - resources.replace(resourceName, resources.get(resourceName)-Integer.parseInt(resourceQuantity)); + String elementQuantityToUse = br.readLine(); + + elementErrorMessage = "사용할 자원의 양은 양수로 입력 되어야 합니다."; + int elementQuantity = validateElement(elementQuantityToUse,elementErrorMessage); + elementErrorMessage = "사용할 자원의 양은 존재하는 자원의 양보다 많을 수 없습니다."; + elementQuantity = validateElement(String.valueOf(resources.get(elementName)-elementQuantity),elementErrorMessage); + + System.out.println("현재 자원의 양: " + elementQuantity); + resources.put(elementName, elementQuantity); + + } catch (Exception e) { + handleExceptions(e); + useElementQuantity(elementName); } } - else{ - System.out.println(); - System.out.print(resourceName+"라는 이름의 자원이 존재하지 않습니다."); - System.out.println(); + else { + System.out.println(elementName+"라는 이름의 자원은 존재하지 않습니다."); } } - void printResourceInformation(String resourceName){ - if (resources.containsKey(resourceName)){ - System.out.println(); - System.out.println("-------------------------"); - System.out.println(); - System.out.println(" 자원 정보"); - System.out.println("\t- 자원 이름: "+resourceName); - System.out.println("\t- 자원의 양: "+resources.get(resourceName)); - System.out.println(); - System.out.println("-------------------------"); + //확인하는 메소드 + private int validateElement(String elementQuantity, String elementErrorMessage) { + + //trim().isEmpty() -> 공백이 있는 문자열도 빈문자열도 체크할 수 있다. + //숫자는 중간에 비어있으면 안됨 + if (elementQuantity == null || elementQuantity.trim().isEmpty()) { + throw new NoSuchElementException("자원의 양을 입력 해주세요."); } - else{ - System.out.println(); - System.out.println(resourceName+"라는 이름의 자원 정보를 조회할 수 없습니다."); - System.out.println(); + + int quantity = Integer.parseInt(elementQuantity); + + if (quantity < 0) { + throw new IllegalArgumentException(elementErrorMessage); + } + + return quantity; + } + + // 예외를 처리하는 메소드 + private void handleExceptions(Exception e) { + + //instanceof 를 안쓰면 오류는 없지만 + //각 타입별로 catch 를 만들어야한다. + if (e instanceof NumberFormatException) { + System.out.println("정수를 적었는데 이 메세지가 뜨는 경우 숫자의 공백을 제거해주세요."); + } + + //음수인 경우 + else if (e instanceof IllegalArgumentException || e instanceof NoSuchElementException) { + System.out.println(e.getMessage()); + } + + //입출력 과정에서 발생할 수 있는 오류를 나타내는 예외 + else if (e instanceof IOException) { + System.out.println(e.getMessage()); + } + + else { + System.out.println(e.getMessage()); } } -} +} \ No newline at end of file