Finished BackAccount abstract.

Made rough SavingsAccount
This commit is contained in:
2025-04-09 11:43:38 -05:00
parent 30872f5bbb
commit 06f622ea45
4 changed files with 102 additions and 10 deletions

View File

@@ -1,7 +0,0 @@
public abstract class BankAccount {
private float balance;
private int numDeposits;
}

View File

@@ -0,0 +1,47 @@
package BankAccount;
public abstract class BankAccount {
float balance;
int numDeposits;
int numWithdrawals;
float annualInterest;
float serviceCharge;
public BankAccount(float balance, float annualInterest) {
this.balance = balance;
this.annualInterest = annualInterest;
}
public void deposit(float amount) {
balance += amount;
numDeposits++;
}
public void withdraw(float amount) {
if(balance >= amount) {
balance -= amount;
numWithdrawals++;
}
else {
System.out.println("Insufficient balance");
}
}
void calculateInterest() {
float monthlyRate = annualInterest / 12;
float monthlyInterest = balance * monthlyRate;
balance += monthlyInterest;
}
void monthlyProcess() {
balance -= serviceCharge;
calculateInterest();
}
public String toString() {
return "Balance: " + balance;
}
}

View File

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

View File

@@ -1,8 +1,14 @@
import BankAccount.*;
public class Main {
public static void main(String[] args) {
// Testing the rough version of SavingsAccount
// Yipee
System.out.println("Hello, World!");
SavingsAccount SA = new SavingsAccount(30, 2);
System.out.println(SA);
SA.withdraw(6);
System.out.println(SA);
SA.withdraw(5);
System.out.println(SA);
}
}