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: 3758708 • 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

class Account{
   private int id;
   private double balance;
   private double annualInterestRate;
   private DateTime dateCreated;
   private static int numberOfAccounts;
   private static double totalValueOfAccounts;
   public Account(){
      
   }
   public Account(int id,double balance,double annualInterestRate){
       this.id = id;
       this.balance = balance;
       this.annualInterestRate = annualInterestRate;
       numberOfAccounts++;
       totalValueOfAccounts+=balance;      
   }
   public int getId(){
       return id;
   }
   public double getBalance(){
       return balance;
   }
   public double getAnnualInterestRate(){
       return annualInterestRate;
   }
   public DateTime getDateCreated(){
       return dateCreated;
   }
   public void setId(int id){
       thi.id = id;
   }
   public void setBalance(double balance){
       this.balance = balance;
   }
   public void setAnnualInterestRate(double a){
       this.annualInterestRate = a;
   }
   public void withdraw(int amount){
       if(balance - amount > 0){
           balance -= amount;
           totalValueOfAccounts -= amount;
       }  
   }
   public void deposit(int amount){      
       balance += amount;
       totalValueOfAccounts += amount;  
   }
}

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