My code is listed blow but i dont know how to make the direc
My code is listed blow but i don\'t know how to make the directions fit in to my program.
Next, develop a test program in a separate file (call it TestAccount) which, before creating the Account object with ID 1122 as stated in the problem statement (before creating any Accountobjects), sets the annual interest rate to 4.5%, displays its value, and invokes the method getMonthlyInterestRate() and displays its value. Test the program and make sure it works properly.
Now, add method toString() to class Account to allow the user to print out a meaningful description of an Account object using all of it instance variables. For example, the following statement
System.out.print(myObject);
on object myObject would display the account information.
Here is an example of toString() method:
Now, modify the test program to create 2 more Account objects (say myAccount and yourAccount) with different initial balance values. Test all class methods, including all constructors, on these 2 objects in logical order and display meaningful information after each method call (or logically-grouped set of method calls). (Note: Displaying information about the objects using the toString() method is not a substitute for displaying information about the object using the accessor methods.)
Document your code and organize the output using appropriate formatting techniques.
Solution
//my code
import java.text.*;
import java.util.Date;
public class AccountTest
{
public static void main(String[] args){
//formatting the data using the decimalFormat object
DecimalFormat df = new DecimalFormat(\"##.##\");
//Account
Account account = new Account(1122,20000);
account.setAnnualIntrestRate(4.5);
account.withdraw(2500);
account.deposit(3000);
//print out account information
System.out.println(\"Account Balance is : \" + df.format(account.getBalance()));
System.out.println(\"Account Monthly interest is : \" + df.format(account.getAnnualIntrestRate()));
System.out.println(\"Account created date : \" + account.getDateCreated().toString());
//myAccount
Account myAccount = new Account(1123,10000);
myAccount.setAnnualIntrestRate(2.5);
myAccount.withdraw(500);
myAccount.deposit(400);
//print out account information
System.out.println(\"Balance for myAccount : \" + df.format(myAccount.getBalance()));
System.out.println(\"Monthly interest for myAccount : \" + df.format(myAccount.getAnnualIntrestRate()));
System.out.println(\"myAccount created date : \" + myAccount.getDateCreated().toString());
System.out.println(myAccount.toString());
//yourAccount
Account yourAccount = new Account(1125,25000);
yourAccount.setAnnualIntrestRate(4.35);
//before withdrawl
System.out.println(\"Before Withdrawl\");
System.out.println(yourAccount.toString());
yourAccount.withdraw(5000);
//after withdrawl
System.out.println(\"After Withdrawl\");
System.out.println(yourAccount.toString());
//after deposit
System.out.println(\"After Deposit\");
yourAccount.deposit(4000);
System.out.println(yourAccount.toString());
//print out account information
System.out.println(\"Balance for myAccount : \" + df.format(yourAccount.getBalance()));
System.out.println(\"Monthly interest for myAccount : \" + df.format(yourAccount.getAnnualIntrestRate()));
System.out.println(\"myAccount created date : \" + yourAccount.getDateCreated().toString());
System.out.println(yourAccount.toString());
}
}
class Account
{
private int id;
private double balance;
private double annualIntrestRate;
private Date dateCreated;
//constructor
Account(){
id = 0;
balance = 0;
annualIntrestRate = 0;
dateCreated = new Date();
}
//parameterized Constructor
Account(int ID, double BALANCE)
{
id = ID;
balance = BALANCE;
dateCreated = new Date();
}
//getter method for Id
public int getId(){
return id;
}
//getter method for Balance
public double getBalance()
{
return balance;
}
//getter method for annual intrest rate
public double getAnnualIntrestRate()
{
return annualIntrestRate;
}
//setter method for id
public void setId(int id)
{
this.id = id;
}
//setter method for balance
public void setAnnualIntrestRate(double annualIntrestRate)
{
this.annualIntrestRate = annualIntrestRate;
}
//returns the creation date
public Date getDateCreated()
{
return dateCreated;
}
//return monthly interest
public double getMonthlyInterestRate()
{
return annualIntrestRate/12.0;
}
//calculate the balance after withdrawal
public void withdraw(double amount)
{
balance = balance - amount;
}
//calculate the balance after deposit
public void deposit(double amount)
{
balance = balance + amount;
}
@Override
public String toString() {
return \"Account [id=\" + id + \", balance=\" + balance + \", annualIntrestRate=\" + annualIntrestRate
+ \", dateCreated=\" + dateCreated + \"]\";
}
}




