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

Design a class named Account with Account.h (including class data fields and fun

ID: 675494 • Letter: D

Question

Design a class named Account with Account.h (including class data fields and function prototype) and Account.cpp (including constructor and function definitions) 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 constructor that creates an account with the specified id and initial balance The accessor (get) and mutator (set) methods for id, balance, and annualInterestRate. **AnnualInterestRate is a static variable, and the getAnnualInterestRate() and setAnnualInterestRate() methods are static methods A method named getMonthlyInterestRate() that returns the monthly 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. Write a test program that creates five Account objects. The account IDs are 1000 to 5000, balance of $1,000 to 5000, and an annual interest rate of 3%. Use the withdraw method to withdraw $500, use the deposit method to deposit $1000, and print the account ID, the monthly interest, and the balance for each account. (Hint: The method getMonthlyInterest() is to return monthly interest, not the interest rate. Monthly interest is balance * monthlyInterestRate. monthlyInterestRate is annualInterestRate / 12. Note that annualInterestRate is a percentage, e.g.,like 3%. You need to divide it by 100.)

Explanation / Answer

import java.util.Scanner;

import java.util.Date;

public class Account

{

    private int id = 0;

    private double balance = 0;

    final private double annualinterestrate = 0.12;

    Date dateCreated;

    public Account()

    {

    }

    public Account(int aId, double aBalance, double annualInterestRate)

    {

        id = aId;

        balance = aBalance;

        annualInterestRate = annualInterestRate;

        dateCreated = new Date();

    }

    public void setID (int aId)

    {

        id = aId;

    }

    public int getID()

    {

        return id;

    }

    public void setBalance (double aBalance)

    {

        balance = aBalance;

    }

    public double getbalance()

    {

        return balance;

    }

    public void setAnnualInterestRate (double aannualInterestRate)

    {

        annualInterestRate = aannualInterestRate;

    }

    public double getAnnualInterestRate()

    {

        return annualInterestRate;

    }

    public Date getDateCreated()

    {

        return dateCreated;

    }

    public double getMonthlyInterestRate()

   {

        return annualInterestRate / 12;

    }

    public void withdraw(double amount)

    {

        balance -= amount;

    }

    public void deposit(double amount)

    {

        balance += amount;

    }

}

Then here is the second class code which contains the main method:

public class AccountTester

{

    public static void main(String[] args)

    {

        Account account = new Account(1857, 5000, 0.12);

        account.setID(1857);

        account.setBalance(5000);

        account.setAnnualInterestRate(0.12);

        System.out.println ("Account number: "+ +account.getID());

        System.out.println ("The account balance is: $ " + +account.getbalance());

        System.out.println("The Annual Interest Rate is: $ " + account.getannualInteresrRate());

        account.deposit(150);

        System.out.println("The account balance is: $ " +account.getbalance());

        account.withdraw(50);

        System.out.println("The account balance is: $ " +account.getbalance());

        System.out.println ("The monthly interest earned is: $ " + +account.getbalance() *    account.annualInterestRate());

        System.out.println ("The account was created on: " + +account.getdateCreated());

    }

}

TRY THIS CODE ALSO

import java.util.Date;

   

public class Example {

    public static void main(String[] args) {

          

        //Create an instance object of class Stock

        Account myAccount = new Account(1122, 20000, 0.045);

        myAccount.withdraw(2500);

        myAccount.deposit(3000);

          

        //display balance, monthly interest and date of account

        System.out.println("Balance: " + myAccount.balance);

        System.out.println("Monthly Interest: " + myAccount.getMonthlyInterestRate());

          

        java.util.Date dateCreated = new java.util.Date();

        System.out.println("Account created on: " + dateCreated.toString());

    }

}

   

//Design a class named Account

class Account {

      

    //Define varables 1 & 2

    private int id;

    private double balance;

    private double annualInterestRate;

    private Date dateCreated;

  

    //A no arg constructer that creates a default account

    Account() {

        id = 0;

        balance = 0;

        annualInterestRate = 0;

    }

  

    //A Constructor that creates an account with specified id and initial balance

    Account(int newId, double newBalance) {

        id = newId;

        balance = newBalance;

    }

  

    Account(int newId, double newBalance, double newAnnualInterestRate) {

        id = newId;

        balance = newBalance;

        annualInterestRate = newAnnualInterestRate;

    }

  

    //The accessor(get) and mutator(set) methods for id, balance, and annualInterestRate

    public int getId() {

        return id;

    }

  

    public double getBalance() {

        return balance;

    }

  

    public double getAnnualInterestRate() {

        return annualInterestRate;

    }

  

    public void setId(int newId) {

        id = newId;

    }

  

    public void setBalance(double newBalance) {

        balance = newBalance;

    }

  

    public void setAnnualInterestRate(double newAnnualInterestRate) {

        annualInterestRate = newAnnualInterestRate;

    }

  

    //The Accessor method for dateCreated

    public void setDateCreated(Date newDateCreated) {

        dateCreated = newDateCreated;

    }

      

    //A method named getMonthlyInterestRate() that returns the monthly interest rate

    double getMonthlyInterestRate() {

        return (annualInterestRate/12);

    }

  

    //A method named getMonthlyInterest() that returns the monthly interest

    double getMonthlyInterest() {

        return (balance * (annualInterestRate/12));

    }

  

    //A Method named withdraw that withdraws a specified amount from the account

    double withdraw(double amount) {

        return balance -= amount;

    }   

  

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

    double deposit(double amount) {

        return balance += amount;

    }

}

import java.util.Date;

   

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