Commit 9b4e69e6 authored by reece.french's avatar reece.french

Assessment Exercise 3

parent 77c2073e
public class bankAccount {
int accountNumber;
String name;
int balance;
int addOverdraft;
public bankAccount(int ID, String owner, int overallBalance, int overdraftLimit) {
accountNumber = ID;
name = owner;
balance = overallBalance;
addOverdraft = overdraftLimit;
}
public String display() {
return "Account number: " + accountNumber + "\n" + "Name: " + name + "\n" + "Balance: " + "£" + balance +
"\n" + "Overdraft: " + "£" + addOverdraft + "\n";
}
public static void main (String[] args) {
bankAccount details = new bankAccount( 13267845, "Reece", 2000, 500);
details.bankFees(5);
System.out.print(details.display());
details.deposit(0);
System.out.println(details.display());
details.withdrawal(3000, 500);
System.out.println(details.display());
}
public int deposit(int deposit) {
balance = deposit + balance;
System.out.println("\n" + "You have deposited " + "£" + deposit + "." + "\n");
return balance;
}
public int withdrawal(int withdrawal, int limit) {
addOverdraft = limit;
if (withdrawal == balance) {
balance = 0;
addOverdraft = limit;
} else if (withdrawal > balance) {
addOverdraft = limit + balance - withdrawal;
balance = 0;
System.out.print("\n" + "You have gone into your overdraft." + "\n");
} else {
balance = balance - withdrawal;
System.out.println("\n" + "You have made a withdrawal of " + "£" + withdrawal + "." + "\n");
}
return balance;
}
public int bankFees(int bankFees) {
balance = balance - ((balance / 100) * bankFees);
return balance;
}
}
class savingsAccount extends bankAccount{
public savingsAccount(int ID, String owner, int overallBalance, int overdraftLimit) {
super(ID, owner, overallBalance, overdraftLimit);
}
public String display() {
return "Account number: " + accountNumber + "\n" + "Name: " + name + "\n" + "Balance: " + "£" + balance;
}
public static void main (String[] args) {
savingsAccount details = new savingsAccount(16253702, "Reece", 1000, 0);
details.accrueInterest(5);
System.out.println(details.display());
details.withdrawal(100);
System.out.print(details.display());
}
public int withdrawal(int withdrawal) {
balance = (balance - withdrawal);
if (withdrawal > balance) {
balance = 0;
System.out.println("\n" + "no additional funds." + "\n");
} else {
System.out.println("\n" + "You have made a withdrawal of " + "£" + withdrawal + "." + "\n");
}
return balance;
}
public int accrueInterest(int accrueInterest) {
balance = balance + ((balance / 100) * accrueInterest);
return 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