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

(The Account Class) Design a class named Account that contains: A private (int)

ID: 3541389 • Letter: #

Question

(The Account Class) Design a class named Account that contains:
A private (int) data field named (id) for the account (default 0) A private double data field named balance for the account (default 0) A private double data field name annualInterestRate that stores the current interest rate (default 0), Assume all accounts have the same interest rate.
A no-arg constructor that creates a default account A constructor that creates an account with the specified id and initial balance. The accessor and mutator methods for id, balance, and annualInterestRate The accessor method for dateCreated A method named getMonthlyInteresrRate() that returns 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.

The method getMonthlyInterest() is to return monthly interest, not the interest rate. Montly 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.
Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use thewithdraw method to withdraw $2,500, use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when this account  was created.
(The Account Class) Design a class named Account that contains:
A private (int) data field named (id) for the account (default 0) A private double data field named balance for the account (default 0) A private double data field name annualInterestRate that stores the current interest rate (default 0), Assume all accounts have the same interest rate.
A no-arg constructor that creates a default account A constructor that creates an account with the specified id and initial balance. The accessor and mutator methods for id, balance, and annualInterestRate The accessor method for dateCreated A method named getMonthlyInteresrRate() that returns 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.

The method getMonthlyInterest() is to return monthly interest, not the interest rate. Montly 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.
Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use thewithdraw method to withdraw $2,500, use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when this account  was created.

Explanation / Answer

Sample Output



Initial account balance : $20000.0

Withdrawing $2500:

2500.0 is deducted from your account. Your present balance is: $17500.0

balance after withdrawl: $17500.0

Depositing $3000

3000.0 is deposited in your account. Your present balance is: $20500.0

Now the balance in account is: $20500.0

Monthly Interest is: $76.875


Account was created on: 05/09/2013





Code



FIRST CLASS





import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.*;


public class BankAccount {

//variables

private int id ;

private double balance;

private double annualInterestRate;


// no argument constructor

public BankAccount() {

this.id = 0;

this.balance = 0;

this.annualInterestRate = 0;

  

}


//parameterized constructor

public BankAccount(int id, double balance) {

this.id = id;

this.balance = balance;

}


//accessors and mutators

public void setID(int id) {

this.id = id;

}


public int getID() {

return this.id;

}


public void setBalance(double balance) {

this.balance = balance;

}


public double getbalance() {

return this.balance;

}


public void setAnnualInterestrate(double annualInterestRate) {

this.annualInterestRate = annualInterestRate;

}


public double getAnnualInterestrate() {

return this.annualInterestRate;

}


// get date created method

public String getDateCreated() {

DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

Date date = new Date();

System.out.println();

return dateFormat.format(date);

}


//monthly interest rate method

public double getMonthlyInterestRate() {

return (this.annualInterestRate) / 12;

}


  

//withdraw method

public void withdraw(double amount) {

if (this.balance < amount) {

System.out.println("Sorry!!! Insufficient balance.");

} else {

this.balance -= amount;

System.out.println(amount + " is deducted from your account. Your present balance is: $" + this.balance);

}

}


//deposit method

public void deposit(double amount) {

this.balance += amount;

System.out.println(amount + " is deposited in your account. Your present balance is: $" + this.balance);

}


  

}