1 Define an Account class with the following private data fi
1. Define an Account class with the following private data fields:
An int data field named id for the Account user name (default 0).
A String data field named name for the Account user name (default “NA”).
A double data field named balance for the Account (default 0).
A double data field named annualInterestRate that stores the current interest rate (default 0).
A Date data field named dateCreated that stores the date when the Account was created.
2. Implement the following methods for the Account class:
A no-arg constructor that creates a default Account.
The accessor and mutator methods for id, name, balance, and annualInterestRate.
The accessor method for dateCreated.
A method named getMonthlyInterestRate() that returns the monthly interest rate.
A method named getMonthlyInterest() that returns the monthly interest.
A method named withdraw that withdraws a specified amount from the Account.
A method named deposit that deposits a specified amount to the Account.
A method named readData() that will ask user to enter the following information in order:
1. Id, 2. Name, 3. Initial balance, 4. Annual interest rate, 5. Deposit amount, and 6. Withdraw
amount
A method named printReceipt() that will print the Id, Account name, the date Account was
created, monthly interest and current balance.
Hint: The method getMonthlyInterest() is to return monthly interest, not the interest rate.
Monthly interest is balance * monthlyInterestRate. monthlyInterestRate is
annualInterestRate / 12. Note that annualInterestRate is a percentage,
e.g., like 4.5%. You need to divide it by 100.
3. Write a test program that creates two Account objects, each object should call readData() to prompt
users to enter the following information and call printReceipt() to print the results.
o Object 1 – id: 1001; user name: John; initial balance: 20000; annual interest rate: 4.5,
withdraw: 2500; deposit: 3000
o Object 2 – id:1002; user name: Mary; initial balance: 10000; annual interest rate: 3.5;
withdraw: 500; deposit: 1000
o DO NOT hardcode these numbers in the program.
Solution
public class Account
{
private int accountNumber;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
public Account()
{
this(1122, 20000, 4.5);
}
public Account(int accountNumber, double balance, double annualInterestRate){
this.accountNumber = accountNumber;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
dateCreated = new java.util.Date();
}
public int getAccountNumber()
{
return accountNumber;
}
public void setAccountNumber(int accountNumber)
{
this.accountNumber = accountNumber;
}
public double getBalance()
{
return balance;
}
public void setBalance(double balance)
{
this.balance = balance;
}
public double getAnnualInterestRate()
{
return annualInterestRate;
}
public void setAnnualInterestRate( double annualInterestRate)
{
this.annualInterestRate = annualInterestRate;
}
public java.util.Date getDateCreated()
{
return dateCreated;
}
public double getMonthlyInterestRate() {
double monthlyInterestRate = annualInterestRate/12;
return monthlyInterestRate;
}
public double withDraw (double ammountWithdrawn, double balance) {
double newBalance = balance - ammountWithdrawn;
System.out.println(\"Your withdrawl has processed. New balance: \" + newBalance);
balance = (int) newBalance;
return newBalance;
}
public double deposit(double amountDeposited, int balance)
{
double newBalance = balance + amountDeposited;
System.out.println(\"Your deposit has processed. New Balance is: \" + newBalance);
balance = (int) newBalance;
return newBalance;
}
public static void main (String[] args)
{
Account account = new Account (1122, 20000, 4.5);
System.out.println(\"Monthly interest rate is \" + account.getMonthlyInterestRate());
System.out.println(\"The account was created on \" + account.getDateCreated());
}
}



