Commit 2eca50e4 authored by lui.bingham's avatar lui.bingham

Exercise 3

parents
import java.text.DecimalFormat;
public class BankAccount {
int accountNumber;
String name;
double balance;
double deposit;
double withdrawal;
double bankfees;
private static final DecimalFormat PoundsFormat = new DecimalFormat("0.00");
public BankAccount(int accountNumber, String name, double balance)
{
this.accountNumber = accountNumber;
this.name = name;
this.balance = balance;
}
public void deposit(double deposit)
{
this.deposit = deposit;
balance = balance + deposit;
}
public void withdrawal(double withdrawal)
{
this.withdrawal = withdrawal;
bankFees();
}
public void addOverdraft(double OverdraftLimit)
{
if((balance - withdrawal) - bankfees < -OverdraftLimit)
{
System.out.println("Your specified withdrawal amount exceeds the overdraft limit. Please withdraw a lower amount.");
}
else
{
balance = (balance - withdrawal) - bankfees;
}
}
public void bankFees()
{
if(balance > 0.00)
{
bankfees = (balance / 100) * 5;
}
else
{
bankfees = (balance / 100) * -5;
}
addOverdraft(100.00);
}
public void display()
{
System.out.println("Account Number: " + accountNumber);
System.out.println("Account Owner: " + name);
System.out.println("Balance: £" + PoundsFormat.format(balance));
}
}
public class Main {
public static void main(String[] args) {
BankAccount bankAccount = new BankAccount(1, "Lui", 100.00);
SavingsAccount savingsAccount = new SavingsAccount(1, "Lui", 100.00);
bankAccount.withdrawal(50.00);
bankAccount.display();
savingsAccount.withdrawal(50.00);
savingsAccount.display();
}
}
import java.text.DecimalFormat;
public class SavingsAccount {
int accountNumber;
String name;
double balance;
double deposit;
double withdrawal;
double bankfees;
double interest;
private static final DecimalFormat PoundsFormat = new DecimalFormat("0.00");
public SavingsAccount(int accountNumber, String name, double balance)
{
this.accountNumber = accountNumber;
this.name = name;
this.balance = balance;
}
public void deposit(double deposit)
{
this.deposit = deposit;
balance = balance + deposit;
interest = (balance / 100) * 5;
accrueInterest(interest);
}
public void withdrawal(double withdrawal)
{
this.withdrawal = withdrawal;
if(withdrawal > balance)
{
System.out.println("You have insufficient funds to withdraw that amount. Your current balance is: £" + PoundsFormat.format(balance));
}
if(withdrawal > 100.00)
{
System.out.println("You can't withdraw more than £100.00 from your saving accounts. Please withdraw a lower amount.");
}
else
{
balance = balance - withdrawal;
interest = (balance / 100) * -5;
accrueInterest(interest);
}
}
public void accrueInterest(double interest)
{
balance = balance + interest;
}
public void display()
{
System.out.println("Account Number: " + accountNumber);
System.out.println("Account Owner: " + name);
System.out.println("Balance: £" + PoundsFormat.format(balance));
}
}
\ No newline at end of file
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