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

import java.io.*;


class Account   
{
         final int max_limit=20;
         final int min_limit=1;
         final double min_bal=500;
         private String name[]=new String[20];
         privateint accNo[]=newint[20];
         private String accType[]=new String[20];
         privatedouble balAmt[]=newdouble[20];
         staticint totRec=0;
      
        publicvoid initialize()
        {
             for(int i=0;i<max_limit;i++)
             {
                name[i]="";
                accNo[i]=0;
                accType[i]="";
                balAmt[i]=0.0;
            }
        }

       publicvoid newEntry()
        {
               String str;
               int acno;
               double amt;
               boolean permit;
                permit=true;

               if (totRec>max_limit)
               {
                    System.out.println("Wrong");
                    permit=false;
               }

               if(permit = true)
               {
               totRec++;                   
               System.out.println("Please enter");
               try{
                          accNo[totRec]=totRec;  
                        System.out.println("Account Number : "+accNo[totRec]);
                      
                     BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                     System.out.print("Enter Name : ");
                     System.out.flush();
                     name[totRec]=obj.readLine();

                     accType[totRec]="Current Account";
                     System.out.println("Account Type : "+accType[totRec]);                   

                    do{
                           System.out.print("Enter Initial Amount to be deposited : ");
                           System.out.flush();
                           str=obj.readLine();
                           balAmt[totRec]=Double.parseDouble(str);
                         }while(balAmt[totRec]<min_bal);    

                  System.out.println(" ");
                    }
                catch(Exception e)
                {}
            }
        }

       public void display()
        {
              String str;
              int acno=0;
              boolean valid=true;
                         
              System.out.println(" DISPLAYING DETAILS OF CUSTOMER ");
              try{
                 BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                 System.out.print("Enter Account number : ");
                 System.out.flush();
                 str=obj.readLine();
                 acno=Integer.parseInt(str);
                  if (acno<min_limit || acno>totRec)
                     {
                          System.out.println(" Invalid Account Number ");
                          valid=false;
                     }

                    if (valid==true)
                      {   
                        System.out.println(" Account Number : "+accNo[acno]);
                        System.out.println("Name : "+name[acno]);
                        System.out.println("Account Type : "+accType[acno]);
                        System.out.println("Balance Amount : "+balAmt[acno]+" ");
                      }
                 }
            catch(Exception e)
            {}
        }


              publicvoid deposit()
        {
              String str;
              double amt;
              int acno;
              boolean valid=true;
              System.out.println(" =====DEPOSIT AMOUNT=====");
            
              try{
                   //Reading deposit value
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));

                        System.out.print("Enter Account No : ");
                        System.out.flush();
                        str=obj.readLine();
                        acno=Integer.parseInt(str);
                         if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                         {
                              System.out.println(" Invalid Account Number ");
                              valid=false;
                         }
         
                        if (valid==true)
                       {
                            System.out.print("Enter Amount you want to Deposit : ");
                            System.out.flush();
                            str=obj.readLine();
                            amt=Double.parseDouble(str);

                            balAmt[acno]=balAmt[acno]+amt;

                            //Displaying Depsit Details
                            System.out.println(" After Updation...");
                            System.out.println("Account Number : "+acno);
                            System.out.println("Balance Amount : "+balAmt[acno]+" ");
                        }
                 }
            catch(Exception e)
            {}
       }


         publicvoid withdraw()
        {
              String str;
              double amt,checkamt,penalty;
              int acno;
              boolean valid=true;
              System.out.println(" =====WITHDRAW AMOUNT=====");
            
              try{
                   //Reading deposit value
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                 
                        System.out.print("Enter Account No : ");
                        System.out.flush();
                        str=obj.readLine();
                        acno=Integer.parseInt(str);

                          if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                             {
                                System.out.println(" Invalid Account Number ");
                                valid=false;
                            }

                        if (valid==true)
                        {
                                System.out.println("Balance is : "+balAmt[acno]);
                                System.out.print("Enter Amount you want to withdraw : ");
                                System.out.flush();
                                str=obj.readLine();
                                amt=Double.parseDouble(str);

                                checkamt=balAmt[acno]-amt;

                                if(checkamt >= min_bal)
                                 {
                                    balAmt[acno]=checkamt;
                                    //Displaying Depsit Details
                                    System.out.println(" After Updation...");
                                    System.out.println("Account Number : "+acno);
                                    System.out.println("Balance Amount : "+balAmt[acno]+" ");
                                }
                                else
                                 {
                                    System.out.println(" Your Balance has gone down and so penalty is calculated");
                               
                                    penalty=((min_bal - checkamt)*20)/100;
                                    balAmt[acno]=balAmt[acno]-(amt+penalty);
                                    System.out.println("Now your balance revels : "+balAmt[acno]+" ");
                                }
                        }
                 }
            catch(Exception e)
            {}
       }

}

class Sav_acct     
{
         final int max_limit=20;
         final int min_limit=1;
         final double min_bal=500;
         private String name[]=new String[20];
         privateint accNo[]=newint[20];
         private String accType[]=new String[20];
         privatedouble balAmt[]=newdouble[20];
         staticint totRec=0;
      
     
        {
             for(int i=0;i<max_limit;i++)
             {
                name[i]="";
                accNo[i]=0;
                accType[i]="";
                balAmt[i]=0.0;
            }
        }

      
      
          publicvoid newEntry()
        {
               String str;
               int acno;
               double amt;
               boolean permit;
                permit=true;

               if (totRec>max_limit)
               {
                    System.out.println(" Sorry we cannot admit you in our bank... ");
                    permit=false;
               }

               if(permit = true)   //Allows to create new entry
               {
               totRec++;         // Incrementing Total Record             
               System.out.println(" =====RECORDING NEW ENTRY=====");
               try{
                          accNo[totRec]=totRec;    //Created AutoNumber to accNo so no invalid id occurs
                        System.out.println("Account Number : "+accNo[totRec]);
                      
                     BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                     System.out.print("Enter Name : ");
                     System.out.flush();
                     name[totRec]=obj.readLine();

                     accType[totRec]="Saving Account";
                     System.out.println("Account Type : "+accType[totRec]);

                    do{
                           System.out.print("Enter Initial Amount to be deposited : ");
                           System.out.flush();
                           str=obj.readLine();
                           balAmt[totRec]=Double.parseDouble(str);
                         }while(balAmt[totRec]<min_bal);      //Validation that minimun amount must be 500

                  System.out.println(" ");
                    }
                catch(Exception e)
                {}
            }
        }

      
      
           publicvoid display()
        {
              String str;
              int acno=0;
              boolean valid=true;
                         
              System.out.println(" =====DISPLAYING DETAILS OF CUSTOMER===== ");
              try{
                 BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                 System.out.print("Enter Account number : ");
                 System.out.flush();
                 str=obj.readLine();
                 acno=Integer.parseInt(str);
                  if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                     {
                          System.out.println(" Invalid Account Number ");
                          valid=false;
                     }

                    if (valid==true)
                      {   
                        System.out.println(" Account Number : "+accNo[acno]);
                        System.out.println("Name : "+name[acno]);
                        System.out.println("Account Type : "+accType[acno]);
                      
                        //Bank policy is to give 10% interest on Net balance amt
                        balAmt[acno]=balAmt[acno]+(balAmt[acno]/10);
                        System.out.println("Balance Amount : "+balAmt[acno]+" ");
                      }
                 }
            catch(Exception e)
            {}
        }

         publicvoid deposit()
        {
              String str;
              double amt;
              int acno;
              boolean valid=true;
              System.out.println(" =====DEPOSIT AMOUNT=====");
            
              try{
                   //Reading deposit value
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));

                        System.out.print("Enter Account No : ");
                        System.out.flush();
                        str=obj.readLine();
                        acno=Integer.parseInt(str);
                         if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                         {
                              System.out.println(" Invalid Account Number ");
                              valid=false;
                         }
         
                        if (valid==true)
                       {
                            System.out.print("Enter Amount you want to Deposit : ");
                            System.out.flush();
                            str=obj.readLine();
                            amt=Double.parseDouble(str);

                            balAmt[acno]=balAmt[acno]+amt;

                            //Displaying Depsit Details
                            System.out.println(" After Updation...");
                            System.out.println("Account Number : "+acno);
                            System.out.println("Balance Amount : "+balAmt[acno]+" ");
                        }
                 }
            catch(Exception e)
            {}
       }

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