Commit 9386f8b2 authored by gavin.white's avatar gavin.white

Add new file

parents
public class BankAccount {
// instance variables
private double balance;
private int accountNumber;
private String name;
private double overdraftLimit;
// constructor
public BankAccount(int accountNumber, String name) {
this.accountNumber = accountNumber;
this.name = name;
this.balance = 0.0;
this.overdraftLimit = 0.0;
}
// methods
public double getBalance() {
return this.balance;
}
public void deposit(double amount) {
this.balance += amount;
}
public void withdraw(double amount) {
if (this.balance + this.overdraftLimit >= amount) {
this.balance -= amount;
} else {
System.out.println("Insufficient funds");
}
}
public void bankFees() {
// apply a 5% fee on the current balance
double fee = this.balance * 0.05;
this.balance -= fee;
}
public void display() {
System.out.println("Account Number: " + this.accountNumber);
System.out.println("Account Holder: " + this.name);
System.out.println("Current Balance: " + this.balance);
}
public void addOverdraft(double overdraftLimit) {
this.overdraftLimit = overdraftLimit;
}
}
class SavingsAccount extends BankAccount {
// constructor
public SavingsAccount(int accountNumber, String name) {
super(accountNumber, name);
}
// accrue interest on the current balance
public void accrueInterest() {
double interest = this.getBalance() * 0.05;
this.deposit(interest);
}
// override the addOverdraft() method to prevent a SavingsAccount from having an
// overdraft limit
@Override
public void addOverdraft(double overdraftLimit) {
// do nothing
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment