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

Write a class called Account that does not contain a main() method, but it does

ID: 653367 • Letter: W

Question

Write a class called Account that does not contain a main() method, but it does contains the following:

A private int data field named id for the account (default value is 0).

A private double data field named balance for the account (default value is 0).

A private double data field named annualInterestRate that stores the current interest rate (default value is 0).

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.

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

The accessor and mutator methods (getter and setter methods) for id, balance, and annualInterestRate.

The accessor method (getter method) for dateCreated.

A public double method named getMonthlyInterestRate() that returns the monthly interest rate.

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

A public void method named withdraw() that withdraws a specified amount from the account.

A public void method named deposit() that deposits a specified amount to the account.

A public String method named toString() that returns a string that contains the account ID, the account balance, the annual interest rate, and the date of the createion of the account.

The getMonthlyInterest() method is to return the monthly interest, not the monthly interest rate. Monthly interest is determined by the following formula:

The monthlyInterestRate value in the above equation is given by the following formula:

The toString() method will format the data into a string like the following:

Note that annualInterestRate is a percentage, like a value of 4.5 for 4.5%. You need to divide it by 100 for the above equations.

Next, write a test program called TestAccount.java that has a main() method, and that creates an Account object named myAccount 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. Then print the balance, the monthly interest, and the date when this account was created. To print this information from your myAccountobject, use a line like the following:

Then print the Monthly Interest Rate by calling getMonthlyInterestRate(), and then print the Monthly Interest by calling getMonthlyInterest().

Next, create an account object named yourAccount with a different ID, a different balance, and a different annual interest rate. Then print all of the same information you just printed for the myAccount object.

Explanation / Answer

Program:-

Account.java:-

class Account {

            int id;

            double balance;

            double annualInterestRate;

            Date dateCreated;

            Account() {

                        id = 0;

                        balance = 0.0;

                        annualInterestRate = 0.0;

            }

            Account(int newId, double newBalance) {

                        id = newId;

                        balance = newBalance;

            }

            public int getId() {

                        return id;

            }

            public double getBalance() {

                        return balance;

            }

            public double getAnnualInterestRate() {

                        return annualInterestRate;

            }

            public void setId() {

                        id = newId;

            }

            public void setBalance() {

                        balance = newBalance;

            }

            public void setAnnualInterestRate() {

                        annualInterestRate = newAnnualInterestRate;

            }

            public void setDateCreated() {

                        dateCreated = newDateCreated;

            }

            double getMonthlyInterestRate() {

                        return annualInterestRate/12;

            }

            double withdraw(double amount) {

                        return balance -= amount;

            }         

            double deposit(double amount) {

                        return balance += amount;

            }

}

TestAccount.java:-

import java.util.Date;

public class TestAccount {

            public static void main(String[] args) {

                        Account myAccount = new Account(34598755, 2754.00, 2.75);

                        myAccount.withdraw(2500.00);

                        myAccount.deposit(3000.00);

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

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

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

            }

}

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