Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to display bank account

Posted By: Easy Tutor     Category: Java     Views: 36804

Design a class to represent a bank account. Include the following members:
Data Members
->Name of the depositor
->Account Number
->Type of Account
->Balance amount in the account

Methods
->To assign intial values(with method and not with constructor)
->To deposit an amount
(Include computation of Interest for saving a/c)
->To withdraw an amount after checking balance
(check minimum balance if necessary for current account impose penalty)
->To display the name and balance

Create a class Account that stores customer name, account number and type of account. From
this derive the classes Curr-acct and Sav-acct to make them more specific to their requirements. Include the necessary methods in order to achieve the above mention task.

Code for Program to display bank account in Java

import java.io.*;


class Curr_acct      //CURRENT ACCOUNT CLASS
{
         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;
        
        //Intializing Methodpublicvoid initialize()
        {
             for(int i=0;i<max_limit;i++)
             {
                name[i]="";
                accNo[i]=0;
                accType[i]="";
                balAmt[i]=0.0;
            }
        }

        
        
        //TO  ADD NEW RECORDpublicvoid newEntry()
        {
               String str;
               int acno;
               double amt;
               boolean permit;
                permit=true;

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

               if(permit = true)   //Allows to create new entry
               {
               totRec++;         // Incrementing Total Record               
               System.out.println("\n\n\n=====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]="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);      //Validation that minimun amount must be 500

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

        
        
        //TO DISPLAY DETAILS OF RECORDpublicvoid display()
        {
              String str;
              int acno=0;
              boolean valid=true;
                           
              System.out.println("\n\n=====DISPLAYING DETAILS OF CUSTOMER=====\n");
              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("\n\n\nInvalid Account Number \n\n");
                          valid=false;
                     }

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



          //TO DEPOSIT AN AMOUNTpublicvoid deposit()
        {
              String str;
              double amt;
              int acno;
              boolean valid=true;
              System.out.println("\n\n\n=====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("\n\n\nInvalid Account Number \n\n");
                              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("\nAfter Updation...");
                            System.out.println("Account Number :  "+acno);
                            System.out.println("Balance Amount :  "+balAmt[acno]+"\n\n\n");
                        }
                 }
            catch(Exception e)
            {}
       }




     //TO WITHDRAW BALANCEpublicvoid withdraw()
        {
              String str;
              double amt,checkamt,penalty;
              int acno;
              boolean valid=true;
              System.out.println("\n\n\n=====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("\n\n\nInvalid Account Number \n\n");
                                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("\nAfter Updation...");
                                    System.out.println("Account Number :  "+acno);
                                    System.out.println("Balance Amount :  "+balAmt[acno]+"\n\n\n");
                                }
                                else
                                 {
                                    System.out.println("\n\nYour Balance has gone down and so penalty is calculated");
                                    //Bank policy is to charge 20% on total difference of balAmt and min_bal to be 

maintain
                                    penalty=((min_bal - checkamt)*20)/100;
                                    balAmt[acno]=balAmt[acno]-(amt+penalty);
                                    System.out.println("Now your balance revels : "+balAmt[acno]+"\n\n\n");
                                }
                        }
                 }
            catch(Exception e)
            {}
       }

}



class Sav_acct        //SAVING ACCOUNT CLASS
{
         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;
        
        //Intializing Methodpublicvoid initialize()
        {
             for(int i=0;i<max_limit;i++)
             {
                name[i]="";
                accNo[i]=0;
                accType[i]="";
                balAmt[i]=0.0;
            }
        }

        
        
        //TO  ADD NEW RECORDpublicvoid newEntry()
        {
               String str;
               int acno;
               double amt;
               boolean permit;
                permit=true;

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

               if(permit = true)   //Allows to create new entry
               {
               totRec++;         // Incrementing Total Record               
               System.out.println("\n\n\n=====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("\n\n\n");
                    }
                catch(Exception e)
                {}
            }
        }

        
        
        //TO DISPLAY DETAILS OF RECORDpublicvoid display()
        {
              String str;
              int acno=0;
              boolean valid=true;
                           
              System.out.println("\n\n=====DISPLAYING DETAILS OF CUSTOMER=====\n");
              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("\n\n\nInvalid Account Number \n\n");
                          valid=false;
                     }

                    if (valid==true)
                      {     
                        System.out.println("\n\nAccount 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]+"\n\n\n");
                      }
                 }
            catch(Exception e)
            {}
        }



          //TO DEPOSIT AN AMOUNTpublicvoid deposit()
        {
              String str;
              double amt;
              int acno;
              boolean valid=true;
              System.out.println("\n\n\n=====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("\n\n\nInvalid Account Number \n\n");
                              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("\nAfter Updation...");
                            System.out.println("Account Number :  "+acno);
                            System.out.println("Balance Amount :  "+balAmt[acno]+"\n\n\n");
                        }
                 }
            catch(Exception e)
            {}
       }



     //TO WITHDRAW BALANCEpublicvoid withdraw()
        {
              String str;
              double amt,checkamt;
              int acno;
              boolean valid=true;
              System.out.println("\n\n\n=====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("\n\n\nInvalid Account Number \n\n");
                                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("\nAfter Updation...");
                                    System.out.println("Account Number :  "+acno);
                                    System.out.println("Balance Amount :  "+balAmt[acno]+"\n\n\n");
                                }
                                else
                                 {
                                    System.out.println("\n\nAs per Bank Rule you should maintain minimum balance of Rs 

500\n\n\n");
                                }
                        }
                 }
            catch(Exception e)
            {}
       }
}



class  Bank_improved
{
    publicstaticvoid main(String args[]) 
    {
        String str;
        int choice,check_acct=1,quit=0;
        choice=0;

         Curr_acct curr_obj = new Curr_acct();
         Sav_acct sav_obj = new Sav_acct();

         System.out.println("\n=====WELLCOME TO BANK DEMO PROJECT=====\n");


while( quit!=1)
{
        try{
           BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
           System.out.print("Type 1 for Current Account and Any no for Saving Account : ");
           System.out.flush();
           str=obj.readLine();
           check_acct=Integer.parseInt(str);
           }
           catch(Exception e) {}

    if(check_acct==1)
     {
        do//For Current Account
        {
        System.out.println("\n\nChoose Your Choices ...");
        System.out.println("1) New Record Entry ");
        System.out.println("2) Display Record Details ");
        System.out.println("3) Deposit...");
        System.out.println("4) Withdraw...");
        System.out.println("5) Quit");
         System.out.print("Enter your choice :  ");
        System.out.flush();
              try{
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                   str=obj.readLine();
                   choice=Integer.parseInt(str);

                          switch(choice)
                           {
                            case 1 :  //New Record Entry
                                            curr_obj.newEntry();
                                           break;
                            case 2 :  //Displaying Record Details
                                           curr_obj.display();
                                           break;
                            case 3 : //Deposit...
                                            curr_obj.deposit();
                                           break;
                            case 4 : //Withdraw...
                                            curr_obj.withdraw();
                                            break;
                            case 5  :  System.out.println("\n\n.....Closing Current Account.....");
                                            break;
                            default : System.out.println("\nInvalid Choice \n\n");
                          }
                    }
                catch(Exception e)
                {}
            }while(choice!=5);
    }
else
  {
      do//For Saving Account
        {
        System.out.println("Choose Your Choices ...");
        System.out.println("1) New Record Entry ");
        System.out.println("2) Display Record Details ");
        System.out.println("3) Deposit...");
        System.out.println("4) Withdraw...");
        System.out.println("5) Quit");
         System.out.print("Enter your choice :  ");
        System.out.flush();
              try{
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                   str=obj.readLine();
                   choice=Integer.parseInt(str);

                          switch(choice)
                           {
                            case 1 :  //New Record Entry
                                            sav_obj.newEntry();
                                           break;
                            case 2 :  //Displaying Record Details
                                           sav_obj.display();
                                           break;
                            case 3 : //Deposit...
                                            sav_obj.deposit();
                                           break;
                            case 4 : //Withdraw...
                                            sav_obj.withdraw();
                                            break;
                            case 5  :  System.out.println("\n\n.....Closing Saving Account.....");
                                            break;
                            default : System.out.println("\nInvalid Choice \n\n");
                          }
                    }
                catch(Exception e)
                {}
            }while(choice!=5);
      }

try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter 1 for Exit : ");
System.out.flush();
str=obj.readLine();
quit=Integer.parseInt(str);
}catch (Exception e){}
}
  }
}
  
Share: 


Didn't find what you were looking for? Find more on Program to display bank account Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program to display bank account is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!