I need help creating a Java program Here is the exercise I a

I need help creating a Java program. Here is the exercise I am working in:

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 named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. Make it static.

A private Date data field named dateCreated that stores the date when the account was created. (private Date dateCreated) You will need to do dateCreated = new Date( ) in your constructor to initialize the dateCreated property.

A no-arg constructor that creates a default account.

A constructor that creates an account with the specified id and initial balance. The property annualInterestRate will be set by the test program and not through the constructor.

The accessor and mutator methods for id, 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 money earned in a month.

A method named withdraw that withdraws a specified amount from the account.

A method named deposit that deposits a specified amount to the account.

(Hints: The method getMonthlyInterest() is to return monthly interest, not the interest rate- the amount earned in one month. 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.)

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 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 and again after the deposit and withdraw.

Paragraph Account -id: int -balance: double double -date Created Date +Account +Account (someld int, someBalance double) get do: int setldonewld int) void +getBalanceo double setBalance(newBalance double) void ate() double +setAnnualInterestRate(newRate double) void getDate Created Date Ratec): double +getMonthly double Interesto): withdrarydamt double void +deposit amt double) oid AaBbc Norn

Solution

import java.util.Date;

public class Account {
   private int id;
   private double balance;
   private double annualInterestRate;
   private Date dateCreated;
  
   Account()
   {
       id=0;
       balance=0;
       annualInterestRate=0;
       dateCreated=new Date();
      
   }
  
   Account(int i,double bal)
   {
       id=i;
       balance=bal;
       annualInterestRate=0;
       dateCreated=new Date(\"28/12/1996\");
      
   }
   int getId()
   {
       return id;
   }
   void setId(int i)
   {
       id=i;
   }
   double getBalance()
   {
       return balance;
   }
   void setBalance(double b)
   {
       balance=b;
   }
  
   double getAnnualInterestRate()
   {
       return annualInterestRate;
   }
  
   void setAnnualInterestRate(double r)
   {
       annualInterestRate=r;
   }
  
   Date getDateCreated()
   {
       return dateCreated;
   }
   void setDateCreated(Date d)
   {
       dateCreated=d;
   }
  
   double getMonthalyInterestRate()
   {
       return annualInterestRate/12;
   }
  
   double getMonthalyInterest()
   {
       return (annualInterestRate/12)*balance/100;
   }
  
   void deposit(double amount)
   {
       balance+=amount;
   }
   void withdraw(double amount)
   {
       balance-=amount;
   }
  
  
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Account o=new Account(1122,20000);
       o.setAnnualInterestRate(4.5);
      
       System.out.println(\"Balance is \"+o.getBalance());
       System.out.println(\"Monthly interest is \"+o.getMonthalyInterest());
       System.out.println(\"Date of creation is \"+o.getDateCreated());
      
       o.withdraw(2500);
      
       System.out.println(\"after withdraw 2500\");
       System.out.println(\"Balance is \"+o.getBalance());
       System.out.println(\"Monthly interest is \"+o.getMonthalyInterest());
       o.deposit(3000);
      
       System.out.println(\"after deposit 3000\");
       System.out.println(\"Balance is \"+o.getBalance());
       System.out.println(\"Monthly interest is \"+o.getMonthalyInterest());


      

   }

}

==============================================

Balance is 20000.0
Monthly interest is 75.0
Date of creation is Sun Apr 12 00:00:00 IST 1998
after withdraw 2500
Balance is 17500.0
Monthly interest is 65.625
after deposit 3000
Balance is 20500.0
Monthly interest is 76.875

I need help creating a Java program. Here is the exercise I am working in: Design a class named Account that contains: A private int data field named id for the
I need help creating a Java program. Here is the exercise I am working in: Design a class named Account that contains: A private int data field named id for the
I need help creating a Java program. Here is the exercise I am working in: Design a class named Account that contains: A private int data field named id for the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site