Hello everyone, how do i get my code to output "The annual interest rate is: 4.5" and not. "The annual interest rate is:0.045".
Below i have attached my code thank you.
import java.util.Date;
public class Account {
public static void main(String[] args) {
// TODO Auto-generated method stub
Account account1 = new Account(1122, 20000.00, .045);
account1.withdraw(2500);
account1.deposit(3000);
System.out.println("The balance is: " + account1.getBalance());
System.out.println("The monthly interest is: " + account1.monthlyInterest());
System.out.println("The monthly interest rate is: " + account1.getMonthlyInterestRate());
System.out.println("The anunual interest rate is:" + account1.getAnnualInterestRate());
}
//define variables
private double id;
private double balance; // balance for account
private double annualInterestRate; //stores the current interest rate
private Date dateCreated; //stores the date account created
//no arg construtor
Account () {
id = 0.0;
balance = 0.0;
annualInterestRate = 0.0;
}
//constructor with specific id and initial balance
Account(double newId, double newBalance) {
id = newId;
balance = newBalance;
}
Account(double newId, double newBalance, double newAnnualInterestRate) {
id = newId;
balance = newBalance;
annualInterestRate = newAnnualInterestRate;
}
//accessor/mutator methods for id, balance, and annualInterestRate
public double getId() {
return id;
}
public double getBalance() {
return balance;
}
public double monthlyInterest() {
return balance * getMonthlyInterestRate();
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int newId) {
id = newId;
}
public void setBalance(double newBalance) {
balance = newBalance;
}
public void setAnnualInterestRate(double newAnnualInterestRate) {
annualInterestRate = newAnnualInterestRate;
}
//accessor method for dateCreated
public void setDateCreated(Date newDateCreated) {
dateCreated = newDateCreated;
}
//define method getMonthlyInterestRate
double getMonthlyInterestRate() {
return annualInterestRate/12;
}
//define method withdraw
double withdraw(double amount) {
return balance -= amount;
}
//define method deposit
double deposit(double amount) {
return balance += amount;
}
}