From 4ecde2d4fcc71a106e4a0066f0cbd6a1a32b5831 Mon Sep 17 00:00:00 2001 From: Cunoucu Date: Thu, 23 Nov 2023 16:12:03 +0100 Subject: [PATCH 1/9] Aggiunta la classe Euro e il file di gitignore --- .gitignore | 37 +++++++++++++++++++++++++++++++++++++ src/Euro.java | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 .gitignore create mode 100644 src/Euro.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8605526 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* diff --git a/src/Euro.java b/src/Euro.java new file mode 100644 index 0000000..1628c5c --- /dev/null +++ b/src/Euro.java @@ -0,0 +1,48 @@ + +public class Euro { + + + private long valore; + + public Euro(long euro, long cent) { + if (euro >= 0) { + valore = euro*100 + cent; + } else { + valore = euro*100 - cent; + } + } + + public Euro(double d) { + valore = (long)(d*100); + } + + public long getValore() { + return valore; + } + + public Euro somma(Euro e) { + this.valore = this.valore + e.getValore(); + return this; + } + + public Euro sottrai(Euro e) { + this.valore = this.valore - e.getValore(); + return this; + } + + public boolean ugualeA(Euro e){ + if (valore == e.getValore()) + return true; + else return false; + } + + public boolean minoreDi(Euro e){ + if (valore <= e.getValore()) + return true; + else return false; + } + + public String stampa(){ + return (double)valore/100 +" euro"; + } +} \ No newline at end of file From b0678d5d33f55e2bfcc19156dc0f92007e8c5b8d Mon Sep 17 00:00:00 2001 From: Dodomp <106491543+Dodomp@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:15:59 +0100 Subject: [PATCH 2/9] refactoring dei file nel package Code --- bin/ATM.class | Bin 2920 -> 0 bytes bin/ATMCaseStudy.class | Bin 456 -> 0 bytes bin/Account.class | Bin 1146 -> 0 bytes bin/BalanceInquiry.class | Bin 1116 -> 0 bytes bin/BankDatabase.class | Bin 1450 -> 0 bytes bin/CashDispenser.class | Bin 677 -> 0 bytes bin/Deposit.class | Bin 1997 -> 0 bytes bin/DepositSlot.class | Bin 343 -> 0 bytes bin/Keypad.class | Bin 535 -> 0 bytes bin/Screen.class | Bin 910 -> 0 bytes bin/Transaction.class | Bin 812 -> 0 bytes bin/Withdrawal.class | Bin 2489 -> 0 bytes src/{ => Code}/ATM.java | 1 + src/{ => Code}/ATMCaseStudy.java | 1 + src/{ => Code}/Account.java | 1 + src/{ => Code}/BalanceInquiry.java | 1 + src/{ => Code}/BankDatabase.java | 1 + src/{ => Code}/CashDispenser.java | 1 + src/{ => Code}/Deposit.java | 1 + src/{ => Code}/DepositSlot.java | 1 + src/{ => Code}/Euro.java | 1 + src/{ => Code}/Keypad.java | 1 + src/{ => Code}/Screen.java | 1 + src/{ => Code}/Transaction.java | 1 + src/{ => Code}/Withdrawal.java | 1 + 25 files changed, 13 insertions(+) delete mode 100644 bin/ATM.class delete mode 100644 bin/ATMCaseStudy.class delete mode 100644 bin/Account.class delete mode 100644 bin/BalanceInquiry.class delete mode 100644 bin/BankDatabase.class delete mode 100644 bin/CashDispenser.class delete mode 100644 bin/Deposit.class delete mode 100644 bin/DepositSlot.class delete mode 100644 bin/Keypad.class delete mode 100644 bin/Screen.class delete mode 100644 bin/Transaction.class delete mode 100644 bin/Withdrawal.class rename src/{ => Code}/ATM.java (99%) rename src/{ => Code}/ATMCaseStudy.java (98%) rename src/{ => Code}/Account.java (99%) rename src/{ => Code}/BalanceInquiry.java (99%) rename src/{ => Code}/BankDatabase.java (99%) rename src/{ => Code}/CashDispenser.java (99%) rename src/{ => Code}/Deposit.java (99%) rename src/{ => Code}/DepositSlot.java (99%) rename src/{ => Code}/Euro.java (98%) rename src/{ => Code}/Keypad.java (99%) rename src/{ => Code}/Screen.java (99%) rename src/{ => Code}/Transaction.java (99%) rename src/{ => Code}/Withdrawal.java (99%) diff --git a/bin/ATM.class b/bin/ATM.class deleted file mode 100644 index 76543bfde35c4daa304c3934c927eca8f833d61e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2920 zcmai0Yi}FJ6+J`JCcRp}l-h|U*QHwj0NitX9^;WbTCUZ{!yU2=XBTDhjB9elGem`Um=<=$9g?duEr6)ggHOaN9+>3!l-(FkR z*Jhl0O}RWnV1I5p>fjq)WmT)z9lubi63X7(%+8civn1X18R^TCtSfWB%bB6PzVF3 zVd>DIi9Ilqc#fe^4+H5ilrhl-Gl>xmH>!t$;qZ;~CiY@q65pmk5k(AK2;(o9*pCBA zj8USfBnB>pFI+Zp5ZzjE$5mnGin3IphTXZUEh|gXbM(CJO!#X~U0_#^WkOlwUc*gc zMqrPztSWYOL-lK3b0)6h8n-AjqZQfAt9o6oDt&~&p@G~^X%&3WaaYF&mkcWLJrghD zC`(U9YU~Esj2!Y zT)~(2dS2E71}PK-P8y39#X7NAv&z#8JWGbPYq>%3j#-+<4HHY6#=a+M==8j7Vg)Sy z)T;8cZmq$RWEEsn_yMnpF}t(xVs>6{b_uU)a<5Ukfoyj0l@z4FNY=eAD^B?vhg((8 z;Fi7qN=q|s=LZ=_$r0h1r8gtcO9SEv)B-6WDk^bqCVN>eh2`qfN5V*)fGC zaT|I1tqrmtOW{pc%&0YFEjj9rwb8Unk}b_9gP(ANa||py{#x0ScP!n3Qh1B*^K`c_ zlXbJ2mdcfI|E&9Z!||F1?%}>}2k!~= z3}ib!@X78pxRk^%b?<2-kre|E@V;L5fxzhhTGnZv-{_Qjw~ut+3j3ph5AiF#)vpDH z|L<0j7Q#Epp5`}eys`rqC^yzsI=4$3!DI z&ZW0;JRRRczy3LyeuUF2+c>j@0h(!=XSXm!bC~An7S7SUK=b)6T%>u4=J*ySz6dZ) z^7mQxY2XkNc$(HTWO9UmJvfD4w&OmG5y31Ge1~tDAp(3CQ=AE0`5N83R7ay5-Nb?P zA2HB9-NJ0Tg)AripFI9M&0GYueq(`eY(D-Q7sasy~{$2TJdH~BROetOzy{=wC{%xWUvtJAQ~ zN2AleBYZ~qEIh)!6@omef%2Ky#xL@ln0$l>Pq-Nx;&W~r4;eoG2p|5p@WpL>oIm?{ zaE87(VL84-Hurd6@AI;}$2{HV$q#TI4~hSM=H($4@ByylBfQF9a*Lyj-$u%@*5*bg h_ze{o+)uyJ;Hb;73yCk$$E+Ma*301U=!)U@{{e#?XM_L% diff --git a/bin/ATMCaseStudy.class b/bin/ATMCaseStudy.class deleted file mode 100644 index 607c10d4dd7fb15304bfa8a9ae6744532e8a1e0c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 456 zcmZut-AV#M7(KJDuDhLH!=Ros>RsS?-;=L0$I$yl5IZ)hiDy$~pc z+nz1z&7_V5YW3%EQFxc;f4b4!b6+V9lN_k$+pQJ)&6yHVQ<4eSx*e z&P54jP7L{uVis%h6T#DxpL70>>PDora&(c0M{;2$R$CKL!#;_5CON<%gifW<(4o(MiXYI# zn3S0K;0O3o#&yn&1S~Ie_St8xwf9~de*gLT3&1Npi6JBqdt=+9$E__!-zdLvH`W~t~)cj$Vr zS*X@(?e5k)0>;j$=OhqD+C&l=>ecFEa?p`uSKWi8;T^l@0`Yb*;0t!_9XrA8-#AgGKD71)a_a5cKxt-=7UoG_ z$bs9Fp3gFBt@YWC$JIVieNRZE{toCEQ^Y;d=#lgKiFpQ7E%)T_N`s5#us^$$OYJ zz

T;7_HB5OUX6VgUUOURLv)?k5|~J+6%rW^bA{^sWCTGayC;E7M>Tz>% diff --git a/bin/BalanceInquiry.class b/bin/BalanceInquiry.class deleted file mode 100644 index 48f8e6aac7e4689adac3e3b62b94bed3ef9ca787..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1116 zcmZ8gTT|0O6#f=kQbOd?3UUz$7qx`~UJ#{Rv`}&C6kq7@z74TP(?pY$k)P#Do$EuXZH8&lMTTh79e!!nr`|*uSuK3}V!!fT#)#%c#|* zA&|Ky#CkmLWyRL|Sqfybga|Z5Xo)ieb zrl1p;OhrK!4VYMBLxkKS&!SZwD|nz`Rlw-2XW$_o3FK7JrF2|1pkyE%ZN6HlsKA1O zH3d^_>wYBN1d>5fU{X(ZX4U)P2Q8`8E9uz8V+~uBu}jjx6Fj9B7f$%al~<>B7|N!t zv|@^U?UTHeTNI+XbruDV*QB-?Yzs`88|HszW}~ZB$yDig47^Y&NBdK%t6c*nP|93# zRqpj28N3qUP>n{a6W6eie4mISA0Cs}qDbC|(A*9sO;z#`=_ yvCY;?SjKCfsy4P6MKVbnY3%bRN2)p{F2`-;76YgP0v*zItMy8-B4FPrPBtH-0_K=s@q-BgBb}KS zh@Pu1c{U7mIitPuuXr_q7(31^+H7yc!A|T_S`Irnf};YRtFr7b5qhmKLz5|aQJ|;J zys(cyS}YaQpw70x0vlB`tI{tkd!{5u>(Vtvlvj1mI5-J9!y)ErFTr!wK$b(GLQFUq zQwY3$hB|lK8OAan5ls#Lm*Ie&{ug2EX zKAD4R>#&OkaNay4YE^i%c;_zhjPtb$Wf3rzeGNMsdk5zg64{qX7;oV$^c*^!>`tL4 zg^jP#JFDVR6;EzXZb@M)KNWt#{0O%3>|+g(H;PVbRFm(*C=wW8)M?hicI?o2&Lq_E zkl9LEM)5D4iM>A&H71^*cS~&G$n;PHyZav@HuU_yAqIM*kAHm^&j~i#3Z{_4CcZb5 zJca$}*9CX##xr3-(qkY02_kHy`HCP*o?aNgumL7*p~u3)0U!|}YzV`lzJSmup~-B2 z0|#e@KO#Q7t${;Nji)UkNsSm}ANxqZAKfgVy3RH;TOyJ;rbUnq$9YqoJ2*kKq2+Kc zKhSMyw@%_zs9>D92-)IVK?A3s@zJ#0Bm@}I#rm3{Ri9pX&LS78 zDpIrZ#n!6Q4NR_Wf~}>Dau>$hhGDm)*)1Pz+)}+ CIN&V+ diff --git a/bin/CashDispenser.class b/bin/CashDispenser.class deleted file mode 100644 index b8cedbabb217701eda2172f78400527c77edff6d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 677 zcmZva&2G~`6ot>kPC`>Bj??f{no`)6Ea(G3D^)>AmO?6#5D7MD;!N8qu3h}o_hH`+ z5>=%x`T#snmk4pjwkj&I8PB=C=YHo}{`Kej2EZ$Q?EzmuY z=W-{M(b3Mq;zR`*yZnhi^Y_PJMh71!GXdcnXB?%OjIy~5b7cYIR-hilc|=3wjgEA- zCtz*AoD0~ac&S>j&~ebh>Iz74u!4qwJJyk!*=wr_w9d0GZ(FLW5DAJn&8Cu%9MuG49Lc&G!dqRd$K&!rAau4hz+H`c#Go58W*3hRCc!)>UtU0?4ySvfthr7d1Kj99R z|CzVOWPP}Fnt9JlPc@HjJT7wANqoYa$+ymJ%DhL^hT)YAgZPfRePLa&Xu*W;F)oVr h2aLT*(AGa7?+)bMft(7oK_5TaZ@B!eFrcbo^DlP^aK8Wm diff --git a/bin/Deposit.class b/bin/Deposit.class deleted file mode 100644 index 57b0c3f71f0c14c3e68bdbb1340a34a706e145a4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1997 zcmZ`(+inwA6kU_Vu`>)Im;?w3^w0~~#&IYuq$J#oowNogq}X*EdV!PiAsI56v1Z1h zk^0i7enLeho_R!-N-FiCAJ9*#RMd6GV@N7hmd59@_daW_efjJ4AAbV44mXVf1L>;j z_@NV}F=XISGmu^=?a1*x1H*FL?|P8|qsq;e+U>};flU2wyjq}nyXV_*eOeu^C!zF~ zx0yNP1CAx?MF$2w>D}j^{)-49w!pE_&J+sg>^bx(b?d z-Bkv%b>Eh5O9qbKCx=7PrV|<%=_4Suquo#iW!u*B^aAi+M%z6GTBC#uAK~$SLIy?; z66|^QH034D_sPiosPC2CjRdBH0)M*`E%`wLp_~)|pRQ`X1w>Vg?UiO(Y6zIT)Dff!ccCI zjVPe=f~Gx(>lSX{rh#LLOVxK>8T1hj<*NBs24&V-Nn2MeRP_VdgAeG8n^?kUX?)81 z-KVsL8t%~E2^SOm_m!=j9mSF-{RbJ;4Lmp3{BH1;;ie45I%`%0iEYVTxz}8r7tKv2 zwtY|SiYMJL>Pw^A;;G}h!t*1#3G#GYU1)-3rz5rWl zm<`x=*vhF~Etc~u19voK(RSJ~>VC4lHyRX0=*M`=&1IqWu%%}!mq=rP(c6Ji%HV;4 zNwX3g=&IO%St=3J`o7L5oG=~;B-1acw<$3g>Tn~H_SUlO#EqJPG%(+{N}rN>sv(FX?1 z29sc`B}WerE2*ZEE?}IcnI3XO7|=b#)qtKq@js^z|4-o%ELt6o&qis@p2irzM|tuC zJ+;?(VX8RuJFD3v$Lo9kFh*D!5$Gb$PBaP!dVoMRj`}m-T#2Da>zI#;I!?`*?h2;XjrB}FA_zjmv ze}0B?G5hfzt`zlt57&y>TYI?8&51oM-Z=dXCyUv;Jh?!(<(|#wFOV%}zvSTyj1;qL zTxeE<(5&u|7l=JY^d|9UiF1mGritkc|Igwa@;HxK6xixBSm3IR%UH%0tl}zKxP~>{ z#6zBHH3~iai5e+<&7aPXNy~3yHRkyJ7T@vxhqNEV;A^a=aX*bY<8NeA)QbZ$$;^+8 zrd1PKiu#4@BQhtci9M`epZ*1@(U;Rdjbp=qNt+&@Q*kzy$fw4f-({9oaDsh0$!^s6 iL@(YOd{Z$hjymSlVcrH}R2;znU{XUOkSBB-z}CO7AjkIr diff --git a/bin/DepositSlot.class b/bin/DepositSlot.class deleted file mode 100644 index a2664ad97f3f37ceedeef3f28138881cd983b39d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 343 zcmYjMyH3ME5S(=`F*pe^`2#vY2!8;NhDT*357J_@mC z5V)Dyxt+P){rr0W0C0h6h=4G>=8dh5TNKuXP=t7`8=Vxod`#xqnsY}OoSV|POG5AP zXh~34cEu5T*d3vd0b!Dwl4slJjH`Q{6-=0>HrK^cSH|n#N9CSOO&F)0k!RvH^-bAu zVK;ooIh%%8?W6}nw6NPM=Ue0dj61PYza$PIM!5wDq>@zxLs5w^3HOiRu=CosBSGH= l6o!JMAA|5%6k!h&K_5O5_P#*9c*K7)>Li1|WZb&;zX8_XJgxu$ diff --git a/bin/Keypad.class b/bin/Keypad.class deleted file mode 100644 index 9b066e220ca842b7787e1c6ebbcc07d61efe2393..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 535 zcmZut%TB^T6g^WOEw#KweByHfEF^J@x-ps%i7skLTn;e7A*Cgy82KkR8kIy7KfsSN z-YLXrbTe}w=bU@*`S^T&2XKTv9U4RYTug?%t0T&g>GNA&bGX~9UAFt86EMW2I~>!W zZ-%{bAf1}s;jSzEI*|{hD}!T(NV(Eth@N;|VIqPB3pxxPNrvnnUIJ-kb!2|cvnQiK z3@qf3XV9d}P?$}WUag^4umfN4LEVIff>K{%ST6qysk9QHriB>d4C$tH#l?8g7XB4) zJAxtC^g7&WabK!@UW^7ea>QUXXLitSMo$FcKm-IhTmpq_fNgCBB6ko7;Pq7B26A$aTAAIARzZ0T%zW`@jWi$W) diff --git a/bin/Screen.class b/bin/Screen.class deleted file mode 100644 index a03675802694ce60d6bb59226365236d62e87a7e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 910 zcmaiyU2oGc7=@49v}v#JAsWT?V7a_A|6S}zz$Zy-Zgud|;< z^xmBclzQoD9f6Dc?)1o$Cp&67m1FvxM(^zSeiXX?xYHbzaS4kiYIEWGC(}qxY+Q!J zU_s2BPHJ|8_G>yL`jwn?EL_1g6ITTm6ZZVJjq9ig6ppk*z?}SwQu{Lr>zWU&>(=-? zHtuSQnNU2RM`glp;CV89J_%w?HyYjMpoA5+bY*q3wRK?OJ{l(0<|^w3F`H(iiFG26 zr5CH+1Kpc$b0$-&N~+tm@c=DCljAAf{!1I*&3My`?PR$5hVWX7GRrHv0#-kW!;yOF z>U&*CudbyVi6yY{d_{o4FTMnhCRc6Ff^%X06G|WWk%PriZ)@oSM>`d8zQ7e90xBG} z`5DzY&ZUp2Zk(ci=C_jnWvZ-%QBQRlgAUxlO;QAI{fl<{Jgq`n^*^*FEN9tvsMZBL q%vQT+d_{gQzxElc{ZnkbJ&$(yGV3#F=XX$t9eS7qeMDFeTR#DnORnGm diff --git a/bin/Transaction.class b/bin/Transaction.class deleted file mode 100644 index 1330b55e97b38711f909025f939758b75d82a158..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 812 zcmZuv+iuf96r8o4q)FUdnl?bMP;Q9@RFg76$`BRX9apK;07}Od?>XHWTpf<{)bA;di_ll zNBW(>=ID6Ay7^{26>tuckE#V5T^DWi1nkjx+JwNGiyG<%t-EMo#h{^!CRzerKZ;eU z?_35mPG9qrP|l_@jZA!b&uzeERf}(!?kvK_Ao#n z_nGxdJ|19`5j$avb47u+IoT@E4rklU?qctH@`Sf}Rr7wL|Bb+c8C6n;MQbC{2rgR- oJcO}lWLL?9?@Q$EJIVWadk(n6d&&EH=80P1>+goQ$T(al+exLike!egL^Tn^f12~R* zDgp|$i07 z)zD3u0-+w9A>P0j~*|J{_kdcwIU| z2up=-9Y>@>lr}4X&~OxQs5nNr%1);o|wb;F(SZYW@b{uDPyb1QQ zE)$eJD^2*C6A_$M(5#&+nCv>k6|<(XR4kW_97PPfxR}r|f{cn$Hm#4Dj&nHAj#)>` zam2JKJBqCqOJ5fYqMf--w~x6c%bxCw)5n;Cl$Nrc^(1`z6!pCBvV~L1fNWZCSU zMw@YQoAJ6O=gPBVafE6VcjC#lIiRqcb(i3Ux{2nL1Pa&Kb_6FM8LhaS4*xT zy12goRzdAGWS!@A+>o{1URhfW4$3OnQ(=Epbu7sKkFcRr_I%lm;HEU6S`Y;*Z#ZVb z^j2xY7%wduVp>=>q15EwU<8)zdeyHb$18A|of)#E85OrFHpceLnWrtemTEUPPeL{p zUg7x39U4SHP9v#+TyEaY)y8`dw(*_i@ZM@D&3sVHGs>4c)RbEFEzPZMzhFm8Q}8*N zrqFXVKJzqo^Q@y3u#=V>QG;EicB6?eCwyJ{XeLK1c**l6sl9lau}Eqk3@^rdMjP=g z)nh+n3o(XQalns6`F=H$2UYzo%XqCf$TQv>YT?!P9Gxvcqca+Qj4Ms@!{KH0q~z0s z*w>G6id3WImeKzZF<-*_x{Se%Z>NL(O`*ECmXUsneWWgUR0FATkJ?6Rg4DC-hby1S zwVA@|6AT)-z7-vsW1Rd56N81G<`V8wBsJ}xt!`-IS^ zBDhPR1|i&zCA>%IL-Y@}aA<{3VHJu3mhY&_C#>KiLh`9orSfA-ed%t57S6C(Bbdb)3WVLJ)D3)& zoA`nNe~H`pinH?#KEStx{t@r*DDeazd8O<2ky$U@6Y9trRPop=PJmwTvFNuMQHfw;mlsd)cyES|KkpGCMgRZ+ diff --git a/src/ATM.java b/src/Code/ATM.java similarity index 99% rename from src/ATM.java rename to src/Code/ATM.java index aa3d187..73c7c78 100644 --- a/src/ATM.java +++ b/src/Code/ATM.java @@ -1,3 +1,4 @@ +package Code; // ATM.java // Represents an automated teller machine diff --git a/src/ATMCaseStudy.java b/src/Code/ATMCaseStudy.java similarity index 98% rename from src/ATMCaseStudy.java rename to src/Code/ATMCaseStudy.java index b9033bd..c7d2213 100644 --- a/src/ATMCaseStudy.java +++ b/src/Code/ATMCaseStudy.java @@ -1,3 +1,4 @@ +package Code; // ATMCaseStudy.java // Driver program for the ATM case study diff --git a/src/Account.java b/src/Code/Account.java similarity index 99% rename from src/Account.java rename to src/Code/Account.java index c308eca..1eceec1 100644 --- a/src/Account.java +++ b/src/Code/Account.java @@ -1,3 +1,4 @@ +package Code; // Account.java // Represents a bank account diff --git a/src/BalanceInquiry.java b/src/Code/BalanceInquiry.java similarity index 99% rename from src/BalanceInquiry.java rename to src/Code/BalanceInquiry.java index d45fa6a..79fc813 100644 --- a/src/BalanceInquiry.java +++ b/src/Code/BalanceInquiry.java @@ -1,3 +1,4 @@ +package Code; // BalanceInquiry.java // Represents a balance inquiry ATM transaction diff --git a/src/BankDatabase.java b/src/Code/BankDatabase.java similarity index 99% rename from src/BankDatabase.java rename to src/Code/BankDatabase.java index 3978497..afe2357 100644 --- a/src/BankDatabase.java +++ b/src/Code/BankDatabase.java @@ -1,3 +1,4 @@ +package Code; // BankDatabase.java // Represents the bank account information database diff --git a/src/CashDispenser.java b/src/Code/CashDispenser.java similarity index 99% rename from src/CashDispenser.java rename to src/Code/CashDispenser.java index b249faf..0c75883 100644 --- a/src/CashDispenser.java +++ b/src/Code/CashDispenser.java @@ -1,3 +1,4 @@ +package Code; // CashDispenser.java // Represents the cash dispenser of the ATM diff --git a/src/Deposit.java b/src/Code/Deposit.java similarity index 99% rename from src/Deposit.java rename to src/Code/Deposit.java index 916ef70..7449ffa 100644 --- a/src/Deposit.java +++ b/src/Code/Deposit.java @@ -1,3 +1,4 @@ +package Code; // Deposit.java // Represents a deposit ATM transaction diff --git a/src/DepositSlot.java b/src/Code/DepositSlot.java similarity index 99% rename from src/DepositSlot.java rename to src/Code/DepositSlot.java index 64e02c2..fe065a4 100644 --- a/src/DepositSlot.java +++ b/src/Code/DepositSlot.java @@ -1,3 +1,4 @@ +package Code; // DepositSlot.java // Represents the deposit slot of the ATM diff --git a/src/Euro.java b/src/Code/Euro.java similarity index 98% rename from src/Euro.java rename to src/Code/Euro.java index 1628c5c..79dc153 100644 --- a/src/Euro.java +++ b/src/Code/Euro.java @@ -1,3 +1,4 @@ +package Code; public class Euro { diff --git a/src/Keypad.java b/src/Code/Keypad.java similarity index 99% rename from src/Keypad.java rename to src/Code/Keypad.java index cd035c7..151d46a 100644 --- a/src/Keypad.java +++ b/src/Code/Keypad.java @@ -1,3 +1,4 @@ +package Code; // Keypad.java // Represents the keypad of the ATM import java.util.Scanner; // program uses Scanner to obtain user input diff --git a/src/Screen.java b/src/Code/Screen.java similarity index 99% rename from src/Screen.java rename to src/Code/Screen.java index 44d3f30..4b559f3 100644 --- a/src/Screen.java +++ b/src/Code/Screen.java @@ -1,3 +1,4 @@ +package Code; // Screen.java // Represents the screen of the ATM diff --git a/src/Transaction.java b/src/Code/Transaction.java similarity index 99% rename from src/Transaction.java rename to src/Code/Transaction.java index 508fea8..7a33323 100644 --- a/src/Transaction.java +++ b/src/Code/Transaction.java @@ -1,3 +1,4 @@ +package Code; // Transaction.java // Abstract superclass Transaction represents an ATM transaction diff --git a/src/Withdrawal.java b/src/Code/Withdrawal.java similarity index 99% rename from src/Withdrawal.java rename to src/Code/Withdrawal.java index 6e0af62..211934b 100644 --- a/src/Withdrawal.java +++ b/src/Code/Withdrawal.java @@ -1,3 +1,4 @@ +package Code; // Withdrawal.java // Represents a withdrawal ATM transaction From 0622ab32ff45bbcd13da28ea394b58e8094bbb64 Mon Sep 17 00:00:00 2001 From: Cunoucu Date: Thu, 23 Nov 2023 16:20:14 +0100 Subject: [PATCH 3/9] Refactoring nel package GUI --- src/Code/{ => GUI}/ATM.java | 4 +++- src/Code/{ => GUI}/ATMCaseStudy.java | 2 +- src/Code/{ => GUI}/BalanceInquiry.java | 4 +++- src/Code/{ => GUI}/CashDispenser.java | 2 +- src/Code/{ => GUI}/Deposit.java | 4 +++- src/Code/{ => GUI}/DepositSlot.java | 2 +- src/Code/{ => GUI}/Keypad.java | 2 +- src/Code/{ => GUI}/Screen.java | 2 +- src/Code/{ => GUI}/Transaction.java | 4 +++- src/Code/{ => GUI}/Withdrawal.java | 4 +++- 10 files changed, 20 insertions(+), 10 deletions(-) rename src/Code/{ => GUI}/ATM.java (99%) rename src/Code/{ => GUI}/ATMCaseStudy.java (98%) rename src/Code/{ => GUI}/BalanceInquiry.java (98%) rename src/Code/{ => GUI}/CashDispenser.java (99%) rename src/Code/{ => GUI}/Deposit.java (98%) rename src/Code/{ => GUI}/DepositSlot.java (98%) rename src/Code/{ => GUI}/Keypad.java (98%) rename src/Code/{ => GUI}/Screen.java (98%) rename src/Code/{ => GUI}/Transaction.java (97%) rename src/Code/{ => GUI}/Withdrawal.java (99%) diff --git a/src/Code/ATM.java b/src/Code/GUI/ATM.java similarity index 99% rename from src/Code/ATM.java rename to src/Code/GUI/ATM.java index 73c7c78..03c9025 100644 --- a/src/Code/ATM.java +++ b/src/Code/GUI/ATM.java @@ -1,7 +1,9 @@ -package Code; +package Code.GUI; // ATM.java // Represents an automated teller machine +import Code.BankDatabase; + public class ATM { private boolean userAuthenticated; // whether user is authenticated diff --git a/src/Code/ATMCaseStudy.java b/src/Code/GUI/ATMCaseStudy.java similarity index 98% rename from src/Code/ATMCaseStudy.java rename to src/Code/GUI/ATMCaseStudy.java index c7d2213..bcf45f1 100644 --- a/src/Code/ATMCaseStudy.java +++ b/src/Code/GUI/ATMCaseStudy.java @@ -1,4 +1,4 @@ -package Code; +package Code.GUI; // ATMCaseStudy.java // Driver program for the ATM case study diff --git a/src/Code/BalanceInquiry.java b/src/Code/GUI/BalanceInquiry.java similarity index 98% rename from src/Code/BalanceInquiry.java rename to src/Code/GUI/BalanceInquiry.java index 79fc813..805c7d1 100644 --- a/src/Code/BalanceInquiry.java +++ b/src/Code/GUI/BalanceInquiry.java @@ -1,7 +1,9 @@ -package Code; +package Code.GUI; // BalanceInquiry.java // Represents a balance inquiry ATM transaction +import Code.BankDatabase; + public class BalanceInquiry extends Transaction { // BalanceInquiry constructor diff --git a/src/Code/CashDispenser.java b/src/Code/GUI/CashDispenser.java similarity index 99% rename from src/Code/CashDispenser.java rename to src/Code/GUI/CashDispenser.java index 0c75883..826e4ee 100644 --- a/src/Code/CashDispenser.java +++ b/src/Code/GUI/CashDispenser.java @@ -1,4 +1,4 @@ -package Code; +package Code.GUI; // CashDispenser.java // Represents the cash dispenser of the ATM diff --git a/src/Code/Deposit.java b/src/Code/GUI/Deposit.java similarity index 98% rename from src/Code/Deposit.java rename to src/Code/GUI/Deposit.java index 7449ffa..8cf2c8e 100644 --- a/src/Code/Deposit.java +++ b/src/Code/GUI/Deposit.java @@ -1,7 +1,9 @@ -package Code; +package Code.GUI; // Deposit.java // Represents a deposit ATM transaction +import Code.BankDatabase; + public class Deposit extends Transaction { private double amount; // amount to deposit diff --git a/src/Code/DepositSlot.java b/src/Code/GUI/DepositSlot.java similarity index 98% rename from src/Code/DepositSlot.java rename to src/Code/GUI/DepositSlot.java index fe065a4..ad34c2c 100644 --- a/src/Code/DepositSlot.java +++ b/src/Code/GUI/DepositSlot.java @@ -1,4 +1,4 @@ -package Code; +package Code.GUI; // DepositSlot.java // Represents the deposit slot of the ATM diff --git a/src/Code/Keypad.java b/src/Code/GUI/Keypad.java similarity index 98% rename from src/Code/Keypad.java rename to src/Code/GUI/Keypad.java index 151d46a..905beee 100644 --- a/src/Code/Keypad.java +++ b/src/Code/GUI/Keypad.java @@ -1,4 +1,4 @@ -package Code; +package Code.GUI; // Keypad.java // Represents the keypad of the ATM import java.util.Scanner; // program uses Scanner to obtain user input diff --git a/src/Code/Screen.java b/src/Code/GUI/Screen.java similarity index 98% rename from src/Code/Screen.java rename to src/Code/GUI/Screen.java index 4b559f3..405669b 100644 --- a/src/Code/Screen.java +++ b/src/Code/GUI/Screen.java @@ -1,4 +1,4 @@ -package Code; +package Code.GUI; // Screen.java // Represents the screen of the ATM diff --git a/src/Code/Transaction.java b/src/Code/GUI/Transaction.java similarity index 97% rename from src/Code/Transaction.java rename to src/Code/GUI/Transaction.java index 7a33323..ce102c6 100644 --- a/src/Code/Transaction.java +++ b/src/Code/GUI/Transaction.java @@ -1,7 +1,9 @@ -package Code; +package Code.GUI; // Transaction.java // Abstract superclass Transaction represents an ATM transaction +import Code.BankDatabase; + public abstract class Transaction { private int accountNumber; // indicates account involved diff --git a/src/Code/Withdrawal.java b/src/Code/GUI/Withdrawal.java similarity index 99% rename from src/Code/Withdrawal.java rename to src/Code/GUI/Withdrawal.java index 211934b..6f37c41 100644 --- a/src/Code/Withdrawal.java +++ b/src/Code/GUI/Withdrawal.java @@ -1,7 +1,9 @@ -package Code; +package Code.GUI; // Withdrawal.java // Represents a withdrawal ATM transaction +import Code.BankDatabase; + public class Withdrawal extends Transaction { private int amount; // amount to withdraw From ba7ffac95f53638199b30e398fd1160da2961e92 Mon Sep 17 00:00:00 2001 From: Dodomp <106491543+Dodomp@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:25:36 +0100 Subject: [PATCH 4/9] Refactoring packgage Business_logic --- src/Code/{ => Business_logic}/Euro.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/Code/{ => Business_logic}/Euro.java (96%) diff --git a/src/Code/Euro.java b/src/Code/Business_logic/Euro.java similarity index 96% rename from src/Code/Euro.java rename to src/Code/Business_logic/Euro.java index 79dc153..6edf75a 100644 --- a/src/Code/Euro.java +++ b/src/Code/Business_logic/Euro.java @@ -1,4 +1,4 @@ -package Code; +package Code.Business_logic; public class Euro { From ba56953510af43ee4c8880bdf64591c8ff6a0b2b Mon Sep 17 00:00:00 2001 From: stefanoamalberti Date: Thu, 23 Nov 2023 16:29:57 +0100 Subject: [PATCH 5/9] Effettuato il refactoring delle classi Account e BankDatabase --- src/Code/{ => Database}/Account.java | 24 ++++--- src/Code/{ => Database}/BankDatabase.java | 82 ++++++++++------------- src/Code/GUI/ATM.java | 2 +- src/Code/GUI/BalanceInquiry.java | 2 +- src/Code/GUI/Deposit.java | 2 +- src/Code/GUI/Transaction.java | 2 +- src/Code/GUI/Withdrawal.java | 2 +- 7 files changed, 55 insertions(+), 61 deletions(-) rename src/Code/{ => Database}/Account.java (79%) rename src/Code/{ => Database}/BankDatabase.java (56%) diff --git a/src/Code/Account.java b/src/Code/Database/Account.java similarity index 79% rename from src/Code/Account.java rename to src/Code/Database/Account.java index 1eceec1..a2e9b3a 100644 --- a/src/Code/Account.java +++ b/src/Code/Database/Account.java @@ -1,17 +1,19 @@ -package Code; +package Code.Database; // Account.java // Represents a bank account +import Code.Business_logic.Euro; + public class Account { private int accountNumber; // account number private int pin; // PIN for authentication - private double availableBalance; // funds available for withdrawal - private double totalBalance; // funds available + pending deposits + private Euro availableBalance; // funds available for withdrawal + private Euro totalBalance; // funds available + pending deposits // Account constructor initializes attributes public Account( int theAccountNumber, int thePIN, - double theAvailableBalance, double theTotalBalance ) + Euro theAvailableBalance, Euro theTotalBalance ) { accountNumber = theAccountNumber; pin = thePIN; @@ -29,28 +31,28 @@ public boolean validatePIN( int userPIN ) } // end method validatePIN // returns available balance - public double getAvailableBalance() + public Euro getAvailableBalance() { return availableBalance; } // end getAvailableBalance // returns the total balance - public double getTotalBalance() + public Euro getTotalBalance() { return totalBalance; } // end method getTotalBalance // credits an amount to the account - public void credit( double amount ) + public void credit( Euro amount ) { - totalBalance += amount; // add to total balance + totalBalance.somma(amount); // add to total balance } // end method credit // debits an amount from the account - public void debit( double amount ) + public void debit( Euro amount ) { - availableBalance -= amount; // subtract from available balance - totalBalance -= amount; // subtract from total balance + availableBalance.sottrai(amount); // subtract from available balance + totalBalance.sottrai(amount); // subtract from total balance } // end method debit // returns account number diff --git a/src/Code/BankDatabase.java b/src/Code/Database/BankDatabase.java similarity index 56% rename from src/Code/BankDatabase.java rename to src/Code/Database/BankDatabase.java index afe2357..20d9103 100644 --- a/src/Code/BankDatabase.java +++ b/src/Code/Database/BankDatabase.java @@ -1,27 +1,26 @@ -package Code; +package Code.Database; // BankDatabase.java + +import Code.Business_logic.Euro; + // Represents the bank account information database -public class BankDatabase -{ +public class BankDatabase { private Account accounts[]; // array of Accounts - + // no-argument BankDatabase constructor initializes accounts - public BankDatabase() - { - accounts = new Account[ 2 ]; // just 2 accounts for testing - accounts[ 0 ] = new Account( 12345, 54321, 1000.0, 1200.0 ); - accounts[ 1 ] = new Account( 98765, 56789, 200.0, 200.0 ); + public BankDatabase() { + accounts = new Account[2]; // just 2 accounts for testing + accounts[0] = new Account(12345, 54321, new Euro(1000.0), new Euro(1200.0)); + accounts[1] = new Account(98765, 56789, new Euro(200.0), new Euro(200.0)); } // end no-argument BankDatabase constructor - + // retrieve Account object containing specified account number - private Account getAccount( int accountNumber ) - { + private Account getAccount(int accountNumber) { // loop through accounts searching for matching account number - for ( Account currentAccount : accounts ) - { + for (Account currentAccount : accounts) { // return current account if match found - if ( currentAccount.getAccountNumber() == accountNumber ) + if (currentAccount.getAccountNumber() == accountNumber) return currentAccount; } // end for @@ -30,56 +29,49 @@ private Account getAccount( int accountNumber ) // determine whether user-specified account number and PIN match // those of an account in the database - public boolean authenticateUser( int userAccountNumber, int userPIN ) - { + public boolean authenticateUser(int userAccountNumber, int userPIN) { // attempt to retrieve the account with the account number - Account userAccount = getAccount( userAccountNumber ); + Account userAccount = getAccount(userAccountNumber); // if account exists, return result of Account method validatePIN - if ( userAccount != null ) - return userAccount.validatePIN( userPIN ); + if (userAccount != null) + return userAccount.validatePIN(userPIN); else return false; // account number not found, so return false } // end method authenticateUser // return available balance of Account with specified account number - public double getAvailableBalance( int userAccountNumber ) - { - return getAccount( userAccountNumber ).getAvailableBalance(); + public Euro getAvailableBalance(int userAccountNumber) { + return getAccount(userAccountNumber).getAvailableBalance(); } // end method getAvailableBalance // return total balance of Account with specified account number - public double getTotalBalance( int userAccountNumber ) - { - return getAccount( userAccountNumber ).getTotalBalance(); + public Euro getTotalBalance(int userAccountNumber) { + return getAccount(userAccountNumber).getTotalBalance(); } // end method getTotalBalance // credit an amount to Account with specified account number - public void credit( int userAccountNumber, double amount ) - { - getAccount( userAccountNumber ).credit( amount ); + public void credit(int userAccountNumber, Euro amount) { + getAccount(userAccountNumber).credit(amount); } // end method credit // debit an amount from of Account with specified account number - public void debit( int userAccountNumber, double amount ) - { - getAccount( userAccountNumber ).debit( amount ); + public void debit(int userAccountNumber, Euro amount) { + getAccount(userAccountNumber).debit(amount); } // end method debit } // end class BankDatabase - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/ATM.java b/src/Code/GUI/ATM.java index 03c9025..d6a1719 100644 --- a/src/Code/GUI/ATM.java +++ b/src/Code/GUI/ATM.java @@ -2,7 +2,7 @@ // ATM.java // Represents an automated teller machine -import Code.BankDatabase; +import Code.Database.BankDatabase; public class ATM { diff --git a/src/Code/GUI/BalanceInquiry.java b/src/Code/GUI/BalanceInquiry.java index 805c7d1..c0813ae 100644 --- a/src/Code/GUI/BalanceInquiry.java +++ b/src/Code/GUI/BalanceInquiry.java @@ -2,7 +2,7 @@ // BalanceInquiry.java // Represents a balance inquiry ATM transaction -import Code.BankDatabase; +import Code.Database.BankDatabase; public class BalanceInquiry extends Transaction { diff --git a/src/Code/GUI/Deposit.java b/src/Code/GUI/Deposit.java index 8cf2c8e..4045092 100644 --- a/src/Code/GUI/Deposit.java +++ b/src/Code/GUI/Deposit.java @@ -2,7 +2,7 @@ // Deposit.java // Represents a deposit ATM transaction -import Code.BankDatabase; +import Code.Database.BankDatabase; public class Deposit extends Transaction { diff --git a/src/Code/GUI/Transaction.java b/src/Code/GUI/Transaction.java index ce102c6..3c41a84 100644 --- a/src/Code/GUI/Transaction.java +++ b/src/Code/GUI/Transaction.java @@ -2,7 +2,7 @@ // Transaction.java // Abstract superclass Transaction represents an ATM transaction -import Code.BankDatabase; +import Code.Database.BankDatabase; public abstract class Transaction { diff --git a/src/Code/GUI/Withdrawal.java b/src/Code/GUI/Withdrawal.java index 6f37c41..686c7a9 100644 --- a/src/Code/GUI/Withdrawal.java +++ b/src/Code/GUI/Withdrawal.java @@ -2,7 +2,7 @@ // Withdrawal.java // Represents a withdrawal ATM transaction -import Code.BankDatabase; +import Code.Database.BankDatabase; public class Withdrawal extends Transaction { From f6cc644e7c7e9efedb9628ff9031fd495378566b Mon Sep 17 00:00:00 2001 From: Cunoucu Date: Thu, 23 Nov 2023 16:37:55 +0100 Subject: [PATCH 6/9] Implementata la classe Euro nel progetto --- src/Code/Business_logic/Euro.java | 4 ++++ src/Code/GUI/BalanceInquiry.java | 9 +++++---- src/Code/GUI/Deposit.java | 3 ++- src/Code/GUI/Withdrawal.java | 7 ++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Code/Business_logic/Euro.java b/src/Code/Business_logic/Euro.java index 6edf75a..24d5860 100644 --- a/src/Code/Business_logic/Euro.java +++ b/src/Code/Business_logic/Euro.java @@ -21,6 +21,10 @@ public long getValore() { return valore; } + public double getValoreDouble() { + return (double)valore/100; + } + public Euro somma(Euro e) { this.valore = this.valore + e.getValore(); return this; diff --git a/src/Code/GUI/BalanceInquiry.java b/src/Code/GUI/BalanceInquiry.java index c0813ae..cd57c15 100644 --- a/src/Code/GUI/BalanceInquiry.java +++ b/src/Code/GUI/BalanceInquiry.java @@ -2,6 +2,7 @@ // BalanceInquiry.java // Represents a balance inquiry ATM transaction +import Code.Business_logic.Euro; import Code.Database.BankDatabase; public class BalanceInquiry extends Transaction @@ -21,19 +22,19 @@ public void execute() Screen screen = getScreen(); // get the available balance for the account involved - double availableBalance = + Euro availableBalance = bankDatabase.getAvailableBalance( getAccountNumber() ); // get the total balance for the account involved - double totalBalance = + Euro totalBalance = bankDatabase.getTotalBalance( getAccountNumber() ); // display the balance information on the screen screen.displayMessageLine( "\nBalance Information:" ); screen.displayMessage( " - Available balance: " ); - screen.displayDollarAmount( availableBalance ); + screen.displayDollarAmount( availableBalance.getValoreDouble() ); screen.displayMessage( "\n - Total balance: " ); - screen.displayDollarAmount( totalBalance ); + screen.displayDollarAmount( totalBalance.getValoreDouble() ); screen.displayMessageLine( "" ); } // end method execute } // end class BalanceInquiry diff --git a/src/Code/GUI/Deposit.java b/src/Code/GUI/Deposit.java index 4045092..7a43096 100644 --- a/src/Code/GUI/Deposit.java +++ b/src/Code/GUI/Deposit.java @@ -2,6 +2,7 @@ // Deposit.java // Represents a deposit ATM transaction +import Code.Business_logic.Euro; import Code.Database.BankDatabase; public class Deposit extends Transaction @@ -53,7 +54,7 @@ public void execute() "enclosed cash and your checks clear." ); // credit account to reflect the deposit - bankDatabase.credit( getAccountNumber(), amount ); + bankDatabase.credit( getAccountNumber(), new Euro(amount) ); } // end if else // deposit envelope not received { diff --git a/src/Code/GUI/Withdrawal.java b/src/Code/GUI/Withdrawal.java index 686c7a9..3e81a09 100644 --- a/src/Code/GUI/Withdrawal.java +++ b/src/Code/GUI/Withdrawal.java @@ -2,6 +2,7 @@ // Withdrawal.java // Represents a withdrawal ATM transaction +import Code.Business_logic.Euro; import Code.Database.BankDatabase; public class Withdrawal extends Transaction @@ -30,7 +31,7 @@ public Withdrawal( int userAccountNumber, Screen atmScreen, public void execute() { boolean cashDispensed = false; // cash was not dispensed yet - double availableBalance; // amount available for withdrawal + Euro availableBalance; // amount available for withdrawal // get references to bank database and screen BankDatabase bankDatabase = getBankDatabase(); @@ -50,13 +51,13 @@ public void execute() bankDatabase.getAvailableBalance( getAccountNumber() ); // check whether the user has enough money in the account - if ( amount <= availableBalance ) + if ( new Euro(amount).minoreDi(availableBalance)) { // check whether the cash dispenser has enough money if ( cashDispenser.isSufficientCashAvailable( amount ) ) { // update the account involved to reflect withdrawal - bankDatabase.debit( getAccountNumber(), amount ); + bankDatabase.debit( getAccountNumber(), new Euro(amount) ); cashDispenser.dispenseCash( amount ); // dispense cash cashDispensed = true; // cash was dispensed From cce80ee67ca2eaba7d0a0570baaea70f6d8c6ef2 Mon Sep 17 00:00:00 2001 From: Cunoucu Date: Thu, 23 Nov 2023 16:59:14 +0100 Subject: [PATCH 7/9] Formattati tutti i file cpp del progetto --- src/Code/Business_logic/Euro.java | 25 ++--- src/Code/Database/Account.java | 56 +++++------- src/Code/GUI/ATM.java | 146 +++++++++++++----------------- src/Code/GUI/ATMCaseStudy.java | 35 ++++--- src/Code/GUI/BalanceInquiry.java | 58 ++++++------ src/Code/GUI/CashDispenser.java | 43 ++++----- src/Code/GUI/Deposit.java | 92 +++++++++---------- src/Code/GUI/DepositSlot.java | 33 +++---- src/Code/GUI/Keypad.java | 44 ++++----- src/Code/GUI/Screen.java | 45 ++++----- src/Code/GUI/Transaction.java | 46 ++++------ src/Code/GUI/Withdrawal.java | 132 ++++++++++++--------------- 12 files changed, 340 insertions(+), 415 deletions(-) diff --git a/src/Code/Business_logic/Euro.java b/src/Code/Business_logic/Euro.java index 24d5860..a8f1260 100644 --- a/src/Code/Business_logic/Euro.java +++ b/src/Code/Business_logic/Euro.java @@ -2,19 +2,18 @@ public class Euro { - private long valore; public Euro(long euro, long cent) { if (euro >= 0) { - valore = euro*100 + cent; + valore = euro * 100 + cent; } else { - valore = euro*100 - cent; + valore = euro * 100 - cent; } } public Euro(double d) { - valore = (long)(d*100); + valore = (long) (d * 100); } public long getValore() { @@ -22,7 +21,7 @@ public long getValore() { } public double getValoreDouble() { - return (double)valore/100; + return (double) valore / 100; } public Euro somma(Euro e) { @@ -35,19 +34,21 @@ public Euro sottrai(Euro e) { return this; } - public boolean ugualeA(Euro e){ + public boolean ugualeA(Euro e) { if (valore == e.getValore()) return true; - else return false; + else + return false; } - - public boolean minoreDi(Euro e){ + + public boolean minoreDi(Euro e) { if (valore <= e.getValore()) return true; - else return false; + else + return false; } - public String stampa(){ - return (double)valore/100 +" euro"; + public String stampa() { + return (double) valore / 100 + " euro"; } } \ No newline at end of file diff --git a/src/Code/Database/Account.java b/src/Code/Database/Account.java index a2e9b3a..7f1b241 100644 --- a/src/Code/Database/Account.java +++ b/src/Code/Database/Account.java @@ -1,20 +1,19 @@ package Code.Database; // Account.java + // Represents a bank account import Code.Business_logic.Euro; -public class Account -{ +public class Account { private int accountNumber; // account number private int pin; // PIN for authentication private Euro availableBalance; // funds available for withdrawal private Euro totalBalance; // funds available + pending deposits // Account constructor initializes attributes - public Account( int theAccountNumber, int thePIN, - Euro theAvailableBalance, Euro theTotalBalance ) - { + public Account(int theAccountNumber, int thePIN, + Euro theAvailableBalance, Euro theTotalBalance) { accountNumber = theAccountNumber; pin = thePIN; availableBalance = theAvailableBalance; @@ -22,58 +21,51 @@ public Account( int theAccountNumber, int thePIN, } // end Account constructor // determines whether a user-specified PIN matches PIN in Account - public boolean validatePIN( int userPIN ) - { - if ( userPIN == pin ) + public boolean validatePIN(int userPIN) { + if (userPIN == pin) return true; else return false; } // end method validatePIN - + // returns available balance - public Euro getAvailableBalance() - { + public Euro getAvailableBalance() { return availableBalance; } // end getAvailableBalance // returns the total balance - public Euro getTotalBalance() - { + public Euro getTotalBalance() { return totalBalance; } // end method getTotalBalance // credits an amount to the account - public void credit( Euro amount ) - { + public void credit(Euro amount) { totalBalance.somma(amount); // add to total balance } // end method credit // debits an amount from the account - public void debit( Euro amount ) - { + public void debit(Euro amount) { availableBalance.sottrai(amount); // subtract from available balance totalBalance.sottrai(amount); // subtract from total balance } // end method debit // returns account number - public int getAccountNumber() - { - return accountNumber; + public int getAccountNumber() { + return accountNumber; } // end method getAccountNumber } // end class Account - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/ATM.java b/src/Code/GUI/ATM.java index d6a1719..556521a 100644 --- a/src/Code/GUI/ATM.java +++ b/src/Code/GUI/ATM.java @@ -1,11 +1,11 @@ package Code.GUI; // ATM.java + // Represents an automated teller machine import Code.Database.BankDatabase; -public class ATM -{ +public class ATM { private boolean userAuthenticated; // whether user is authenticated private int currentAccountNumber; // current user's account number private Screen screen; // ATM's screen @@ -21,130 +21,116 @@ public class ATM private static final int EXIT = 4; // no-argument ATM constructor initializes instance variables - public ATM() - { + public ATM() { userAuthenticated = false; // user is not authenticated to start currentAccountNumber = 0; // no current account number to start screen = new Screen(); // create screen - keypad = new Keypad(); // create keypad + keypad = new Keypad(); // create keypad cashDispenser = new CashDispenser(); // create cash dispenser depositSlot = new DepositSlot(); // create deposit slot bankDatabase = new BankDatabase(); // create acct info database } // end no-argument ATM constructor - // start ATM - public void run() - { + // start ATM + public void run() { // welcome and authenticate user; perform transactions - while ( true ) - { + while (true) { // loop while user is not yet authenticated - while ( !userAuthenticated ) - { - screen.displayMessageLine( "\nWelcome!" ); + while (!userAuthenticated) { + screen.displayMessageLine("\nWelcome!"); authenticateUser(); // authenticate user } // end while - - performTransactions(); // user is now authenticated + + performTransactions(); // user is now authenticated userAuthenticated = false; // reset before next ATM session - currentAccountNumber = 0; // reset before next ATM session - screen.displayMessageLine( "\nThank you! Goodbye!" ); - } // end while + currentAccountNumber = 0; // reset before next ATM session + screen.displayMessageLine("\nThank you! Goodbye!"); + } // end while } // end method run // attempts to authenticate user against database - private void authenticateUser() - { - screen.displayMessage( "\nPlease enter your account number: " ); + private void authenticateUser() { + screen.displayMessage("\nPlease enter your account number: "); int accountNumber = keypad.getInput(); // input account number - screen.displayMessage( "\nEnter your PIN: " ); // prompt for PIN + screen.displayMessage("\nEnter your PIN: "); // prompt for PIN int pin = keypad.getInput(); // input PIN - + // set userAuthenticated to boolean value returned by database - userAuthenticated = - bankDatabase.authenticateUser( accountNumber, pin ); - + userAuthenticated = bankDatabase.authenticateUser(accountNumber, pin); + // check whether authentication succeeded - if ( userAuthenticated ) - { + if (userAuthenticated) { currentAccountNumber = accountNumber; // save user's account # } // end if else - screen.displayMessageLine( - "Invalid account number or PIN. Please try again." ); + screen.displayMessageLine( + "Invalid account number or PIN. Please try again."); } // end method authenticateUser // display the main menu and perform transactions - private void performTransactions() - { + private void performTransactions() { // local variable to store transaction currently being processed Transaction currentTransaction = null; - + boolean userExited = false; // user has not chosen to exit // loop while user has not chosen option to exit system - while ( !userExited ) - { + while (!userExited) { // show main menu and get user selection int mainMenuSelection = displayMainMenu(); // decide how to proceed based on user's menu selection - switch ( mainMenuSelection ) - { + switch (mainMenuSelection) { // user chose to perform one of three transaction types - case BALANCE_INQUIRY: - case WITHDRAWAL: + case BALANCE_INQUIRY: + case WITHDRAWAL: case DEPOSIT: // initialize as new object of chosen type - currentTransaction = - createTransaction( mainMenuSelection ); + currentTransaction = createTransaction(mainMenuSelection); currentTransaction.execute(); // execute transaction - break; + break; case EXIT: // user chose to terminate session - screen.displayMessageLine( "\nExiting the system..." ); + screen.displayMessageLine("\nExiting the system..."); userExited = true; // this ATM session should end break; default: // user did not enter an integer from 1-4 - screen.displayMessageLine( - "\nYou did not enter a valid selection. Try again." ); + screen.displayMessageLine( + "\nYou did not enter a valid selection. Try again."); break; } // end switch } // end while } // end method performTransactions - + // display the main menu and return an input selection - private int displayMainMenu() - { - screen.displayMessageLine( "\nMain menu:" ); - screen.displayMessageLine( "1 - View my balance" ); - screen.displayMessageLine( "2 - Withdraw cash" ); - screen.displayMessageLine( "3 - Deposit funds" ); - screen.displayMessageLine( "4 - Exit\n" ); - screen.displayMessage( "Enter a choice: " ); + private int displayMainMenu() { + screen.displayMessageLine("\nMain menu:"); + screen.displayMessageLine("1 - View my balance"); + screen.displayMessageLine("2 - Withdraw cash"); + screen.displayMessageLine("3 - Deposit funds"); + screen.displayMessageLine("4 - Exit\n"); + screen.displayMessage("Enter a choice: "); return keypad.getInput(); // return user's selection } // end method displayMainMenu - + // return object of specified Transaction subclass - private Transaction createTransaction( int type ) - { + private Transaction createTransaction(int type) { Transaction temp = null; // temporary Transaction variable - - // determine which type of Transaction to create - switch ( type ) - { + + // determine which type of Transaction to create + switch (type) { case BALANCE_INQUIRY: // create new BalanceInquiry transaction - temp = new BalanceInquiry( - currentAccountNumber, screen, bankDatabase ); + temp = new BalanceInquiry( + currentAccountNumber, screen, bankDatabase); break; case WITHDRAWAL: // create new Withdrawal transaction - temp = new Withdrawal( currentAccountNumber, screen, - bankDatabase, keypad, cashDispenser ); - break; + temp = new Withdrawal(currentAccountNumber, screen, + bankDatabase, keypad, cashDispenser); + break; case DEPOSIT: // create new Deposit transaction - temp = new Deposit( currentAccountNumber, screen, - bankDatabase, keypad, depositSlot ); + temp = new Deposit(currentAccountNumber, screen, + bankDatabase, keypad, depositSlot); break; } // end switch @@ -152,19 +138,17 @@ private Transaction createTransaction( int type ) } // end method createTransaction } // end class ATM - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/ATMCaseStudy.java b/src/Code/GUI/ATMCaseStudy.java index bcf45f1..75b061a 100644 --- a/src/Code/GUI/ATMCaseStudy.java +++ b/src/Code/GUI/ATMCaseStudy.java @@ -1,30 +1,27 @@ package Code.GUI; // ATMCaseStudy.java + // Driver program for the ATM case study -public class ATMCaseStudy -{ +public class ATMCaseStudy { // main method creates and runs the ATM - public static void main( String[] args ) - { - ATM theATM = new ATM(); + public static void main(String[] args) { + ATM theATM = new ATM(); theATM.run(); } // end main -} // end class ATMCaseStudy - - +} // end class ATMCaseStudy /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/BalanceInquiry.java b/src/Code/GUI/BalanceInquiry.java index cd57c15..0c40ffe 100644 --- a/src/Code/GUI/BalanceInquiry.java +++ b/src/Code/GUI/BalanceInquiry.java @@ -1,57 +1,51 @@ package Code.GUI; // BalanceInquiry.java + // Represents a balance inquiry ATM transaction import Code.Business_logic.Euro; import Code.Database.BankDatabase; -public class BalanceInquiry extends Transaction -{ +public class BalanceInquiry extends Transaction { // BalanceInquiry constructor - public BalanceInquiry( int userAccountNumber, Screen atmScreen, - BankDatabase atmBankDatabase ) - { - super( userAccountNumber, atmScreen, atmBankDatabase ); + public BalanceInquiry(int userAccountNumber, Screen atmScreen, + BankDatabase atmBankDatabase) { + super(userAccountNumber, atmScreen, atmBankDatabase); } // end BalanceInquiry constructor // performs the transaction - public void execute() - { + public void execute() { // get references to bank database and screen BankDatabase bankDatabase = getBankDatabase(); Screen screen = getScreen(); // get the available balance for the account involved - Euro availableBalance = - bankDatabase.getAvailableBalance( getAccountNumber() ); + Euro availableBalance = bankDatabase.getAvailableBalance(getAccountNumber()); // get the total balance for the account involved - Euro totalBalance = - bankDatabase.getTotalBalance( getAccountNumber() ); - + Euro totalBalance = bankDatabase.getTotalBalance(getAccountNumber()); + // display the balance information on the screen - screen.displayMessageLine( "\nBalance Information:" ); - screen.displayMessage( " - Available balance: " ); - screen.displayDollarAmount( availableBalance.getValoreDouble() ); - screen.displayMessage( "\n - Total balance: " ); - screen.displayDollarAmount( totalBalance.getValoreDouble() ); - screen.displayMessageLine( "" ); + screen.displayMessageLine("\nBalance Information:"); + screen.displayMessage(" - Available balance: "); + screen.displayDollarAmount(availableBalance.getValoreDouble()); + screen.displayMessage("\n - Total balance: "); + screen.displayDollarAmount(totalBalance.getValoreDouble()); + screen.displayMessageLine(""); } // end method execute } // end class BalanceInquiry - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/CashDispenser.java b/src/Code/GUI/CashDispenser.java index 826e4ee..38f248b 100644 --- a/src/Code/GUI/CashDispenser.java +++ b/src/Code/GUI/CashDispenser.java @@ -1,51 +1,46 @@ package Code.GUI; // CashDispenser.java + // Represents the cash dispenser of the ATM -public class CashDispenser -{ +public class CashDispenser { // the default initial number of bills in the cash dispenser private final static int INITIAL_COUNT = 500; private int count; // number of $20 bills remaining - + // no-argument CashDispenser constructor initializes count to default - public CashDispenser() - { + public CashDispenser() { count = INITIAL_COUNT; // set count attribute to default } // end CashDispenser constructor // simulates dispensing of specified amount of cash - public void dispenseCash( int amount ) - { + public void dispenseCash(int amount) { int billsRequired = amount / 20; // number of $20 bills required count -= billsRequired; // update the count of bills } // end method dispenseCash // indicates whether cash dispenser can dispense desired amount - public boolean isSufficientCashAvailable( int amount ) - { + public boolean isSufficientCashAvailable(int amount) { int billsRequired = amount / 20; // number of $20 bills required - if ( count >= billsRequired ) + if (count >= billsRequired) return true; // enough bills available - else + else return false; // not enough bills available } // end method isSufficientCashAvailable } // end class CashDispenser - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/Deposit.java b/src/Code/GUI/Deposit.java index 7a43096..7fd9b2d 100644 --- a/src/Code/GUI/Deposit.java +++ b/src/Code/GUI/Deposit.java @@ -1,24 +1,23 @@ package Code.GUI; // Deposit.java + // Represents a deposit ATM transaction import Code.Business_logic.Euro; import Code.Database.BankDatabase; -public class Deposit extends Transaction -{ +public class Deposit extends Transaction { private double amount; // amount to deposit private Keypad keypad; // reference to keypad private DepositSlot depositSlot; // reference to deposit slot private final static int CANCELED = 0; // constant for cancel option // Deposit constructor - public Deposit( int userAccountNumber, Screen atmScreen, - BankDatabase atmBankDatabase, Keypad atmKeypad, - DepositSlot atmDepositSlot ) - { + public Deposit(int userAccountNumber, Screen atmScreen, + BankDatabase atmBankDatabase, Keypad atmKeypad, + DepositSlot atmDepositSlot) { // initialize superclass variables - super( userAccountNumber, atmScreen, atmBankDatabase ); + super(userAccountNumber, atmScreen, atmBankDatabase); // initialize references to keypad and deposit slot keypad = atmKeypad; @@ -26,81 +25,74 @@ public Deposit( int userAccountNumber, Screen atmScreen, } // end Deposit constructor // perform transaction - public void execute() - { + public void execute() { BankDatabase bankDatabase = getBankDatabase(); // get reference Screen screen = getScreen(); // get reference amount = promptForDepositAmount(); // get deposit amount from user // check whether user entered a deposit amount or canceled - if ( amount != CANCELED ) - { + if (amount != CANCELED) { // request deposit envelope containing specified amount - screen.displayMessage( - "\nPlease insert a deposit envelope containing " ); - screen.displayDollarAmount( amount ); - screen.displayMessageLine( "." ); + screen.displayMessage( + "\nPlease insert a deposit envelope containing "); + screen.displayDollarAmount(amount); + screen.displayMessageLine("."); // receive deposit envelope boolean envelopeReceived = depositSlot.isEnvelopeReceived(); // check whether deposit envelope was received - if ( envelopeReceived ) - { - screen.displayMessageLine( "\nYour envelope has been " + - "received.\nNOTE: The money just deposited will not " + - "be available until we verify the amount of any " + - "enclosed cash and your checks clear." ); - + if (envelopeReceived) { + screen.displayMessageLine("\nYour envelope has been " + + "received.\nNOTE: The money just deposited will not " + + "be available until we verify the amount of any " + + "enclosed cash and your checks clear."); + // credit account to reflect the deposit - bankDatabase.credit( getAccountNumber(), new Euro(amount) ); + bankDatabase.credit(getAccountNumber(), new Euro(amount)); } // end if else // deposit envelope not received { - screen.displayMessageLine( "\nYou did not insert an " + - "envelope, so the ATM has canceled your transaction." ); + screen.displayMessageLine("\nYou did not insert an " + + "envelope, so the ATM has canceled your transaction."); } // end else - } // end if + } // end if else // user canceled instead of entering amount { - screen.displayMessageLine( "\nCanceling transaction..." ); + screen.displayMessageLine("\nCanceling transaction..."); } // end else } // end method execute - // prompt user to enter a deposit amount in cents - private double promptForDepositAmount() - { + // prompt user to enter a deposit amount in cents + private double promptForDepositAmount() { Screen screen = getScreen(); // get reference to screen // display the prompt - screen.displayMessage( "\nPlease enter a deposit amount in " + - "CENTS (or 0 to cancel): " ); + screen.displayMessage("\nPlease enter a deposit amount in " + + "CENTS (or 0 to cancel): "); int input = keypad.getInput(); // receive input of deposit amount - + // check whether the user canceled or entered a valid amount - if ( input == CANCELED ) + if (input == CANCELED) return CANCELED; - else - { - return ( double ) input / 100; // return dollar amount + else { + return (double) input / 100; // return dollar amount } // end else } // end method promptForDepositAmount } // end class Deposit - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/DepositSlot.java b/src/Code/GUI/DepositSlot.java index ad34c2c..3a9c92d 100644 --- a/src/Code/GUI/DepositSlot.java +++ b/src/Code/GUI/DepositSlot.java @@ -1,30 +1,27 @@ package Code.GUI; // DepositSlot.java + // Represents the deposit slot of the ATM -public class DepositSlot -{ - // indicates whether envelope was received (always returns true, +public class DepositSlot { + // indicates whether envelope was received (always returns true, // because this is only a software simulation of a real deposit slot) - public boolean isEnvelopeReceived() - { + public boolean isEnvelopeReceived() { return true; // deposit envelope was received } // end method isEnvelopeReceived } // end class DepositSlot - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/Keypad.java b/src/Code/GUI/Keypad.java index 905beee..eac2bf1 100644 --- a/src/Code/GUI/Keypad.java +++ b/src/Code/GUI/Keypad.java @@ -1,38 +1,34 @@ package Code.GUI; + // Keypad.java // Represents the keypad of the ATM import java.util.Scanner; // program uses Scanner to obtain user input -public class Keypad -{ +public class Keypad { private Scanner input; // reads data from the command line - + // no-argument constructor initializes the Scanner - public Keypad() - { - input = new Scanner( System.in ); + public Keypad() { + input = new Scanner(System.in); } // end no-argument Keypad constructor - // return an integer value entered by user - public int getInput() - { - return input.nextInt(); // we assume that user enters an integer + // return an integer value entered by user + public int getInput() { + return input.nextInt(); // we assume that user enters an integer } // end method getInput -} // end class Keypad - - +} // end class Keypad /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/Screen.java b/src/Code/GUI/Screen.java index 405669b..a74848d 100644 --- a/src/Code/GUI/Screen.java +++ b/src/Code/GUI/Screen.java @@ -1,41 +1,36 @@ package Code.GUI; // Screen.java + // Represents the screen of the ATM -public class Screen -{ +public class Screen { // displays a message without a carriage return - public void displayMessage( String message ) - { - System.out.print( message ); + public void displayMessage(String message) { + System.out.print(message); } // end method displayMessage // display a message with a carriage return - public void displayMessageLine( String message ) - { - System.out.println( message ); + public void displayMessageLine(String message) { + System.out.println(message); } // end method displayMessageLine // display a dollar amount - public void displayDollarAmount( double amount ) - { - System.out.printf( "$%,.2f", amount ); - } // end method displayDollarAmount + public void displayDollarAmount(double amount) { + System.out.printf("$%,.2f", amount); + } // end method displayDollarAmount } // end class Screen - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/Transaction.java b/src/Code/GUI/Transaction.java index 3c41a84..c75d415 100644 --- a/src/Code/GUI/Transaction.java +++ b/src/Code/GUI/Transaction.java @@ -1,39 +1,35 @@ package Code.GUI; // Transaction.java + // Abstract superclass Transaction represents an ATM transaction import Code.Database.BankDatabase; -public abstract class Transaction -{ +public abstract class Transaction { private int accountNumber; // indicates account involved private Screen screen; // ATM's screen private BankDatabase bankDatabase; // account info database // Transaction constructor invoked by subclasses using super() - public Transaction( int userAccountNumber, Screen atmScreen, - BankDatabase atmBankDatabase ) - { + public Transaction(int userAccountNumber, Screen atmScreen, + BankDatabase atmBankDatabase) { accountNumber = userAccountNumber; screen = atmScreen; bankDatabase = atmBankDatabase; } // end Transaction constructor - // return account number - public int getAccountNumber() - { - return accountNumber; + // return account number + public int getAccountNumber() { + return accountNumber; } // end method getAccountNumber // return reference to screen - public Screen getScreen() - { + public Screen getScreen() { return screen; } // end method getScreen // return reference to bank database - public BankDatabase getBankDatabase() - { + public BankDatabase getBankDatabase() { return bankDatabase; } // end method getBankDatabase @@ -41,19 +37,17 @@ public BankDatabase getBankDatabase() abstract public void execute(); } // end class Transaction - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file diff --git a/src/Code/GUI/Withdrawal.java b/src/Code/GUI/Withdrawal.java index 3e81a09..df6e50c 100644 --- a/src/Code/GUI/Withdrawal.java +++ b/src/Code/GUI/Withdrawal.java @@ -1,12 +1,12 @@ package Code.GUI; // Withdrawal.java + // Represents a withdrawal ATM transaction import Code.Business_logic.Euro; import Code.Database.BankDatabase; -public class Withdrawal extends Transaction -{ +public class Withdrawal extends Transaction { private int amount; // amount to withdraw private Keypad keypad; // reference to keypad private CashDispenser cashDispenser; // reference to cash dispenser @@ -15,120 +15,110 @@ public class Withdrawal extends Transaction private final static int CANCELED = 6; // Withdrawal constructor - public Withdrawal( int userAccountNumber, Screen atmScreen, - BankDatabase atmBankDatabase, Keypad atmKeypad, - CashDispenser atmCashDispenser ) - { + public Withdrawal(int userAccountNumber, Screen atmScreen, + BankDatabase atmBankDatabase, Keypad atmKeypad, + CashDispenser atmCashDispenser) { // initialize superclass variables - super( userAccountNumber, atmScreen, atmBankDatabase ); - + super(userAccountNumber, atmScreen, atmBankDatabase); + // initialize references to keypad and cash dispenser keypad = atmKeypad; cashDispenser = atmCashDispenser; } // end Withdrawal constructor // perform transaction - public void execute() - { + public void execute() { boolean cashDispensed = false; // cash was not dispensed yet Euro availableBalance; // amount available for withdrawal // get references to bank database and screen - BankDatabase bankDatabase = getBankDatabase(); + BankDatabase bankDatabase = getBankDatabase(); Screen screen = getScreen(); // loop until cash is dispensed or the user cancels - do - { - // obtain a chosen withdrawal amount from the user + do { + // obtain a chosen withdrawal amount from the user amount = displayMenuOfAmounts(); - + // check whether user chose a withdrawal amount or canceled - if ( amount != CANCELED ) - { + if (amount != CANCELED) { // get available balance of account involved - availableBalance = - bankDatabase.getAvailableBalance( getAccountNumber() ); - - // check whether the user has enough money in the account - if ( new Euro(amount).minoreDi(availableBalance)) - { + availableBalance = bankDatabase.getAvailableBalance(getAccountNumber()); + + // check whether the user has enough money in the account + if (new Euro(amount).minoreDi(availableBalance)) { // check whether the cash dispenser has enough money - if ( cashDispenser.isSufficientCashAvailable( amount ) ) - { + if (cashDispenser.isSufficientCashAvailable(amount)) { // update the account involved to reflect withdrawal - bankDatabase.debit( getAccountNumber(), new Euro(amount) ); - - cashDispenser.dispenseCash( amount ); // dispense cash + bankDatabase.debit(getAccountNumber(), new Euro(amount)); + + cashDispenser.dispenseCash(amount); // dispense cash cashDispensed = true; // cash was dispensed // instruct user to take cash - screen.displayMessageLine( - "\nPlease take your cash now." ); + screen.displayMessageLine( + "\nPlease take your cash now."); } // end if else // cash dispenser does not have enough cash - screen.displayMessageLine( - "\nInsufficient cash available in the ATM." + - "\n\nPlease choose a smaller amount." ); + screen.displayMessageLine( + "\nInsufficient cash available in the ATM." + + "\n\nPlease choose a smaller amount."); } // end if else // not enough money available in user's account { - screen.displayMessageLine( - "\nInsufficient funds in your account." + - "\n\nPlease choose a smaller amount." ); + screen.displayMessageLine( + "\nInsufficient funds in your account." + + "\n\nPlease choose a smaller amount."); } // end else } // end if - else // user chose cancel menu option + else // user chose cancel menu option { - screen.displayMessageLine( "\nCanceling transaction..." ); + screen.displayMessageLine("\nCanceling transaction..."); return; // return to main menu because user canceled } // end else - } while ( !cashDispensed ); + } while (!cashDispensed); } // end method execute // display a menu of withdrawal amounts and the option to cancel; // return the chosen amount or 0 if the user chooses to cancel - private int displayMenuOfAmounts() - { + private int displayMenuOfAmounts() { int userChoice = 0; // local variable to store return value Screen screen = getScreen(); // get screen reference - + // array of amounts to correspond to menu numbers int amounts[] = { 0, 20, 40, 60, 100, 200 }; // loop while no valid choice has been made - while ( userChoice == 0 ) - { + while (userChoice == 0) { // display the menu - screen.displayMessageLine( "\nWithdrawal Menu:" ); - screen.displayMessageLine( "1 - $20" ); - screen.displayMessageLine( "2 - $40" ); - screen.displayMessageLine( "3 - $60" ); - screen.displayMessageLine( "4 - $100" ); - screen.displayMessageLine( "5 - $200" ); - screen.displayMessageLine( "6 - Cancel transaction" ); - screen.displayMessage( "\nChoose a withdrawal amount: " ); + screen.displayMessageLine("\nWithdrawal Menu:"); + screen.displayMessageLine("1 - $20"); + screen.displayMessageLine("2 - $40"); + screen.displayMessageLine("3 - $60"); + screen.displayMessageLine("4 - $100"); + screen.displayMessageLine("5 - $200"); + screen.displayMessageLine("6 - Cancel transaction"); + screen.displayMessage("\nChoose a withdrawal amount: "); int input = keypad.getInput(); // get user input through keypad // determine how to proceed based on the input value - switch ( input ) - { - case 1: // if the user chose a withdrawal amount + switch (input) { + case 1: // if the user chose a withdrawal amount case 2: // (i.e., chose option 1, 2, 3, 4 or 5), return the case 3: // corresponding amount from amounts array case 4: case 5: - userChoice = amounts[ input ]; // save user's choice - break; + userChoice = amounts[input]; // save user's choice + break; case CANCELED: // the user chose to cancel userChoice = CANCELED; // save user's choice break; default: // the user did not enter a value from 1-6 - screen.displayMessageLine( - "\nIvalid selection. Try again." ); + screen.displayMessageLine( + "\nIvalid selection. Try again."); } // end switch } // end while @@ -136,19 +126,17 @@ private int displayMenuOfAmounts() } // end method displayMenuOfAmounts } // end class Withdrawal - - /************************************************************************** - * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * - * Pearson Education, Inc. All Rights Reserved. * - * * - * DISCLAIMER: The authors and publisher of this book have used their * - * best efforts in preparing the book. These efforts include the * - * development, research, and testing of the theories and programs * - * to determine their effectiveness. The authors and publisher make * - * no warranty of any kind, expressed or implied, with regard to these * + * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and * + * Pearson Education, Inc. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * - * and publisher shall not be liable in any event for incidental or * - * consequential damages in connection with, or arising out of, the * - * furnishing, performance, or use of these programs. * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * *************************************************************************/ \ No newline at end of file From 9e4fcb05191620d8b9769667aa571e9680adffbc Mon Sep 17 00:00:00 2001 From: Cunoucu Date: Thu, 23 Nov 2023 17:04:20 +0100 Subject: [PATCH 8/9] Modificato Account per ottenere un conflitto --- .gitignore | 37 +++++++++++++++++++++++++++++++++++++ src/Account.java | 14 +++++++------- 2 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8605526 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* diff --git a/src/Account.java b/src/Account.java index c308eca..188284f 100644 --- a/src/Account.java +++ b/src/Account.java @@ -5,12 +5,12 @@ public class Account { private int accountNumber; // account number private int pin; // PIN for authentication - private double availableBalance; // funds available for withdrawal - private double totalBalance; // funds available + pending deposits + private long availableBalance; // funds available for withdrawal + private long totalBalance; // funds available + pending deposits // Account constructor initializes attributes public Account( int theAccountNumber, int thePIN, - double theAvailableBalance, double theTotalBalance ) + long theAvailableBalance, long theTotalBalance ) { accountNumber = theAccountNumber; pin = thePIN; @@ -28,25 +28,25 @@ public boolean validatePIN( int userPIN ) } // end method validatePIN // returns available balance - public double getAvailableBalance() + public long getAvailableBalance() { return availableBalance; } // end getAvailableBalance // returns the total balance - public double getTotalBalance() + public long getTotalBalance() { return totalBalance; } // end method getTotalBalance // credits an amount to the account - public void credit( double amount ) + public void credit( long amount ) { totalBalance += amount; // add to total balance } // end method credit // debits an amount from the account - public void debit( double amount ) + public void debit( long amount ) { availableBalance -= amount; // subtract from available balance totalBalance -= amount; // subtract from total balance From a0e1f9936d7956ea6702fdb7c8ff7941af9c2c44 Mon Sep 17 00:00:00 2001 From: stefanoamalberti Date: Thu, 23 Nov 2023 17:13:51 +0100 Subject: [PATCH 9/9] Aggiunto file componenti.txt --- componenti.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 componenti.txt diff --git a/componenti.txt b/componenti.txt new file mode 100644 index 0000000..c83a40e --- /dev/null +++ b/componenti.txt @@ -0,0 +1,3 @@ +Stefano Amalberti 5209118 +Lorenzo Massone 5198151 +Stefano Musso Piantelli 5320921 \ No newline at end of file