Commit b078e44f authored by jinny.wilkin's avatar jinny.wilkin

Section1 complete

parents
File added
public class App{
public static void main(String[] args) throws Exception {
BankAccount account1 = new BankAccount(12345678, "Jinny Wilkin", 420.69);
account1.deposit(0.01);
account1.withdrawal(420);
account1.withdrawal(1);
account1.deposit(99.30);
account1.bankFees();
account1.display();
}
}
import java.text.DecimalFormat;
public class BankAccount {
protected String name;
protected int accountNumber;
protected double balance;
private static final DecimalFormat df = new DecimalFormat("0.00");
public BankAccount(int accNum, String name, double currBal){
this.name = name;
this.accountNumber = accNum;
this.balance = currBal;
}
public void deposit(double dep){
this.balance += dep;
System.out.println("The new balance is £" + df.format(this.balance));
}
public void withdrawal(double wd){
if(wd < this.balance){
this.balance -= wd;
}else{
System.out.println("You are attempting to withdraw more than your current balance");
}
}
public void bankFees(){
double fee = this.balance * 0.05f;
this.balance -= fee;
System.out.println("Thank you for paying your bank fees. Your current balance is £"+ df.format(this.balance));
}
public void display(){
System.out.println("Your Account Details:");
System.out.format("Account Number: %-20d Account Name: %-32s Current Balance: £%-16s", this.accountNumber, this.name, df.format(this.balance));
}
}
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