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

When run, your program should read data from an input file called bankfile.txt t

ID: 3757973 • Letter: W

Question

When run, your program should read data from an input file called bankfile.txt to create your bank environment. The input file will have the following format:
The first line will be an integer n to indicate the number of bank accounts included in the file
The next n lines will be pairs of an integer and a float. These are an account number and the original balance in the account
The subsequent lines of data each begin with a character representing the service to be performed. This is followed by an account number (an integer), indicating the account on which the service is to be applied. If the service is W or D, an amount will follow the account number. When the service is W, this amount represents the withdrawal amount. When the service is D, the amount represents the amount of money that should be deposited into the account.
You may assume that the account numbers and amounts are valid numbers. However, your program should check that the requested service is legitimate. If it is not, your code should print out an error message.
Your program should process each of the requested services one line at a time- as it is read. The data terminates when a line of data is read, in which the service character is Z. When this Z is encountered, your program prints out a summary of the balances in each of the n accounts as shown in the sample output.
The implementation of your solution to this assignment should include the following functions:
1. withdraw: This function takes 2 floats. The first represents the current balance of the account, and the second is the amount of money to be withdrawn from the account. The function returns the updated balance after the withdrawal. Note that if the account does not have enough to make the withdrawal, then the balance remains unchanged and an error message is printed
2. deposit: This function takes 2 floats. The first represents the current balance of the account, and the second is the amount of money to be deposited into the account. The function returns the updated balance after the deposit.
3. update: This function takes a single float – the balance in the account. It computes the interest for the account, and updates the account balance by adding the interest to the balance. The function returns the updated balance.
4. getBalance: This function takes an integer representing the account number , an integer array storing account numbers and an array of floats which stores account balance. The function returns the balance in that account.
5. processServices: This function takes three parameters: a file pointer representing the file from which the data is being read, an integer array storing account numbers and an array of floats which stores account balances. The function reads each line requesting service and calls the appropriate function, to get the service rendered to the appropriate account.
Objectives: . The purpose of this assignment, is for students to demonstrate their ability to use
C syntax and semantics to create user defined functions
C syntax to read file input
C syntax to format data output
C variable declarations to create appropriate variable types to store program data
C syntax and semantics to create a program that compiles and runs correctly
Comments to annotate code
Error handling techniques to build robust code by using correct C syntax and semantics

Hint: Parallel arrays may be useful in designing your solution.

Your program MUST include the 5 functions described above. You may include other functions if you wish.
Sample input/output
Your program should run on any input file that matches the format of the sample bankfile.txt below
3
123 20000.00
467 10000.00
499 2500.00
W 467 2000.00
D 123 50.00
B 123
U 467
W 499 125.00
Z
Sample screen output
Account Balance

---------------------------------
123 20050.00
467 8148.00
499 2375.00

Explanation / Answer

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 DEPOSIT AN AMOUNTpublicvoid 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)

            {}

       }

     //TO WITHDRAW BALANCEpublicvoid 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");

                                    //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]+" ");

                                }

                        }

                 }

            catch(Exception e)

            {}

       }

}    

       

       

       

       

       

                       

                        //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)

            {}

        }

          //TO DEPOSIT AN AMOUNTpublicvoid 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)

            {}

       }

     //TO WITHDRAW BALANCEpublicvoid withdraw()

        {

              String str;

              double amt,checkamt;

              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(" As per Bank Rule you should maintain minimum balance of Rs

500 ");

                                }

                        }

                 }

            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(" =====WELLCOME TO BANK DEMO PROJECT===== ");

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(" 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

                                            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(" .....Closing Current Account.....");

                                            break;

                            default : System.out.println(" Invalid Choice ");

                          }

                    }

                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(" .....Closing Saving Account.....");

                                            break;

                            default : System.out.println(" Invalid Choice ");

                          }

                    }

                catch(Exception e)

                {}

            }while(choice!=5);

      }

try{

BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));

System.out.print(" Enter 1 for Exit : ");

System.out.flush();

str=obj.readLine();

quit=Integer.parseInt(str);

}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