Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a transfer method to the BankAccount class from the previous excercise (Both of my classes are listed below). Your method should move money from

Add a transfer method to the BankAccount class from the previous excercise (Both of my classes are listed below). Your method should move money from one bank account to another account . The method accepts two parameters: a second BankAccount to accept the money, and a real number for the amount of money to transfer. There is a $5.00 fee for transferring money, so this much must be deducted from the current account's balance before any transfer. The method should modify the two bank account objects such that "this" current object has its balance decreased by the given amount plus the $5.00 fee, and the other account's balance is increased by the given amount. If this account's object doesn not have enough money to make the full transfer, transfer whatever money is left after the $5.00 fee is deducted. If the account has under $5.00 or the amount is 0 or less, no transfer should occur and neither account's state should be modified.

(CLASS FOR MY BANKACCOUNT OBJECT):

public class BankAccount{

private String name;

private double transactionFee;

private double balance;

//public BankAccount is the constructor

public BankAccount(String name, double balance){ //<< these parameters will give values

//'this.' initializes the private

this.name = name;

this.balance = balance;

this.transactionFee = 5.00;

}

//^^^ Puts values into them

public void deposit(double amount){

balance = balance + amount;

}

public void withdraw(double amount){

balance = balance - (amount - transactionFee);

}

public String toString(){

return this.name + ", has $" + this.balance;

}

}

(CLASS FOR MY BANKACCOUNT MAIN):

public class BankAccountMain {

public static void main(String[] args) {

BankAccount Mason = new BankAccount("Mason", 20.00);

Mason.withdraw(10);

System.out.println(Mason);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions