From 3d05bab3bad684e43d4cab77dd83806114ae5c32 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 17 Nov 2022 09:22:27 -0500 Subject: [PATCH 1/2] Solution to satisfy requirements --- .idea/jpa-buddy.xml | 6 ++ .idea/misc.xml | 3 + src/com/example/bankaccount/BankAccount.java | 88 ++++++++++++++++---- src/com/example/main/Main.java | 28 +++++++ 4 files changed, 109 insertions(+), 16 deletions(-) create mode 100644 .idea/jpa-buddy.xml diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 0000000..966d5f5 --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..88ee905 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,4 +3,7 @@ + + \ No newline at end of file diff --git a/src/com/example/bankaccount/BankAccount.java b/src/com/example/bankaccount/BankAccount.java index 6dc00bc..7098624 100644 --- a/src/com/example/bankaccount/BankAccount.java +++ b/src/com/example/bankaccount/BankAccount.java @@ -27,6 +27,10 @@ Class methods(return types): These fields should not be able to be manipulated or access outside this class! */ + private double balance; + private String nameOnAccount; + private int accountNumber; + private String accountType; /* Constructor method should go here @@ -34,26 +38,64 @@ Class methods(return types): then, assign that input to the appropriate field */ - - /* + public BankAccount(double balance, String nameOnAccount, int accountNumber, String accountType) { + this.balance = balance; + this.nameOnAccount = nameOnAccount; + this.accountNumber = accountNumber; + this.accountType = accountType; + } +/* All your getter methods can go below The return type for your getter methods depends on which instance field you are getting! */ + public double getBalance() { + return balance; + } - /* - Here you should write your withdraw method - requirements: - 1. no negatives as input - 2. depending on accountType: - calculate transaction fee of $1.50 (checking only) - calculate interest of 1% on withdrawn amount (savings only) - 3. check balance, do not allow for overdrafting - 4. update balance - 5. return true if successful - otherwise, return false - */ + public String getNameOnAccount() { + return nameOnAccount; + } + + public int getAccountNumber() { + return accountNumber; + } + + public String getAccountType() { + return accountType; + } + /* + Here you should write your withdraw method + requirements: + 1. no negatives as input + 2. depending on accountType: + calculate transaction fee of $1.50 (checking only) + calculate interest of 1% on withdrawn amount (savings only) + 3. check balance, do not allow for overdrafting + 4. update balance + 5. return true if successful + otherwise, return false + */ + public boolean withdraw(double sum) { + double checkingTotalChange = sum + 1.5; + if (sum < 0 + || ( + this.accountType.equalsIgnoreCase("checking") + && checkingTotalChange > this.balance + ) + || sum > this.balance) { + return false; + } + + if (this.accountType.equalsIgnoreCase("checking")) { + this.balance -= checkingTotalChange; + return true; + } + + this.balance -= sum * 1.01; + return true; + } /* Here you should write your deposit method @@ -64,6 +106,13 @@ Class methods(return types): otherwise, return false */ + public boolean deposit(double sum) { + if (sum < 0) { + return false; + } + this.balance += sum; + return true; + } /* Here you should write you toString method @@ -71,6 +120,13 @@ Class methods(return types): 1. returns a String that represents all your instance field values */ - - + @Override + public String toString() { + return "BankAccount{" + + "balance=" + balance + + ", nameOnAccount='" + nameOnAccount + '\'' + + ", accountNumber=" + accountNumber + + ", accountType='" + accountType + '\'' + + '}'; + } } diff --git a/src/com/example/main/Main.java b/src/com/example/main/Main.java index 10c7f11..ca0abef 100644 --- a/src/com/example/main/Main.java +++ b/src/com/example/main/Main.java @@ -16,7 +16,35 @@ we do this to ensure that our class handles input as expected this means that it also has to handle invalid input appropriately */ public static void main(String[] args) { + BankAccount savings = new BankAccount(0, "Adam Roesner", 1, "saving"); + BankAccount checkings = new BankAccount(0, "Adam Roesner", 2, "checking"); + System.out.println(savings); + System.out.println(checkings); + + System.out.println(savings.deposit(100)); + System.out.println(checkings.deposit(-200)); + + System.out.println(savings.toString()); + System.out.println(checkings.toString()); + + System.out.println(savings.withdraw(1000)); + System.out.println(checkings.withdraw(-200)); + + System.out.println(savings.toString()); + System.out.println(checkings.toString()); + + System.out.println(savings.deposit(-100)); + System.out.println(checkings.deposit(200)); + + System.out.println(savings.toString()); + System.out.println(checkings.toString()); + + System.out.println(savings.withdraw(1000)); + System.out.println(checkings.withdraw(198.5)); + + System.out.println(savings.toString()); + System.out.println(checkings.toString()); } } From f160b96847b23b6eede41aecbc5169fdedb01334 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 9 May 2023 16:09:09 -0400 Subject: [PATCH 2/2] gets rid of weird savings thing --- .../com/example/bankaccount/BankAccount.class | Bin 0 -> 2059 bytes .../com/example/main/Main.class | Bin 0 -> 1244 bytes src/com/example/bankaccount/BankAccount.java | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 out/production/JavaIntro2Debrief/com/example/bankaccount/BankAccount.class create mode 100644 out/production/JavaIntro2Debrief/com/example/main/Main.class diff --git a/out/production/JavaIntro2Debrief/com/example/bankaccount/BankAccount.class b/out/production/JavaIntro2Debrief/com/example/bankaccount/BankAccount.class new file mode 100644 index 0000000000000000000000000000000000000000..bb4f7c36c55adbebb0320b85784f93e238aaad6a GIT binary patch literal 2059 zcma)7TW=dh6#gc@tmAHOZZ5Qil0Z^lNMbH6(7I`wIE1=&QbDW$y+}+pt7L0?*Y&Pj zD%1yl0gn^`{RNQ#iGb7xBzWZ4@PfnxLVUBkah%vfjpUs(XU_S~E815Y-VwTwwT~d?52RY47B3Zrw8tPauBTvMuk5KqQmh>_-Cq8j?CrKo@w`aO!#U zGg)uc%>0(LtI{x>mhI)2DK7=GfVL%xXqW_m84dDJlDi+{5^{v~imAYts9MwMtuyo9qF zUe+;*sUx)p(Wo--w`9#N?buG!EJ~Ltk7c^E%HE1E{+apf_b=~cQ;agB;~dfg6LncN zi;itb?<33GrQ~|j_FREWnU!voQnxDGtrEySuk)rrwCHRz>7lY^n?au{a;rv7s_YoD zwkeyI+K0-hw`(!GneubcSP)3=nBMXMm7InZHjJwEqb!bQdRCzBHf)><3QO z%m?TJ;j7Z{oaQ5eC!O;W8U~=(q`h4;-RZL9R9lTgH`N`QBaW&qJQ4_auKL2?0DmK@GtV#$9OvP22M^<6fCw%VxDN~bHy>P$MMiiJ?{k-= LbPd;0#;N}R!N|5; literal 0 HcmV?d00001 diff --git a/out/production/JavaIntro2Debrief/com/example/main/Main.class b/out/production/JavaIntro2Debrief/com/example/main/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..eea5d05da75891e150b6f22d8c7eba20504d4b16 GIT binary patch literal 1244 zcmZ`&&rcIU6#fQEx2(3BV#PUNFEoj6vf~VRCG|9toaU>bKLXhXY%fQ$|V z8M-$3HdjmBT37GoH+0Qq2u>N6;Z8HOr<9z85W|pWo2veln_DGa&2wv$YnolLTy>WA zGu}Rg2!lLR;AZlHt(Ps`2|*^ZGT%0=^#~+Hg=8m#lA6!%tFE{X#nX!iT}m#5V+q2_ue#gl-u<=xwTe z&)82Il`)2KI+bgCCuc~clm;!oAA)5SfTFEce>QOji+S41tL9m6da9KI9W z^D7NzeDz?a_`QagFh!h=S88&@QkQ6=is$Tt&d`}PEPc6R=5^;G&zHy(%i0<*<+x)A z+jj=sqETk(%^u2@COSdQ(35(6@Q6x|;@nv$g7_g}YOMEmC_daI(BcJ>T=?Hxp`6Hy zU2!yh!4TDl#px!*onsJb`T}CKfr(E*^L4URS{bb!qq|^lYvE~{MOe%?XqG(yGMFJN zj9JW)hmzS7x`TG|{r(7PH5v;CVn=pyH0xU(u`aTf-XS(t#c^83y=5$cQ&l9ZI4gV! zoU0pzQ>r-cLH!+}FH~`<5$zi-&{ykp#64LzTA-V_uhoSPp!ZvoLpL2cjwllJP