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

Using JAVA to Design a class named Account that contains: A private int data fie

ID: 3563213 • Letter: U

Question

Using JAVA to 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.

A private Date data field named dateCreated that stores the date when the account was created.

A no-arg constructor that creates a default account.

Add a new data field name of the String type to store the name of the customer.

Add a new data field named transactions whose type is ArrayList that stores that transaction for the accounts. Each transaction is an instance of the Transaction class. The Transaction class is defined as shown:

Modify the withdraw and deposit methods to add a transaction to the transactions array list

A constructor that creates an account with the specified id and initial balance.

Add a new constructor that constructs an account with the specified name, id, and balance.

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.

Amethod named getMonthlyInterest() that returns the monthly interest.

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

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

Write a test program that creates an Account with annual interest rate 1.5%, balance 1000, id 1122, and name George. Deposit $30, $40, and $50 to the account and withdraw $5, $4, and $2 from the account. Print an account summary that show account holder name, interest rate, balance, and all transactions.

Explanation / Answer

Account.java

import java.util.ArrayList;
import java.util.Date;


public class Account {
   private int id;
   private double balance;
   private double annualInterestRate = 0.0;
   private Date dateCreated ;
   private String name;
   private ArrayList<Transaction> transaction;
   public Account()
   {
       transaction = new ArrayList<Transaction>();
   }
   public Account(int id,double bal){
       this();
       this.id = id;
       this.balance = bal;
       }
   public Account(int id,String name,double bal){
       this();
       this.id = id;
       this.balance = bal;
       this.name = name;
   }
  
   public int getId()
   {
       return id;
   }
   public double getBalance(){
       return balance;
   }
   public double getAnnualInterestRate()
   {
       return annualInterestRate;
   }
  
   public void setId(int id){
       this.id = id;
   }
   public void setBalance(double bal){
       this.balance = bal;
   }
   public void setannualInterestRate(double rate)
   {
       this.annualInterestRate = rate;
   }
   public Date getDateCreated(){
       return dateCreated;
   }
  
   public double getMonthlyInterestRate(){
       return annualInterestRate / 12;
   }
  
   public double getMonthlyInterest(){
       return (balance * annualInterestRate) / (100 * 12);
   }
   public void withdraw(double amt)
   {
       if(balance > amt){
           balance -= amt;
           Transaction t = new Transaction('w', amt, this.balance, "Amount withdraw");
           transaction.add(t);
       }
       else{
           System.out.println("In sufficient balance");
       }
   }
   public void deposit(double amt){
       balance = balance + amt;
       Transaction t = new Transaction('d', amt, this.balance, "Amount deposit");
       transaction.add(t);
   }
  
   public void print()
   {
       System.out.println("Name:"+name+" Interest Rate:"+annualInterestRate+" Balance:"+balance);
       for(Transaction t : transaction ){
           System.out.println(t.print());
       }
   }
}
class Transaction{
   private Date date;
   private double balance;
   private double amount;
   private char type;
   private String description;
  
   public Transaction(char type,double amt,double bal,String desc){
       balance = bal;
       this.type = type;
       this.amount = amt;
       description = desc;
   }
  
   public String print()
   {
       return "Balance:"+balance+" Amount:"+amount+" Type:"+type+" Description:"+description;
   }
}


Test.java


public class Test {

   public static void main(String[] args) {
       Account act = new Account(1122,"George",1000);
       act.setannualInterestRate(1.5);
       act.deposit(30);
       act.deposit(40);
       act.deposit(50);
      
       act.withdraw(5);
       act.withdraw(4);
       act.withdraw(2);
      
       act.print();
   }

}

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