Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# To the BankingLib project add a class Account with private fields _accountNum

ID: 3872587 • Letter: C

Question

C# To the BankingLib project add a class Account with private fields _accountNumber, _currentBalance, _bankName. Add the constructor and properties Add methods: Deposit(amount) and Withdraw(amount) One adds the amount to the _currentBalance and the other removes the amount from the _currentBalance. Be careful not to remove if the account does not have enough money. Add a static method, Transfer (fromAccount, toAccount, amount), that takes the amount from the fromAccount and adds it to the toAccount. Of course make sure that the fromAccount has sufficient funds.

Explanation / Answer

public class BankAccount {
    public int balance;
    public final String accountNumber;
    public String transactionLog;

    public BankAccount(String accountNumber) {
    this.accountNumber = accountNumber;
    this.balance = 0;
    this.transactionLog = "";
    }


    public String report() {
        String s = "";
        s = transactionLog +" "+ "Balance: $"+ balance;
       return s;
    }


    public int getBalance() {
  
    return balance;
    }


    public void transfer(int transferAmount, BankAccount fromAccount) {
     if (transferAmount < 0 && transferAmount > fromAccount.balance)
   {
      
   }

else
{  
       balance = balance + transferAmount;
       fromAccount.balance = fromAccount.balance - transferAmount;
    transactionLog = "Deposit: $"+balance+" "+"Transfer from "+fromAccount.accountNumber+" : $"+transferAmount;
    System.out.println(report());
}
    }


    public void withdraw(int withdrawalAmount) {
     if (withdrawalAmount < 0 && withdrawalAmount > balance)
   {
      
   }

      else
   {  
       balance = balance - withdrawalAmount;
       transactionLog = "Deposit: $"+balance+" "+"Withdrawal: $"+withdrawalAmount;
    System.out.println(report());
      }
      
    }
    public void deposit(int depositAmount) {
   if (depositAmount < 0)
   {
      
   }

      else
   
       balance = balance + depositAmount;
       transactionLog = "Deposit: $"+balance;
    System.out.println(report());
      }
    }