In: Computer Science
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
package add;
public class MainAcount {
public static void main(String[] args) {
Account account = new Account("AC1111", 25000.0,3.5);
account.withdraw(3500.0);
account.deposit(3500.0);
System.out.println("Balance: $" + account.getBalance());
System.out.format("Monthly Interest: %.2f\n" ,account.getMonthlyInterest());
System.out.println("Date Created: " + account.getDateCreated());
}
}
class Account {
private String id = "";
private double balance = 0.0;
private static double annualInterestRate = 0.0;
private java.util.Date dateCreated;
public Account() {
dateCreated = new java.util.Date();
}
public Account(String id, double balance,double annualInterestRate ) {
this();
this.id = id;
this.balance = balance;
this.annualInterestRate=annualInterestRate;
}
public String getId() {
return this.id;
}
public double getBalance() {
return this.balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public String getDateCreated() {
return this.dateCreated.toString();
}
public void setId(String id) {
this.id = id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public double getMonthlyInterestRate() {
return (annualInterestRate / 100) / 12 ;
}
public double getMonthlyInterest() {
return balance * getMonthlyInterestRate();
}
public void withdraw(double amount) {
this.balance -= amount;
}
public void deposit(double amount) {
this.balance += amount;
}
}
OUTPUT:-
Balance: $25000.0
Monthly Interest: 72.92
Date Created: Thu Oct 22 11:55:01 IST 2020