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

In Java, implement a class named Account that contains: You do not need to draw

ID: 3759232 • Letter: I

Question

In Java, implement a class named Account that contains:

You do not need to draw a UML diagram for the class. The code for the Account class should reside in a file called Account.java. All of the data members in your class should be private.

In a TestAccount class in a file called TestAccount.java, write a printAccount method that will print the account number, balance, annual interest rate, and date created for an account. This method takes only one parameter: a reference to an Account object. System.out.printf is good useful for this. You could use the following format string: "%5d $%9.2f %5.2f%% %29s "

Next, also in TestAccount.java, write a main method. In main, first call averageBalance and print out the result. Then create a default Account object and print it (using printAccount, of course). Then modify the object so that it has an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Print it again. Then use the withdraw method to withdraw $2,500, use the deposit method to deposit $3,000, and print the object. Award the account six months of compounded monthly interest by calling your awardMonthlyInterest method repeatedly. Display the account yet again. Again call averageAccountBalance and print the result. Then close the account.

Next, again in your main method, create an array of five Account objects. Create the five individual Account objects in a loop (not with five separate lines of code calling ‘new’). The objects should have account IDs of 1, 2, 3, 4, and 5, respectively. Initialize the accounts with random balances in the range $0-$100,000. (You may exclude $100,000 from the range.) Give each of these five accounts an annual interest rate of 3.0%. In a second loop, display the five accounts. Again, call averageAccountBalance and print the result. In a third loop (with a nested loop inside), award each of the accounts six months of compounded monthly interest. Display the five accounts one last time. Again display the average account balance.

Sample output:

The average account balance is: $0.00

Default account: 0 $ 0.00 0.00% Mon Mar 31 12:00:21 EDT 2014

Modified account: 1122 $ 20000.00 4.50% Mon Mar 31 12:00:21 EDT 2014

After withdrawal and deposit 1122 $ 20500.00 4.50% Mon Mar 31 12:00:21 EDT 2014

After six months of interest: 1122 $ 20965.60 4.50% Mon Mar 31 12:00:21 EDT 2014

An int data member named id (default 0). A double data member named balance (default 0). A double data member named annualInterestRate (default 0). A java.util.Date data member named dateCreated that stores the date when the account was created A static int data member, numberOfAccounts, that stores the number of unclosed accounts in existence. A static double data member, totalValueOfAccounts, that stores the total value of all of the unclosed accounts. A no-arg constructor that creates a default account A second constructor that receives initial values for id, balance, and annualInterestRate Accessor and mutator methods (“getters and setters”) for id, balance, and annualInterestRate. An accessor method for dateCreated. A method named withdraw that withdraws a specified amount from the account. A method named deposit that deposits a specified amount to the account. A method named getMonthlyInterestRate that returns the account’s monthly interest rate. A method called awardMonthlyInterest for depositing one month’s worth of interest into the account. A close method for closing an account. It should print the message “Closing account xxxx”, where xxxx is the account number, and update numberOfAccounts and totalValueOfAccounts A static method called averageBalance that returns the average balance of all of the accounts. The method should return totalValueOfAccounts / numberOfAccounts, unless numberOfAccounts is zero, in which case it should return zero.

Explanation / Answer

public class Account

{

   //Data fields

   private double balance; //Account Balance

   private double annualInterestRate; //Account annual interest rate

   private double monthlyInterestRate;

   private double totalDeposits;

   private double totalWithdraws;

   private double totalInterest;

    public Account(double startBalance, double annual_Interest_Rate)

    {

        balance = startBalance;

        annualInterestRate = annual_Interest_Rate;

    }

    //end of Constructor

   public void setAnnualInterestRate(double annual_Interest_Rate)

   {

       monthlyInterestRate = annualInterestRate / 12;

   }

   //end of setAnnualInterestRate method

   public void setDeposit(double amount)

   {

       balance += amount;

       totalDeposits += amount;

   }

   //end of deposit method

   public void setWithdraw(double amount)

   {

       balance -= amount;

       totalWithdraws += amount;

   }

   //end of withdraw method

   public void calculateMonthlyInterest()

   {

       totalInterest = totalInterest + balance * monthlyInterestRate;

      balance = balance + balance * monthlyInterestRate;

   }

   //end of calculateMonthlyInterest method

   public double getBalance()

   {

       return balance;

   }

   public double getAnnualInterestRate()

   {

       return annualInterestRate;

   }

   public double getMonthlyInterestRate()

   {

       return monthlyInterestRate;

   }

   public double getTotalDeposits()

   {

       return totalDeposits;

   }

   public double getTotalWithdraws()

   {

       return totalWithdraws;

   }

   public double getTotalnterest()

   {

       return totalInterest;

   }

   public void displayData()

   {

       balance = Math.round(balance * 100.0) / 100.0;

       totalInterest = Math.round(totalInterest * 100.0) / 100.0;

       System.out.println();

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

       System.out.println("Total amount of deposits: $" + totalDeposits);

       System.out.println("Total amount of withdraws: $" + totalWithdraws);

       System.out.println("Total interest earned: $" + totalInterest);

   }

   //end of displayData method

}

//end of Account class

import java.util.Scanner;

public class AccountTest

{

    public static void main(String[] args)

    {

        double startBalance;

        double annual_Interest_Rate;

        int months;

        double deposit_Amount;

        double withdraw_Amount;

        Scanner input = new Scanner(System.in);

        System.out.print("Enter starting balance: $");

        startBalance = input.nextDouble();

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

        annual_Interest_Rate = input.nextDouble();

        System.out.print("Enter the number of months: ");

        months = input.nextInt();

        Account ac = new Account(startBalance, annual_Interest_Rate);

        ac.setAnnualInterestRate(annual_Interest_Rate);

        for (int i = 0; i < months; i++)

        {

            /* Prompt user for deposit amount */

            System.out.print("Enter amount to deposit for the month " + (i+1) + ":$");

            deposit_Amount = input.nextDouble();

            sa.setDeposit(deposit_Amount);

            System.out.print("Enter amount to withdraw for the month " + (i+1) + ":$");

            withdraw_Amount = input.nextDouble();

            ac.setWithdraw(withdraw_Amount);

            ac.calculateMonthlyInterest();

        }

        ac.displayData();

    }

}

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