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

a) Create a class named BankAccount with fields that hold an account number, the

ID: 642641 • Letter: A

Question

a) Create a class named BankAccount with fields that hold an account number, the owner's name, and the account balance. Include a constructor that initializes each field to appropriate default values. Also include methods to get and set each of the fields. Include a method named deductMonthlyFee() that reduces the balance by $4.00. Include a static method named explainAccountPolicy() that explains that the $4 service fee will be deducted each month. **Note--(provide your best shot in explaining why you would be taking away the money from them

Explanation / Answer


import java.util.*;
import java.lang.*;
import java.io.*;

public class BankAccount {

int accountNumber;
String ownerName;
int accountBalance;
public BankAccount(int accountNumber, String ownerName, int accountBalance) {
super();
this.accountNumber = accountNumber;
this.ownerName = ownerName;
this.accountBalance = accountBalance;
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public int getAccountBalance() {
return accountBalance;
}
public void setAccountBalance(int accountBalance) {
this.accountBalance = accountBalance;
}
  
public void deductMonthlyFee()
{
this.setAccountBalance(this.getAccountBalance()-4);
}
  
public static void explainAccountPolicy()
{
System.out.println("According to polocy the service fee of $4 will be deducted each month");
}
@Override
public String toString() {
return "BankAccount [accountNumber=" + accountNumber + ", ownerName="
+ ownerName + ", accountBalance=" + accountBalance + "]";
}
public BankAccount() {
super();
}
  
  
}


public class TestBankAccount {

Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
TestBankAccount testBankAccount=new TestBankAccount();
BankAccount bankAccount1=testBankAccount.getData();
BankAccount bankAccount2=testBankAccount.getData();
BankAccount bankAccount3=testBankAccount.getData();
BankAccount bankAccount4=new BankAccount();
  
BankAccount.explainAccountPolicy();
  
testBankAccount.showValues(bankAccount1);
testBankAccount.showValues(bankAccount2);
testBankAccount.showValues(bankAccount3);
testBankAccount.showValues(bankAccount4);
}

public BankAccount getData()
{
System.out.println("enter Account number Owner's Name Account Balance");
int accountNumber=sc.nextInt();
String ownerName=sc.next();
int accountBalance=sc.nextInt();
return new BankAccount(accountNumber, ownerName, accountBalance);
}

public void showValues(BankAccount bankAccount)
{
System.out.println("Showing the initial values");
System.out.println("Account Number "+bankAccount.getAccountNumber()+"'s owner is "+bankAccount.getOwnerName()+" having balance "+bankAccount.getAccountBalance());
BankAccount.explainAccountPolicy();
bankAccount.deductMonthlyFee();
System.out.println("Balance after deduction");
System.out.println("Account Number "+bankAccount.getAccountNumber()+"'s owner is "+bankAccount.getOwnerName()+" having balance "+bankAccount.getAccountBalance());

}
  
}