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

I need help creating a Java program. Please make this code as basic as possible:

ID: 3789260 • Letter: I

Question

I need help creating a Java program. Please make this code as basic as possible:

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

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(" Account "+acc1.getId()+" balance is :"+acc1.getBalance());
System.out.println("Monthly Interest is :"+acc1.getMonthlyInterest());
System.out.println("Account "+acc1.getId()+" is created on :"+acc1.getDateCreated());

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

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

}

_____________________

output:


Account 1122 balance is :20000.0
Monthly Interest is :75.0
Account 1122 is created on :Thu Feb 09 00:13:33 IST 2017

Account 1122 balance is :17500.0
Monthly Interest is :65.625
Account 1122 is created on :Thu Feb 09 00:13:33 IST 2017

Account 1122 balance is :20500.0
Monthly Interest is :76.875
Account 1122 is created on :Thu Feb 09 00:13:33 IST 2017

___________Thank You

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