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

A private int data field named id for the account. A private double data field n

ID: 3740970 • Letter: A

Question

A private int data field named id for the account.

A private double data field named balance for the account.

A private double static data field named annualInterestRate that stores the current interest rate.

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

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

Accessor methods (get) for id, balance and annualInterestRate.

A mutator method (set) for annualInterestRate.

The accessor method for dateCreated.

A method named getMonthlyInterest() that returns the monthly interest rate.

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

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

CAWINDOWS1system32)cmd.exe Bank Account Balance Enter your account id: 1122 Enter your current Balance: 28888 Enter your annual interest rate: .045 Enter any withdraals: 2500 Enter any deposits: 300 Balance for account # 1122 is $17,800 .00 Monthly interest is $66.75 This account was created at Wed Nov 02 11:05:02 EDT 2016 Annual intere st rate is 4.50% Press any key to continue . - -

Explanation / Answer

Here is the required CheckAcct.java class as required. Defined all the necessary attributes and methods, explained using comments, and tested the class using the code provided by you, verified the output. Drop a comment if you have any queries. Thanks.

// CheckAcct.java

import java.util.Calendar;

import java.util.Date;

public class CheckAcct {

                // required attributes

                private int id;

                private double balance;

                private static double annualInterestRate;

                private Date dateCreated;

                /**

                * constructor to initialize CheckAcct object with account id and initial

                * balance

                *

                * @param acctID

                *            - account id

                * @param acctBalance

                *            - starting balance

                */

                public CheckAcct(int acctID, double acctBalance) {

                                id = acctID;

                                balance = acctBalance;

                                dateCreated = Calendar.getInstance().getTime(); /*setting current time to dateCreated */

                }

                // getter methods

                public int getId() {

                                return id;

                }

                public double getBalance() {

                                return balance;

                }

                public static double getAnnualInterestRate() {

                                return annualInterestRate;

                }

                public Date getDateCreated() {

                                return dateCreated;

                }

                /**

                * calculates and returns the monthly interest amount

                *

                * @return the monthly interest amount

                */

                public double getMonthlyInterest() {

                                // finding monthly interest rate

                                double monthlyRate = annualInterestRate / 12.0;

                                // monthly interest= balance* monthly interest rate

                                return balance * monthlyRate;

                }

                // setter method for annual interest rate

                public static void setAnnualInterestRate(double annualInterestRate) {

                                CheckAcct.annualInterestRate = annualInterestRate;

                }

                /**

                * method to withdraw money from account

                *

                * @param amount

                *            - amount to be withdrawn

                */

                public void withdraw(double amount) {

                                balance -= amount;

                }

                /**

                * method to deposit money to account

                *

                * @param amount

                *            - amount to be deposited

                */

                public void deposit(double amount) {

                                balance += amount;

                }

}

// BankAcctDemo.java (no changes)

import java.util.Scanner;

import java.text.DecimalFormat;

public class BankAcctDemo {

                public static void main(String[] args) {

                                int acctID;

                                double acctBalance, annIntRate, withAmt, depAmt;

                                Scanner input = new Scanner(System.in);

                                DecimalFormat twoDigits = new DecimalFormat("$###,###.00");

                                DecimalFormat percent = new DecimalFormat("##.00%");

                                System.out.println("   Bank Account Balance");

                                System.out.println();

                                System.out.print("Enter your account id: ");

                                acctID = input.nextInt();

                                System.out.println();

                                System.out.print("Enter your current Balance: ");

                                acctBalance = input.nextDouble();

                                System.out.println();

                                System.out.print("Enter your annual interest rate: ");

                                annIntRate = input.nextDouble();

                                System.out.println();

                                System.out.print("Enter any withdrawals: ");

                                withAmt = input.nextDouble();

                                System.out.println();

                                System.out.print("Enter any deposits: ");

                                depAmt = input.nextDouble();

                                System.out.println();

                                CheckAcct account = new CheckAcct(acctID, acctBalance);

                                CheckAcct.setAnnualInterestRate(annIntRate);

                                account.withdraw(withAmt);

                                account.deposit(depAmt);

                                System.out.println("Balance for account # " + account.getId() + " is "

                                                                + twoDigits.format(account.getBalance()));

                                System.out.println("Monthly interest is "

                                                                + twoDigits.format(account.getMonthlyInterest()));

                                System.out.println("This account was created at "

                                                                + account.getDateCreated());

                                System.out.println();

                                System.out.println();

                                System.out.println("Annual interest rate is "

                                                                + percent.format(CheckAcct.getAnnualInterestRate()));

                }

}

//OUTPUT

   Bank Account Balance

Enter your account id: 1122

Enter your current Balance: 20000

Enter your annual interest rate: .045

Enter any withdrawals: 2500

Enter any deposits: 300

Balance for account # 1122 is $17,800.00

Monthly interest is $66.75

This account was created at Sun Apr 01 11:48:02 IST 2018

Annual interest rate is 4.50%

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