Finished BackAccount abstract.
Made rough SavingsAccount
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
public abstract class BankAccount {
|
|
||||||
private float balance;
|
|
||||||
private int numDeposits;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
47
src/BankAccount/BankAccount.java
Normal file
47
src/BankAccount/BankAccount.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
46
src/BankAccount/SavingsAccount.java
Normal file
46
src/BankAccount/SavingsAccount.java
Normal 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()?????????
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
|
import BankAccount.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
// Testing the rough version of SavingsAccount
|
||||||
|
|
||||||
// Yipee
|
SavingsAccount SA = new SavingsAccount(30, 2);
|
||||||
|
System.out.println(SA);
|
||||||
System.out.println("Hello, World!");
|
SA.withdraw(6);
|
||||||
|
System.out.println(SA);
|
||||||
|
SA.withdraw(5);
|
||||||
|
System.out.println(SA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user