Question: Can someone help me understand how to format the Method named getMonthlyInterest() that returns the earned monthly interest amount (i.e., balance * monthlyInterestRate, formatted as
Can someone help me understand how to format the "Method named getMonthlyInterest() that returns the earned monthly interest amount (i.e., balance * monthlyInterestRate, formatted as currency ($)).
import java.util.*;
public class BankAccount {
private int id = 0; private double balance = 0; private double annualInterestRate = 0; private double monthlyInterestRate; private Date dateCreated;
public BankAccount() { } // END default constructor
public BankAccount (int i, double b) { this.id = i; this.balance = b; this.dateCreated = new Date(); } // END constructor public int getid() { return id; } // END METHOD setid public void setid(int i) { this.id = i; } // END METHOD setid public double getBalance() { return balance; } // END METHOD getBalance public void setBalance(double b) { this.balance = b; } // END METHOD setBalance public double getannualInterestRate() { return annualInterestRate; } // END METHOD getannulInterestRate public void setannualInterestRate(double a) { this.annualInterestRate = a; } // END METHOD setannualInterestRate public Date getDateCreated() { return dateCreated; } // END METHOD dateCreated public double getMonthlyInterestRate() { double monthlyInterestRate = annualInterestRate/12; return monthlyInterestRate; } // END METHOD getMonthlyInterestRate public void setWithdraw(double withdraw) { balance -= withdraw; } // END METHOD getWithdraw public void setDeposit (double deposit) { balance += deposit; } // END METHOD getDeposit public String toString() { return "Account Balance: " + java.text.NumberFormat.getCurrencyInstance().format (getBalance()) + " " + "Earned monthly interest: " + getMonthlyInterestRate() + " " + "Date Opened: " + getDateCreated(); } // END METHOD toString
} // END class BankAccount
import java.util.*;
public class TestBankAccount {
public static void main(String[] args) { BankAccount myObject = new BankAccount (123456,10000); System.out.println("Account ID is: \t\t" + myObject.getid()); System.out.printf("The initial balance: " + java.text.NumberFormat.getCurrencyInstance().format (myObject.getBalance())); myObject.setannualInterestRate(2.5); System.out.printf(" Interest Rate: \t\t" + "%.1f%%",myObject.getannualInterestRate()); System.out.println(" Withdraw: $3500\t\t\t\t"); myObject.setWithdraw(3500); java.text.NumberFormat.getCurrencyInstance().format (myObject.getBalance()); System.out.println("Deposit: $500\t\t\t\t"); myObject.setDeposit(500); java.text.NumberFormat.getCurrencyInstance().format (myObject.getBalance()); System.out.println(); System.out.println(myObject.toString()); } // END METHOD Main
} // END TestBankAccount Program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
