From 73c9b9cf95ff944fd1d57bfac0a4faa3a48cdf77 Mon Sep 17 00:00:00 2001 From: Dangoo2002 Date: Thu, 28 Nov 2024 21:50:17 +0300 Subject: [PATCH 1/4] made chnages as per the assignment --- src/Lecture1_adt/Transaction1.class | Bin 0 -> 410 bytes src/Lecture1_adt/Transaction2.class | Bin 0 -> 549 bytes src/Lecture1_adt/Transaction2.java | 23 +-- src/Lecture1_adt/Transaction3.class | Bin 0 -> 549 bytes src/Lecture1_adt/Transaction3.java | 18 +- src/Lecture1_adt/Transaction4.class | Bin 0 -> 555 bytes src/Lecture1_adt/Transaction4.java | 21 +-- .../Transaction4.class | Bin 0 -> 569 bytes .../Transaction4.java | 35 ++-- .../BankAccount.class | Bin 0 -> 475 bytes .../BankAccount.java | 12 +- .../BaseTransaction.class | Bin 0 -> 1776 bytes .../BaseTransaction.java | 58 +++---- .../DepositTransaction.class | Bin 0 -> 997 bytes .../DepositTransaction.java | 14 ++ .../DepositTrasaction.java | 30 ---- .../InsufficientFundsException.class | Bin 0 -> 252 bytes .../InsufficientFundsException.java | 6 + .../Main.class | Bin 0 -> 1597 bytes .../Main.java | 27 +++ .../TransactionInterface.class | Bin 0 -> 315 bytes .../TransactionInterface.java | 15 +- .../WithdrawalTransaction.class | Bin 0 -> 1412 bytes .../WithdrawalTransaction.java | 49 ++---- src/Main.java | 156 ------------------ 25 files changed, 132 insertions(+), 332 deletions(-) create mode 100644 src/Lecture1_adt/Transaction1.class create mode 100644 src/Lecture1_adt/Transaction2.class create mode 100644 src/Lecture1_adt/Transaction3.class create mode 100644 src/Lecture1_adt/Transaction4.class create mode 100644 src/Lecture2_adt_specification/Transaction4.class create mode 100644 src/Lecture4_interfaces_abstract_classes/BankAccount.class create mode 100644 src/Lecture4_interfaces_abstract_classes/BaseTransaction.class create mode 100644 src/Lecture4_interfaces_abstract_classes/DepositTransaction.class create mode 100644 src/Lecture4_interfaces_abstract_classes/DepositTransaction.java delete mode 100644 src/Lecture4_interfaces_abstract_classes/DepositTrasaction.java create mode 100644 src/Lecture4_interfaces_abstract_classes/InsufficientFundsException.class create mode 100644 src/Lecture4_interfaces_abstract_classes/InsufficientFundsException.java create mode 100644 src/Lecture4_interfaces_abstract_classes/Main.class create mode 100644 src/Lecture4_interfaces_abstract_classes/Main.java create mode 100644 src/Lecture4_interfaces_abstract_classes/TransactionInterface.class create mode 100644 src/Lecture4_interfaces_abstract_classes/WithdrawalTransaction.class delete mode 100644 src/Main.java diff --git a/src/Lecture1_adt/Transaction1.class b/src/Lecture1_adt/Transaction1.class new file mode 100644 index 0000000000000000000000000000000000000000..25224be4466ce95dc313926d4f707809f349e756 GIT binary patch literal 410 zcmZvYPfNo<5XIjlX=Br9|JZ74y?9H57%|32I|;%V4-KDUy1`8hc*U;x>#q0(gd0ltXODC z=!GlsEP_HOX)qJ1RI$jXY`siWqOS-8Z~mWSe9sB9Earq(m?(Kutd}xhh-Jzh=PoPq zNM0wU=qz%fosaN;6e{%^UxsZ+WIT;f>h5E(25|@Qs1dtST|tF6%v37wj;(_Wd`I mKia_XPhVkv!rGwrQrTO4c6rg@0She-Yomt_2ei3opz{Om{Zy3z literal 0 HcmV?d00001 diff --git a/src/Lecture1_adt/Transaction2.class b/src/Lecture1_adt/Transaction2.class new file mode 100644 index 0000000000000000000000000000000000000000..036f6d65966ebfd695851c6c348e9e1a49d52828 GIT binary patch literal 549 zcmZutT}#4X7(K6ZF6T;J=12BPH!6`-7hM=Z7=a*lk#rlcI%G08SX;lUi-IiZBD(HJ zMQ2(e<;{7vvvbaK_I!N4z5zJGmJSX1BoZh@P}HHKq+wMAl{dO zC6H?m<(;gDf$h|r(y`pW^c$2O+pZm)2ox)=d5Y>a6PjM13F)@&S{LD{Yxy17b;u+K zR&e^gN~u)2Oe1qP*_W?W=j93LS6=A%taCd`$aZ|`-pXEJd+xzr)X;!|bps1X8qkq4 zuz^hh^M84PQrqeUp>OTq$bL|tO%ljV432aM^~>&%IsrE1&!|1ebEA9w^qbK%u+4L7 zym1U>RDn-s)PhriV6#Qy65kG~P&m`I7l>MUj96`V4CRp&4@EQ)CuWHzW0q;k@k@rx tG+>=mP@&eI5WD}iB_?EnXwo#5?r=uZ6s5{D;_px&{us&>Vu+sI9fu54^NREaJgKMUaY6D0)!5$~Fll5)+7tzsiGxAK*be z`=i9!Ql+SudAqao=FPs3&(}8qdssJNppr)pRRv2Xbkqzi8>kyt5y;8wC=C+<(HF?N zGVuf!23PV{cGAQTIz1V9p)2DqrTc#9CkFyc&HjIi)&(7UkxPftzz@BX^m^#U=W-a3 z$&b9`a5743wm8fnb2Oe;X}13J6EM%BGIY}COJD1W;I@3-9<#9tG!%^pSctxE66Y?{<6GWlf$9KLdO&1$n zr@&DvyD(pgHiXJp@@-~Vc;Qm{ZSgT*fnz-ROT literal 0 HcmV?d00001 diff --git a/src/Lecture1_adt/Transaction3.java b/src/Lecture1_adt/Transaction3.java index 48781e7..ef47946 100644 --- a/src/Lecture1_adt/Transaction3.java +++ b/src/Lecture1_adt/Transaction3.java @@ -1,31 +1,25 @@ package Lecture1_adt; -import org.jetbrains.annotations.NotNull; - import java.util.Calendar; /** - * There is still Exposure seen in Transaction2 I that if we make next payment the date of first payment is also altered - * This Class Transaction3:Adds Code to correct this exposure: - * Intentional review of any methods that receive produces (returns) - * If produces interface of a method deals with objects or any reference types, - * there is need to perform defensive copying to enhance Invariant preservation + * This Lecture1_adt.Transaction3 class adds code to correct potential exposure issues in Transaction2. + * Methods that return objects of reference types use defensive copying to enhance invariant preservation. */ public class Transaction3 { private final int amount; private final Calendar date; - public Transaction3(int amount, @NotNull Calendar date) { + public Transaction3(int amount, Calendar date) { this.amount = amount; - this.date = date; + this.date = date; // Defensive copying not required for constructor arguments in this class } public int getAmount() { - return amount; // Because we are dealing with Value types we need not worry about what we return + return amount; // Value types like integers can be returned directly } public Calendar getDate() { -// return date; // Because we are dealing with Reference types we need to judiciously copy what our getters return - return (Calendar) date.clone(); // Defensive copying or Judicious Copying + return (Calendar) date.clone(); // Defensive copying ensures reference types are not altered externally } } diff --git a/src/Lecture1_adt/Transaction4.class b/src/Lecture1_adt/Transaction4.class new file mode 100644 index 0000000000000000000000000000000000000000..1533774de52cb607100ede3cfcbd2520e8e23b8f GIT binary patch literal 555 zcmZuuOG^S#6#lNSNu5e3pV^Z(Dv<<1gb{=h2vUorZCsr}M#dSKX8Khv3bLR@wC+bm z-!%&ARyWTF;fPX zK&~^Ccd`)%w$o@y$8t^SHwitqT{}1tC{^3@5VdP6v^`@3NTV!40>4=CZd%pexQLl^e2h+~07 zM}|ru*SM57vKEDoTRV`h@;Wl8le+78PPivfEFb^JsGL*b!0%9DqTzVzB)V#=pefrf zJL#?p_dl)TvOTJ%P-b9|g8LaI+G+ceQv%G(PfOaa z@9FJ)rTxLFW0^}exbYY)9f)t1c4m!3Fy|O?oTnW!;;i}V6GU~ck63m65%E_f`bggM zg3BXX{8vNFQY^Ug+c-ORaY)t6}ph68#NJ$D}NRk5|`6qf(2{|6nPXEK7=vRn7Hr( zd?@27Qlg8_+|E7UIrn~je|!Qs#I6GiwLDDJZ8U6b3)sG#$WUnk(G|!Z1z`}M2w2T- ztIz8!8n9Kq2ts|excBw!M*0)JI71zGQqpX;$l3!vjpjitkXr`v-C!n{0;OIo)%a3Q zQ?3^+W=fw2iAkj+!||z7(ISiwM)E-xVPmI=46*`+KTS%LcAJw9+t>a`E2c2DkA3c9 zaW?@Y!B|4oJhxUIi$sRnEQtb&Yi^Hzf|`u?3gdZ$ zBqC7E#WoQx@g$<)-BRnSe;E#aK(WI#!7rWbcnviYfA{eTrC)lurVSG5gjELCP)7r0 OzL^kpT2)vYsQv(CzDC*r literal 0 HcmV?d00001 diff --git a/src/Lecture4_interfaces_abstract_classes/BankAccount.java b/src/Lecture4_interfaces_abstract_classes/BankAccount.java index 28d0d07..37b8bf4 100644 --- a/src/Lecture4_interfaces_abstract_classes/BankAccount.java +++ b/src/Lecture4_interfaces_abstract_classes/BankAccount.java @@ -1,7 +1,7 @@ package Lecture4_interfaces_abstract_classes; - public class BankAccount { private double balance; + public BankAccount(double balance) { this.balance = balance; } @@ -10,7 +10,13 @@ public double getBalance() { return balance; } - public void setBalance(double balance) { - this.balance = balance; + public void deposit(double amount) { + balance += amount; + } + + public void withdraw(double amount) { + if (balance >= amount) { + balance -= amount; + } } } diff --git a/src/Lecture4_interfaces_abstract_classes/BaseTransaction.class b/src/Lecture4_interfaces_abstract_classes/BaseTransaction.class new file mode 100644 index 0000000000000000000000000000000000000000..b6d95202b4945c187a94874680d08fa66fd21775 GIT binary patch literal 1776 zcmaJ>YjfK~6g}(2mhGsxRh@*kB)DxJj-heOt5BChVw2XzeSlrct$e zpYShu3@tPH!0?$L#c)BT#Gc(;HX*tCdyuZZ{Yfdzq&H0rj63_i)@j)8`Oy9PcL$jPBMc0&Qt5||yxPzjVf zFXW-Dk3-w3H>IQ8f%F>!=R#k)f$WF2=eCKqVwfY{y?QtFZFi5L++EwX!+Qd?YHOOC zvo;&wkhtj$NL=dJu6jHk?kc}0cOC8&_Efl)L^xC3AgjThRutw!bz>TXz(RP1_Vzpr*|9cFo31}a6l zsRcB#h-)S;z%p?UpHZ;0vYNPvvWa;t82H@87Pd*Y?RjB9u}6uQVz{LS|+~0 zj)D6o9-y7aL%sgeL7#XD5K zZx4vyw}Z+sBHLsYP9?*LqQE2Rp6tF*eYQ(Em2KM%mH(scQ;2Ne@mwv)gx;|cyCdbO zdlZCfNTIzk-Ob09w7vRMT@kjElEX$3Pw|z&g%nq%-MUi|0*ga=pqifBm*I0e+~;2q zN;hQX)~Zu_?Ch4n#VD&uO7>UO5{}E5ra5Be3vok6Va!)sNfS;smhRG?J){!WYbB!V zq&t^77>jDXO;Mf`|N>q2aXC>V#CH+$x=HLhP|VangahJg-<#lom=994~)~bsfvN` z1Xj=FH!U`S<^RXwD&N5p-@Wsgfu*k?UqegZwP@ybl!h3#69T3h_6t%3z=i{EX;n6!{a6Z}XZ^@qO(c0#u-Gn?I^32)+S z=nqW#!w2x8jCWa*(m>2+Co}is+;h*|`SbVkH-G~inn>ZM2?IG3tGJcM8gA#vb;rbA z+%s_Bz$QcTts@=%j-gU&G|%}3uMV~2R_ojq(&m0GvbkLLsx9q1vR5mgG9>EC77UrD zBgLoTpd@H;-2S@7_z12F_-)QOZB1zHR!PYo%1Ez-zQ z)h{HFCYb~u)J*K7%3w{|2>ZNPFdv47{dMXe!kodc^sIl)|sOJO~6a z`#xJ?iV@wwdoFEP1cfMZ!K}B`PtKJg3e2OUTwT1^TCIa5fIO(l2-^T6dB^AsMI=P#*v|O3|YLG*cqPT6`mtcUQiUn H2L1Vey8Zx0 literal 0 HcmV?d00001 diff --git a/src/Lecture4_interfaces_abstract_classes/DepositTransaction.java b/src/Lecture4_interfaces_abstract_classes/DepositTransaction.java new file mode 100644 index 0000000..db15e3e --- /dev/null +++ b/src/Lecture4_interfaces_abstract_classes/DepositTransaction.java @@ -0,0 +1,14 @@ +package Lecture4_interfaces_abstract_classes; +import java.util.Calendar; + +public class DepositTransaction extends BaseTransaction { + public DepositTransaction(double amount, Calendar date, String transactionID) { + super(amount, date, transactionID); + } + + @Override + public void apply(BankAccount ba) { + ba.deposit(getAmount()); + System.out.println("Deposited: " + getAmount()); + } +} diff --git a/src/Lecture4_interfaces_abstract_classes/DepositTrasaction.java b/src/Lecture4_interfaces_abstract_classes/DepositTrasaction.java deleted file mode 100644 index 81afab5..0000000 --- a/src/Lecture4_interfaces_abstract_classes/DepositTrasaction.java +++ /dev/null @@ -1,30 +0,0 @@ -package Lecture4_interfaces_abstract_classes; - -import org.jetbrains.annotations.NotNull; - -import java.util.Calendar; - -public class DepositTrasaction extends BaseTransaction { - public DepositTrasaction(int amount, @NotNull Calendar date){ - super(amount, date); - } - private boolean checkDepositAmount(int amt){ - if (amt < 0){ - return false; - } - else{ - return true; - } - } - - // Method to print a transaction receipt or details - public void printTransactionDetails(){ - System.out.println("Deposit Trasaction: "+this.toString()); - } - - public void apply(BankAccount ba){ - double curr_balance = ba.getBalance(); - double new_balance = curr_balance + getAmount(); - ba.setBalance(new_balance); - } -} diff --git a/src/Lecture4_interfaces_abstract_classes/InsufficientFundsException.class b/src/Lecture4_interfaces_abstract_classes/InsufficientFundsException.class new file mode 100644 index 0000000000000000000000000000000000000000..c4dddd2fc690bc832531a9bd86c0ef245ed0c60a GIT binary patch literal 252 zcmX^0Z`VEs1_pBmUM>b^1}=66ZgvJ9Mg}&U%)HDJJ4Oak4WF#UvPAuy#JqI<;F6-u zymV{LFh&Lz=lqmZMh1SL%)C^;(%hufqL9R-9H0nSaDHh~a;jSZFdtz6n-Xcchc>az?QTi0;v>DOWU-dfCMo#u~1D4k|-d)O*TVWvf0hqos`oL z>QC^i{sKSaht@;S@dx-9{4X5u?8cJX9QVV_?49S{dG2%X%wMlx{R!Y2q=|FLbIcp1 zpG#x`Or)^DamgtC^siwNOKB{dFi_CLiXK+SaT!-M_T~8fW8{O>WoIC~@58SYt45y1uJ!F^uHrzhoFK2QA5vsk*-0>~)$lY>1{u zmeG!IeTM1$lj?J^Eef9Sw+eL?y8c#CJ5JV>aN0G|?c>dQ&8?rP`p8aXd(KMUuP zW0+VIe*3oL1U+AAQ<=f8$Zin1su2o55{_~MpQB>o6Rb0gH6E?3tZL*P3wM#Tuz^oG zKC@6o&B7+`F&tkD0u`xHbZb&Q3tCae!2L8nx9|XUj)sLVKt!_-UG=OLiWkBgII4fd z&;dXm|)!WLU^ohHVTNe5Om<52{s>idaUJiRgB{9U_^p4#*r= zX@GZqCsMLQbq{*PKARlk28H`NEEQIY4pB0R`I?|&YvR-*6%$YJHAAjnyj(Nc%!#K; zhPhT!!y7rqFw+rjSq^+hC@ndyv;c|-W=X1}Nij^t+8yS=z~e+cQazhL>ZLWmFr3Vb zgF?rAcor_bSDXhxi`gk{q3MF`}ZKpb)9-Q2zNLfx?I&D zX!p7d)`suPuaLPSjuykkBl!*E#&GWcahSzfdg1h!qUVS1J&m*Uca~;G^Vq^3*h^Y4yhEcA z8%HpX3z(y|hW<^~QJR0;N9yrOjO<~ox(|bv{11%V<{l<$i@UHEFYRLTcO0WB^9sj- zU7Xm5O}HtI%kE)%b7>bdO9VJ|fIA)IwC$~5kv%Y6m{nT@k_kyUgMgn)~P`?76^j&0A-sS&)I3lHF-B$Wms z3pf3ms#o>C`uY9(25^nj949%ZgmGhK{@(UM2zy0Y6LPK8ES7Lyl#3OAaMg?R)h&A) zUO3JOQ?)!s4r?~z+HkK^XMbMLp{bS-EI>{7(J6XS$ngILr4grg_<;glRyk@X$z*Lu|puOO)Dj81zb(mldyO_yV@Ox z<`wz^t<(qLrZ@D$NK|U?`%o2UY=@f0LMzSAe81<+_kHuvzpwuS@C6>a$m0VSAL6`= zDO|9-k8&vB;tchdTwKN#2gNLwU1YIhmsM+Xbp`^L9IQDg35?$fbYSiZtQ0qE&*Y&j zwM`I~sxnl%A(L`X7D|0k+A&F>56a6w2xO{JLkZ+-fmRROtv!|O%Ds@1F&W3=X(N%(Ww@J2 zol4&XkzTWCJxt@2gXi`yQ` zxZ~g}4|lQ76x%v&@9zhGptRX)>qdI-Ctt-jkHF%fvaoNph5aZgJbw#o&Ei=1@HI9( zRB$tks=(Y(*u1rhOw|Apfr){;BKHGjDw0?3lly3Kc~c-q(MHQ&r9k#LEz3~cwAGmI z)~#2gqtvJt-J&*4=X%u(qSE&)onZl$Y?WPX;+}wa3{T%K2!Z*QY^rLceQB(MyVOW+ zQbu8xlWibyx|{ah-~vu;Q-!>?x#CGL3)k|it2C7df2hYq#DXJRV4W9Akcn{ zUbj4ux)G{$spmLk7zP-=K|To9YsnXTGxxu)xy-bt5>3ZT@Z8`}h_QC|%@vikgopTk5XY-T= getAmount()) { + ba.withdraw(getAmount()); + System.out.println("Withdrawn: " + getAmount()); + } else { + throw new InsufficientFundsException("Insufficient funds for withdrawal."); + } + } catch (InsufficientFundsException e) { + System.out.println(e.getMessage()); } } - // Method to reverse the transaction - public boolean reverse() { + public boolean reverse(BankAccount ba) { + ba.deposit(getAmount()); + System.out.println("Withdrawal reversed: " + getAmount()); return true; - } // return true if reversal was successful - - // Method to print a transaction receipt or details - public void printTransactionDetails() { - System.out.println("Deposit Trasaction: " + this.toString()); - } - - /* - Oportunity for assignment: implementing different form of withdrawal - */ - public void apply(BankAccount ba) { - double curr_balance = ba.getBalance(); - if (curr_balance > getAmount()) { - double new_balance = curr_balance - getAmount(); - ba.setBalance(new_balance); - } } - - /* - Assignment 1 Q3: Write the Reverse method - a method unique to the WithdrawalTransaction Class - */ } - diff --git a/src/Main.java b/src/Main.java deleted file mode 100644 index 584a048..0000000 --- a/src/Main.java +++ /dev/null @@ -1,156 +0,0 @@ -import Lecture1_adt.*; // Import all classes from Lecture1_adt package to be used in this client code - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.ArrayList; -import java.util.List; - -//TIP To Run code, press or -// click the icon in the gutter. -/* -* Client Code for accessing the Lecture1_adt.TransactionInterface.java module - */ -public class Main { - - public static void testTransaction1() { - Calendar d1 = new GregorianCalendar(); // d1 is an Object [Objects are Reference types] - Lecture1_adt.Transaction1 t1 = new Lecture1_adt.Transaction1(1000, d1); // amount and d1 are arguments - - System.out.println(t1.toString()); - System.out.println("Lecture1_adt.TransactionInterface Amount: \t " + t1.amount); - System.out.println("Lecture1_adt.TransactionInterface Date: \t " + t1.date); - - // Please note that the Client Codes can access the data in the class directly through the dot operator - // This kind of exposure is a threat to both the Representation Independence and Preservation of Invariants - } - - - /** @return a transaction of same amount as t, one month later - * This is a PRODUCER of the class Lecture1_adt.Transaction2 - * This code will help demostrate the Design exposures still present in transaction2 class - * */ - - public static Transaction2 makeNextPayment(Transaction2 t) { - Calendar d = t.getDate(); - d.add(Calendar.MONTH, 1); - return new Transaction2(t.getAmount(), d); - } - - /* - Testing Transaction2 class - */ - public static void testTransaction2() { - - Calendar d1 = new GregorianCalendar(); - - Lecture1_adt.Transaction2 t = new Lecture1_adt.Transaction2(1000, d1); - - Lecture1_adt.Transaction2 modified_t = makeNextPayment(t); - - System.out.println("\n\nState of the Object T1 After Client Code Tried to Change the Amount"); - System.out.println("Lecture1_adt.TransactionInterface Amount: \t "+modified_t.getAmount()); - System.out.println("Lecture1_adt.TransactionInterface Date: \t "+modified_t.getDate().getTime()); - - System.out.println("\n\nHow does T2 Look Like?????"); - System.out.println("Lecture1_adt.TransactionInterface Amount: \t "+modified_t.getAmount()); - System.out.println("Lecture1_adt.TransactionInterface Date: \t "+modified_t.getDate().getTime()); - - /* Please note that Although we have solved the problem of Transaction1 - * And client code can no longer use the dot (.) operator to directly access the data - * There is still some exposure especially if we pass an object of a previous Transaction2 to create a new Transaction2 object - */ - - } - - - /** @return a list of 12 monthly payments of identical amounts - * This code will help demostrate the Design exposures still present in transaction3 class - * */ - public static List makeYearOfPayments (int amount) throws NullPointerException { - - List listOfTransaction3s = new ArrayList(); - Calendar date = new GregorianCalendar(2024, Calendar.JANUARY, 3); - - - for (int i = 0; i < 12; i++) { - listOfTransaction3s.add(new Transaction3(amount, date)); - date.add(Calendar.MONTH, 1); - } - return listOfTransaction3s; - } - - /* - Testing Transaction3 class - */ - public static void testTransaction3() { - - List allPaymentsIn2024 = makeYearOfPayments(1000); - - for (Transaction3 t3 : allPaymentsIn2024) { - - // Display all the 12 Transactions - for (Transaction3 transact : allPaymentsIn2024) { - System.out.println("\n\n ::::::::::::::::::::::::::::::::::::::::::::\n"); - System.out.println("Lecture1_adt.TransactionInterface Amount: \t "+transact.getAmount()); - System.out.println("Lecture1_adt.TransactionInterface Date: \t "+transact.getDate().getTime()); - } - } - - /* Please Check all the 12 transactions displayed and hwo their dates look like - * Note that Although Transaction3 class resolves to an extent the exposure in Transaction2 class - * There is still some exposure especially if we pass an object of a previous Transaction3 to create a - * new Transaction3 object - */ - } - - - /** @return a list of 12 monthly payments of identical amounts - * This code Show that by judicious copying and defensive programming we eliminate the exposure in Transaction3 - * As defined in the constructor of Transaction4 class - * */ - - public static List makeYearOfPaymentsFinal (int amount) throws NullPointerException { - - List listOfTransaction4s = new ArrayList(); - Calendar date = new GregorianCalendar(2024, Calendar.JANUARY, 3); - - - for (int i = 0; i < 12; i++) { - listOfTransaction4s.add(new Transaction4(amount, date)); - date.add(Calendar.MONTH, 1); - } - return listOfTransaction4s; - } - - /* - Testing Transaction3 class - */ - public static void testTransaction4() { - - /* - * Call the function to make all the Twelve transaction in a year of our business - */ - - List transactionsIn2024 = makeYearOfPaymentsFinal(1200); - - // Display all the 12 Transactions - for (Transaction4 transact : transactionsIn2024) { - System.out.println("\n\n ::::::::::::::::::::::::::::::::::::::::::::\n"); - System.out.println("Lecture1_adt.TransactionInterface Amount: \t "+transact.getAmount()); - System.out.println("Lecture1_adt.TransactionInterface Date: \t "+transact.getDate().getTime()); - } - - // Please Take a look at all the 12 transaction now and compare with the outputs of the Transaction3 class - } - - - public static void main(String[] args) { - // This is the client code - // Uncomment the following lines to test the class which you would like to test - - // testTransaction1() - // testTransaction2() - // testTransaction3() - // testTransaction4() - } -} \ No newline at end of file From ee24f3f3a7d3c34cf24114ef1a0cdaf536a2839d Mon Sep 17 00:00:00 2001 From: Dangoo2002 Date: Sat, 30 Nov 2024 21:48:28 +0300 Subject: [PATCH 2/4] Assignment Feedback --- src/Lecture4_interfaces_abstract_classes/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lecture4_interfaces_abstract_classes/Main.java b/src/Lecture4_interfaces_abstract_classes/Main.java index 3bb0cad..75fc4b5 100644 --- a/src/Lecture4_interfaces_abstract_classes/Main.java +++ b/src/Lecture4_interfaces_abstract_classes/Main.java @@ -10,7 +10,7 @@ public static void main(String[] args) { deposit.printTransactionDetails(); deposit.apply(account); - System.out.println("Account balance after deposit: " + account.getBalance()); + System.out.println("Account balance after amount being deposit: " + account.getBalance()); WithdrawalTransaction withdrawal = new WithdrawalTransaction(200, Calendar.getInstance(), "TX002"); withdrawal.printTransactionDetails(); From 57634236b6163fcff2095e30af0671853b1693ef Mon Sep 17 00:00:00 2001 From: Dangoo2002 Date: Sat, 30 Nov 2024 22:04:37 +0300 Subject: [PATCH 3/4] assignment feedback --- src/Lecture4_interfaces_abstract_classes/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lecture4_interfaces_abstract_classes/Main.java b/src/Lecture4_interfaces_abstract_classes/Main.java index 75fc4b5..8518342 100644 --- a/src/Lecture4_interfaces_abstract_classes/Main.java +++ b/src/Lecture4_interfaces_abstract_classes/Main.java @@ -16,7 +16,7 @@ public static void main(String[] args) { withdrawal.printTransactionDetails(); withdrawal.apply(account); - System.out.println("Account balance after withdrawal: " + account.getBalance()); + System.out.println("Account balance after withdrawing: " + account.getBalance()); if (withdrawal.reverse(account)) { System.out.println("Account balance after reversal: " + account.getBalance()); From c2ec29c131a83b2842473c871c4a33323c24826d Mon Sep 17 00:00:00 2001 From: Dangoo2002 Date: Thu, 5 Dec 2024 11:31:25 +0300 Subject: [PATCH 4/4] Implemented deposit and withdrawal logic, added .gitignore --- .gitignore | 5 +++- .../BankAccount.class | Bin 475 -> 701 bytes .../BankAccount.java | 3 +++ .../BaseTransaction.class | Bin 1776 -> 1847 bytes .../BaseTransaction.java | 10 +++++--- .../DepositTransaction.class | Bin 997 -> 1475 bytes .../DepositTransaction.java | 13 ++++++++++ .../InsufficientFundsException.class | Bin 252 -> 289 bytes .../Main.class | Bin 1597 -> 2259 bytes .../Main.java | 24 ++++++++++++++---- .../TransactionInterface.class | Bin 315 -> 463 bytes .../TransactionInterface.java | 4 ++- .../WithdrawalTransaction.class | Bin 1412 -> 1468 bytes .../WithdrawalTransaction.java | 16 +++++------- 14 files changed, 55 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index f68d109..985ff6c 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,7 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +# Ignore all .class files +*.class diff --git a/src/Lecture4_interfaces_abstract_classes/BankAccount.class b/src/Lecture4_interfaces_abstract_classes/BankAccount.class index 14c015ec3771a88bc9435bae84e65468be3de528..22eca184dd56c75e64cfe5f12207d161fcd3665f 100644 GIT binary patch literal 701 zcmZvZU279T6o%i~d`z-Q+q7w8{b-wNCCOeiUI<=P1Zxq5RE0>PS7CNCNvGY+hTU0< zzr+iFfS0290bck6{88fBZ4xTT!0hZf=Xu|AW`6(q`3t}!+;_pTQAQDsGHzhAgqtpI z;Woz|jx7f6i$EBu7}ya*@v%1AK4HkWk2)vxc@_>SwbIi@y-X&)irxr6polwG_Ha(- z+8tu~P));FTZYo5wr9ggTrw>6t&kVTVmjygVG>F8T&E(nLt!qSN*N}`?w^adq6!z= zRg_TX*r}q4U533ECQe2pEwwVXIqSAL3Zv%SMFjgCcdNLEJ%$H8C2bO^hXZY_ibg`J zcp&`PMnc+w3`88OxO>f*+DNUtbPMC|EB~Bu2AYVbzn18~i>;baB1|Z~(aR7Wc3($i z)3=cllLLnOf5LPz)3his#I>)$%!?>(#s{4f?9%ISdMySgot;j3I=iUQUZp<|Ia+}0 z{Q&b?-{5@Cs+VYA&N4+JIFThHma#J9wn&drO~LyL=hFfyX2Ddvwytyr ze>_~$0jatKFsv@1;~BJ*>bKs1K<$bi6a5jDFUYOszoU>g>mY4*joJk2)aW`Iw6?KH Pv2= amount) { balance -= amount; + } else { + System.out.println("Insufficient balance for withdrawal."); } } } diff --git a/src/Lecture4_interfaces_abstract_classes/BaseTransaction.class b/src/Lecture4_interfaces_abstract_classes/BaseTransaction.class index b6d95202b4945c187a94874680d08fa66fd21775..a38098636a75e2d4ebc4995d1a46aa750856d234 100644 GIT binary patch delta 666 zcmbVJNlqg{5R7VXa$_6l0kbd0#=~N;0ka7Sgwf228>`@86+MN-U>T{q&6NjmLFzMa z00aVw1Df-Eflu%PL{!6x6XFt)l^GeC%6dsYq$>YkAD;lsW6wkiBXJ}#Y9frW7{>LZ zpkX48Nfa&WW=xbZYe8UMs}?L6H@{}Y+3d*ry0X27qsrBzx~H5&X)CuX4_wcYwpX=l z(sh+vtjPNDs%@V%>fX}mwm{5Lr^<1az_%Rs1k8<-hT~s|fkGOY1X|FVz%o_@tiSS9 z78~ACt+*y@s{Thh30U}%KpWcqXYo5<{?f|+p^?ikeo1t0(*d2^31_HV@ z8YK0<^iuLJ&62gWiPFeDLjMrH{?wr7_hSHJ;=}yCLz_oGYkR33M26Vum!g$@J=Wr` xV6GWM^vR-xTv#y90^}TqSq&jiH1HE!WRv|H*uf^(F7e&Q`V@210nP=u_y((lcd-Bf delta 524 zcmYk1O)mpc6o%iq^kYV~HQJ(zX=&@Ds=kSYv1Dgeu0G) zA+fNq^j{=4w&I|zh7Pftl~sL2w53HOe*Ncln>KRG2?`s zj9KJWatjI;v7|!6ibJic5LowjN{doocyhO-H_nRXve|C5Hl~j34=LjxKq`PfsP?c( z`1=tFAc~m1C3d!pCEYT#R#R_Sdbw3I8=8J`QLh=5ytdyyE!TC+GAzxin(cZ;GcS#1 zvsNKrty$W+(W;u2yo8W_D<-7K!V^I0%V4fa7d~nTvTHAOg}>0@gfoV{SF)`5g2t)d()eU{wY!R z#-O>1>5ctU;_M}na+Pau>B@Pd(gMhb_+pf5!PUnx;ZRi4G$EMfd-&AeC&(QZzeW^S j$Z(4+w@l_Th$*3e2-`A%5k#=?h0AvelD7Gx!lgK zE8mgZxrz4-iGo)a4DCfnir4jON%$MQ2yFObPxt{L{TISVhO6s}+m$t5iy4{gUfs9Fs-x-k zu85i!IBLV^G9Vs~Cug*13s=!*VG>gY?pm0}jDf6$S=?jj$a|jBv}@nED*q!3k1=Io5i=>|7-ru|U5~W#(y^d)Im*14c4ScB+H!11NR=*eDy=PM z7#1#7uk-vF<}MYP=YeRD&Ct3n)N)l|3&tA~OkI&6!xj69y~RCCZCwM#og;6;be{&D94-?NBdJT&jRj zD9d?EGIWJ$&w>-Xnoi|P9d|xT(>19G`REK7Qu~yw?DKuXiwXTbKF!O(Q+?)nhS5`z zj@t>Yz+|;hcwY?5_a<; z0XBv729TtFC&6pbZj7LZ)b!Ge(MP>d=NRR`9tQMcnf@l_eue^`qaQ;wZX>8$G?xzB GJAVKc$%;V$ delta 334 zcmW-b%Sr-a6vuzx%;YzYleg?*7t73aH0_>&n{v^rXcx2;3xYr+$Dm!W5Z?pz3@svP z(I#lodqnGAAUb*u=fMAR{+y54x2}Kvy}bhs_B~uu9-6er1eqw4Or=Gd^_XK`v!Ka6 z9-OC=<>OYndwtmH^akCq8JwBC3R+P-pGB55d7otpniZcStBPc+*9-gMZTsfrGQ8?t z^b-+EE@hv9il*wbMop16zbc~=rfL;b%!JmdU1!~VTKBGIW9Z#613OTA=E;6>8j7NM zaB}9(sUB&0d{`C=c|&$gP?0fdh*nCqtn-R`7NGEDdtyaImxwUq#D^#5#|fH4HI6;< dxDqohew&0~izM44Ua`q8TVzE=G88j1*?({SE9L+I diff --git a/src/Lecture4_interfaces_abstract_classes/DepositTransaction.java b/src/Lecture4_interfaces_abstract_classes/DepositTransaction.java index db15e3e..c585717 100644 --- a/src/Lecture4_interfaces_abstract_classes/DepositTransaction.java +++ b/src/Lecture4_interfaces_abstract_classes/DepositTransaction.java @@ -1,4 +1,5 @@ package Lecture4_interfaces_abstract_classes; + import java.util.Calendar; public class DepositTransaction extends BaseTransaction { @@ -11,4 +12,16 @@ public void apply(BankAccount ba) { ba.deposit(getAmount()); System.out.println("Deposited: " + getAmount()); } + + @Override + public boolean reverse(BankAccount ba) { + if (ba.getBalance() >= getAmount()) { + ba.withdraw(getAmount()); + System.out.println("Deposit reversed: " + getAmount()); + return true; + } else { + System.out.println("Unable to reverse deposit: insufficient balance."); + return false; + } + } } diff --git a/src/Lecture4_interfaces_abstract_classes/InsufficientFundsException.class b/src/Lecture4_interfaces_abstract_classes/InsufficientFundsException.class index c4dddd2fc690bc832531a9bd86c0ef245ed0c60a..67311d291d6ed1029a787346023e36b5f1cde430 100644 GIT binary patch delta 67 zcmeyvxR7Z=tD3z}YH~?wQL0INW?o5ZQCebhYH@sGQgKO9Vsc4*a!z7#acZ&t#CWNR V3w-%m7+8Ujk%5DOfq{vE698656pjD@ delta 30 lcmZ3;^oMamE2GrJc&Uj;efgOgSQ%It7#TPi7#NrsI01sm1+4%8 diff --git a/src/Lecture4_interfaces_abstract_classes/Main.class b/src/Lecture4_interfaces_abstract_classes/Main.class index 4318851c6f99dce5f20d61d4de0adbd3e907efca..6d5faf3bc70f22d24b23dd4cc1eff86e196c79dd 100644 GIT binary patch literal 2259 zcmbVO%U2s!82?=!nIQxy;nmWX4v%Wm0-?1PB^4=2vDiRsgQcZayqVm;gEVbW^w1<@BV(@{hs&cuQ#v%05ASD*K@e;t?MRt zUE!wYxmCWc>$Y!slJ}5d`c%BEsM@aKtvK9rNuOa`3i2_m;B$u7mB&+4*QB~f3RYuy zj3*42qIbR#y6=%QTAi$g*fR>&Vt9&YF?@kU3}0eBhOfXG&dl4kC#|k732)Obx?K?z zROm4jL4MDi%G_1M+blZ#IX6RR)-AoxFcLEE2ztyu6(xy#D7J;;N+;fei(vzs48x&q zC*X*p=K4A%!7cfwxiiTyUQ@}CYAF5)DA$h8h$$FybA64T0!WLB&m1!a?t1%wzP(saAhMU4Fa)+UPLwJjp z>q(PkB`0f@d<>OlxRS^=+Gt$%ArtaDt|uzgNVZRg^wsc&oq9k$;!&pvULoy0fn~?V z3`$jkO!BEO(fFW&01+yXtner?F4YOIR?QuTn~B`1Vi)SFpmU=XmibyDgIgdQMHwc8 zR&Tw7ENi?(t*RAk%{8MjhJgw%i;QjQ+><3mGZ|fvjOwF2oOFa?w6W6Xhb<83Rq6%u zKb=~m5^sD?O)octQ<9A_bqBQ&RzXE}^w$hyMJKw-cp|NU%J%XJ{~Fmwt^D6O4C6AreDc>s4-(z^G$v_vk-m(+tylKIexnKX8;y~g z5N)`Mahem9=plTs#P{!EU|HhNl6+zp=Ozd^c!)nA;N|`Wxlel+e?+HT57GJ;w9Dxw znjSK=L&h+P<>@1J#^_rZV*x{Y-4uAehJKo>Xs3S#=V=^;e3v>X0-f~!cjF#;k*9Zj z6}@(_`L=)peo_jGBA@~)_&t_U8?hyAai?9oGG~@aEKnAUM>AP zEesf_^y&0#>B>K1fWaU`1{%jaNO>?EVuVpoeB2V(guzKp>73TmIj;%?Ib&dX4$E^` z3|lCk&f;9e65m9Sw9b@H=FPiOB|%aloU!vyr?T0?R=#YKU|PYNaW)I3TzREv=Sz0B zoGavYW=zg=K_RfRno13O%2|_(Buy?cr*qk4o&}Rdt|-)J3Waj1T(mbAobr>xdMT=L zHOMuSC6;woOs;c7QE7IE)Obgbn3k21bH9 zcfCGr_eY>t$-1ic(Z8%Ok7rt`S=w>0n5u^PQiSQzV|RPwq}Yu$`dCwYJ{Ix+bT2|~}LtuUit@)W2Q(7#JAL8HCvx1lbvcCJH3hvnCc4;m}>a=q$Zb?7NwfRXXcfp z7NsR7rxwR2CKZURm*$mNYlbm0uotD4r4|*Zl4$~C q)Wm$HiEA{~EQzvx;x!{iw#l4~8bU0L47?0{K;JMj@B>LE1_1y_-$^(C delta 82 zcmX@lyqihj)W2Q(7#JAL83frG_}Li*CJH1@{H!3(npjYfQ_096pyA_`n3wICoSa{p kS7JSxpHY`lWU?Xd3v3w%}Qd>$9ic*AD<)ffpiYF7osTs-=nvkySF7e=j3s(PsSX?tVvC%5K5>MwbDdIE*f$N9)BPMYCiV znLa?4sacCcgBbcJS7LEpXly>;g4se31@-Eh2LN>wS9G#H#6E^K-w#JK?*05}0 z1s5z_l;sjuHC(o+#fk9cvcWab3d=3pdeXsBA~c{@z}{ z*AJp}b3fWmI4+Dl$t=@gXU-9Nk9)-=v>98M#>!PE0xlMVYdt#u}Sy#MQ zzA|4tRJ*QCnaQD02J}*@j`*ZjJeM#78LC;zDMxq-Wyuoq4l3z^miVW7;na8NJ5K%^ zj9(vM`(Kb<8p9kz`%H3RnKIMKNE%jY1(>ktD`AR$NP&2l6w?%{LrIlzgcNzG3;DJN z-5`q@%*wvvQPzEGk$Ynd<$w-@TBsjM%_iRVbd{zZ(73u diff --git a/src/Lecture4_interfaces_abstract_classes/WithdrawalTransaction.java b/src/Lecture4_interfaces_abstract_classes/WithdrawalTransaction.java index 8ddfbea..8c6d5ca 100644 --- a/src/Lecture4_interfaces_abstract_classes/WithdrawalTransaction.java +++ b/src/Lecture4_interfaces_abstract_classes/WithdrawalTransaction.java @@ -1,4 +1,5 @@ package Lecture4_interfaces_abstract_classes; + import java.util.Calendar; public class WithdrawalTransaction extends BaseTransaction { @@ -8,18 +9,15 @@ public WithdrawalTransaction(double amount, Calendar date, String transactionID) @Override public void apply(BankAccount ba) { - try { - if (ba.getBalance() >= getAmount()) { - ba.withdraw(getAmount()); - System.out.println("Withdrawn: " + getAmount()); - } else { - throw new InsufficientFundsException("Insufficient funds for withdrawal."); - } - } catch (InsufficientFundsException e) { - System.out.println(e.getMessage()); + if (ba.getBalance() >= getAmount()) { + ba.withdraw(getAmount()); + System.out.println("Withdrawn: " + getAmount()); + } else { + System.out.println("Insufficient funds for withdrawal."); } } + @Override public boolean reverse(BankAccount ba) { ba.deposit(getAmount()); System.out.println("Withdrawal reversed: " + getAmount());