Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program #2 (10 points): Following the instructions in the problem statement, des

ID: 3689094 • Letter: P

Question

Program #2 (10 points): Following the instructions in the problem statement, design and implement a Java program for programming exercise 9.7, page 361 (call it Account) Next, develop a test program in a separate file (call it TestAccount) to create account object with ID 1122 stated in the problem statement. Test the program and make sure it works properly Now, add method toString(to class Account to allow the user to printout a meanin Account object using all of it instance valuables. For example, the following statement of an System.out.print (myObject) on object myObject would display the account information. 34598755 Account ID: Account Balance $2754.45 Interest Rate: Date Opened: 2.758 Sun Nov 2 14:18:16 EDT 2014 Here is an example of tostring () method // Returns a string representation of student object using name and studentID public String tostring ) // name and studentID are instance variables in class Student return ("The student name is"+ name +", and the ID is "studentID) Now, modify the test program to create 2 more account objects (say myAccout and yourAccount) with different initial balance values. Test all class methods on these 2 objects in logical order and display meaningful information after each method call Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable

Explanation / Answer

Account.java

package org.students;

import java.text.DecimalFormat;
import java.util.Date;

public class Account
{
   DecimalFormat df=new DecimalFormat("#.##");
   //Declaring variables
   private int id=0;
   private double balance=0;
   private double annualInterestRate=0;
   private Date dateCreated;
   //Default Constructor
   public Account() {
       super();
   }
   //Parameterized constructor
   public Account(int id, double balance,double annualInterestRate) {
       super();
       this.id = id;
       this.balance = balance;
       this.annualInterestRate=annualInterestRate;
      
   }
   //Getters and Setters
   public int getId() {
       return id;
   }
   public void setId(int id) {
       this.id = id;
   }
   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 Date getDateCreated() {
       dateCreated=new Date();
       return dateCreated;
   }
   //Method which calculate Monthly Interest Rate.
public double getMonthlyInterestRate()
{double ai=annualInterestRate/100;
   return (ai/12);
   }
//Method which calculate Monthly Interest.
public double getMonthlyInterest()
{
return balance*getMonthlyInterestRate();
}
//Method which returns balance after withdrawl
   public void withdraw(double amount)
   {
       balance=balance-amount;
   }
   //Method which returns balance after deposit
   public void deposit(double amount)
   {
       balance=balance+amount;
   }
   //Method Which is used to display the contents of Account Object.
   @Override
   public String toString() {
       System.out.println("Acount ID :"+id);
       System.out.println("Account Balance :"+balance+" $");
       System.out.println("Monthly Interest :"+df.format(getMonthlyInterest())+" $");
       System.out.println("Date Opened :"+ getDateCreated());
       return "";
   }

}

____________________________________________________________________________________

TestAccount.java

package org.students;

import java.text.DecimalFormat;

public class TestAccount {

   public static void main(String[] args)
   {
      
       //Account Object Created
       Account myAccount=new Account(1122,20000,4.5);
       //Calling Methods on Account Object
       myAccount.withdraw(2500);
       myAccount.deposit(3000);
       //Calling toString
       System.out.println("============My Account Details=================");
       System.out.println(myAccount.toString());
}

}

________________________________________________________________________________________

output:

============My Account Details=================
Acount ID       :1122
Account Balance   :20500.0 $
Monthly Interest   :76.88 $
Date Opened       :Thu Apr 14 00:22:21 IST 2016

__________________________________________________________________________________________

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote