Suppose the following BankAccount class has been created: 1 // Each BankAccount
ID: 3886315 • Letter: S
Question
Suppose the following BankAccount class has been created:
1 // Each BankAccount object represents one user's account
2 // information including name and balance of money.
3 public class BankAccount {
4 String name;
5 double balance;
6
7 public void deposit(double amount) {
8 balance = balance + amount;
9 }
10
11 public void withdraw(double amount) {
12 balance = balance - amount;
Add a field to the BankAccount class named transactionFee for a real number representing an amount of money
to deduct every time the user withdraws money. The default value is $0.00, but the client can change the value.
Deduct the transaction fee money during every withdraw call (but not from deposits). Make sure that the balance
cannot go negative during a withdrawal. If the withdrawal (amount plus transaction fee) would cause it to become
negative, don’t modify the balance at all.
Add a toString method to the BankAccount class from the previous exercise. Your method should return a string that
contains the account's name and balance separated by a comma and space. For example, if an account object named yana
has the name "Yana" and a balance of 3.03, the call yana.toString() should return the string "Yana, $3.03".
Add a transfer method to the BankAccount class from the previous exercises. Your method should move money
from the current 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 BankAccount objects such that “this” current object has its balance decreased by the given amount
plus the $5 fee, and the other account's balance is increased by the given amount. If this account object does not have
enough money to make the full transfer, transfer whatever money is left after the $5 fee is deducted. If this account
has under $5 or the amount is 0 or less, no transfer should occur and neither account's state should be modified. The
following are some example calls to the method:
BankAccount ben = new BankAccount();
ben.deposit(80.00);
BankAccount hal = new BankAccount();
hal.deposit(20.00);
ben.transfer(hal, 20.00); // ben $55, hal $40 (ben -$25, hal +$20)
ben.transfer(hal, 10.00); // ben $40, hal $50 (ben -$15, hal +$10)
hal.transfer(ben, 60.00); // ben $85, hal $ 0 (ben +$45, hal -$50)
There are five requirements in the picture. Please help me answer these five questions.
return shift CS50x2 In-Lab: BankSoft All classes should have special methods, called constructors, that are called to create and prepare the object for use Typically, the constructor accepts parámeters that are then used to initial the data fields of the object. It is also possible that the method does not accept parameters. Add two constructors to the BankAccount class; one that accepts the appropriate number of parameters and one that does not require parameters. The parameter-less constructor should call the parameter-based constructor with default values. I Add an updateTransactionFee method to the BankAccount class. The method accepts one parameter: a real number representing the new transaction fee amount. It should return true if the new fee is greater than the previous fee and false if the new fee is equal to or lower than the previous fee Most bank accounts earn interest, either daily, monthly, or yearly. Add a calculateInterest method to the BankAccount class that will calculate the amount of interest the account would accrue if left untouched for a given amount of time. For this exercise, use the compounding interest formula to calculate the amount of interest. How many parameters should the calculateInterest accept? This method should only calculate the interest and inform the user of their expected gains 3 The payInterest method that should also be added to the BankAccount class would perform the action of adding the earned interest to the account balance. Again, how many parameters should this method accept? 4 ose that the bank manager needs to determine when each account was opened (e.g. 2007-12-03T10: 15:30) Incorporate this information into the BankAccount classExplanation / Answer
import java.util.Scanner;
public class BankAccount {
String name;
double balance;
double transactionFee = 0;
static Scanner scanner = new Scanner(System.in);
public BankAccount(String name, double balance) {
this.name = name;
this.balance = balance;
}
public BankAccount() {
this("ram",0);
}
public String getName() {
return name;
}
public double getBalance() {
return balance;
}
public void deposit(double amount) {
balance = balance + amount;
}
public void withdraw(double amount) {
if (balance > 0 & balance > amount) {
System.out.println("enter the transaction fee");
transactionFee = scanner.nextDouble();
balance = balance - amount;
balance = balance - transactionFee;
} else
System.out
.println("withdraw is not possible due to insufficient funds");
}
@Override
public String toString() {
return "BankAccount [name=" + name + ", balance=" + balance + "]";
}
public void transfer(BankAccount account, double transfermoney) {
if (this.balance < 5) {
double transferMoney = this.balance - transfermoney;
double movingAccountBalance = account.getBalance() + transfermoney;
}
}
public boolean uadateTransactionFee(double updateTransactionFee)
{
if(updateTransactionFee>transactionFee)
return true;
return false;
}
public void findCompoundInterest()
{
System.out.println("enter interest rate");
double rate=scanner.nextDouble();
System.out.println("enter how many times you want to calculate the interest is compounded per year");
int n=scanner.nextInt();
System.out.println("enter time in years");
int t=scanner.nextInt();
double amount=balance*Math.pow((1+(rate/n)), t);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.