SavingsAccount done, needs docs

This commit is contained in:
2025-04-15 16:30:30 -05:00
parent 06f622ea45
commit 5be70f4643
3 changed files with 14 additions and 16 deletions

View File

@@ -1,3 +1,4 @@
// I put BankAccount and SavingsAccount into a package for the sake of member access
package BankAccount; package BankAccount;
public abstract class BankAccount { public abstract class BankAccount {

View File

@@ -5,42 +5,36 @@ public class SavingsAccount extends BankAccount {
public SavingsAccount(float balance, float annualInterest) { public SavingsAccount(float balance, float annualInterest) {
super(balance, annualInterest); super(balance, annualInterest);
status = balance >= 25; updateStatus();
} }
public void withdraw(float amount) { public void withdraw(float amount) {
if(status) { if(status) {
super.withdraw(amount); super.withdraw(amount);
updateStatus();
} }
else { else {
System.out.println("Cannot withdraw, account is inactive"); System.out.println("Cannot withdraw, account is inactive");
} }
if(balance < 25)
status = false;
} }
public void deposit(float amount) { public void deposit(float amount) {
if(balance + amount >= 25) {
status = true;
}
super.deposit(amount); super.deposit(amount);
updateStatus();
} }
void monthlyProcess() { void monthlyProcess() {
int withdrawlOverAmount = 4 - numWithdrawals; if(numWithdrawals > 4) {
int withdrawlsOverLimit = numWithdrawals - 4;
if(withdrawlOverAmount > 0){ super.serviceCharge += withdrawlsOverLimit;
serviceCharge += withdrawlOverAmount;
} }
super.monthlyProcess(); super.monthlyProcess();
//Update status updateStatus();
} }
public String toString() { public String toString() {
return "Balance: " + balance + "\n Account is active: " + status; return "Balance: " + balance + "\n Account is active: " + status;
} }
//UPDATE_STATUS()????????? private void updateStatus() { status = balance >= 25; }
} }

View File

@@ -1,3 +1,4 @@
// Import the BankAccount package
import BankAccount.*; import BankAccount.*;
public class Main { public class Main {
@@ -10,5 +11,7 @@ public class Main {
System.out.println(SA); System.out.println(SA);
SA.withdraw(5); SA.withdraw(5);
System.out.println(SA); System.out.println(SA);
} }
} }