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

Project: The Account Class Problem Description The Aecount clasa) Design a class

ID: 3748093 • Letter: P

Question

Project: The Account Class Problem Description The Aecount clasa) Design a class named ecount that * A private data field named id for the account (default 0) * A private do Le data field named for the account (default ) A private doubile data field namedatancatRats that stores the current interest rate (default ssume all accounts have the sane interest rate stores the date when the account was created o- constructor that creates a default account specified id and initial balance * A private Date data field named gateczsated, that *A constructor that creates an account with the * The esesaaaandtasaa methods for id, bal ce, and A method naned that returns *method naned withdzaw that withdraMsaspecified *method naned deposit that deposits a specified the monthly interest rate anount from the account anount to thc account Draw the UML diagram for the class. Implenent the class. rite 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.58. Use the withdraw 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. Aralysis: (30 points)

Explanation / Answer

Account.java

import java.util.Date;

public class Account {

   //Declaring instance variables
   private int id;
   private double balance;
   static private double annualInterestRate=0;
   private Date dateCreated;
  
   //Zero argumented constructor
   public Account() {
       dateCreated = new Date();
   }
  
   //Parameterized constructor
   public Account(int id, double balance) {
       this.id = id;
       this.balance = balance;
       dateCreated = new Date();
   }
  
   //Setters and getters
   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 static double getAnnualInterestRate() {
       return annualInterestRate;
   }
   public static void setAnnualInterestRate(double annualInterestRate) {
       Account.annualInterestRate = annualInterestRate;
   }
   public Date getDateCreated() {
       return dateCreated;
   }

   //This method will calculate and return the monthly interest rate
   public double getMonthlyInterestRate()
   {
       double monthlyInterestRate=getAnnualInterestRate()/1200;
       return monthlyInterestRate;
   }
  
   //This method will calculate and return the monthly interest amount
   public double getMonthlyInterest()
   {
   double monthlyInterest=getBalance()*getMonthlyInterestRate();
   return monthlyInterest;  
   }
  
   //This method will do the withdraw transaction
   public void withdraw(double amount)
   {
       balance=getBalance()-amount;
      
   }
  
   //This method will do the deposit transaction
   public void deposit(double amount)
   {
       balance=getBalance()+amount;
   }
  

}

________________

Test.java

public class Test {

   public static void main(String[] args) {
   //Creating Account class object by passing inputs as arguments  
   Account acc1=new Account(1122,20000);
  
   //Calling the method on the Account class
   acc1.setAnnualInterestRate(4.5);
  
   //Displaying the Account information before any other transaction
   System.out.println("Your Account balance is :"+acc1.getBalance());
System.out.println("Monthly Interest is :"+acc1.getMonthlyInterest());
System.out.println("Your Account is created on :"+acc1.getDateCreated());

   //Displaying the Account information after withdraw amount
acc1.withdraw(2500);
System.out.println(" Your Account balance is :"+acc1.getBalance());
System.out.println("Monthly Interest is :"+acc1.getMonthlyInterest());
System.out.println("Your Account is created on :"+acc1.getDateCreated());

   //Displaying the Account information after deposit amount
acc1.deposit(3000);
System.out.println(" Your Account balance is :"+acc1.getBalance());
System.out.println("Monthly Interest is :"+acc1.getMonthlyInterest());
System.out.println("Your Account is created on :"+acc1.getDateCreated());
  
  
   }

}

_________________

output::

Your Account balance is :20000.0
Monthly Interest is :75.0
Your Account is created on :Wed Feb 08 23:24:54 IST 2017
Your Account balance is :17500.0
Monthly Interest is :65.625
Your Account is created on :Wed Feb 08 23:24:54 IST 2017
Your Account balance is :20500.0
Monthly Interest is :76.875
Your Account is created on :Wed Feb 08 23:24:54 IST 2017

__________________Thank You