Strip HTML

profileAkinty
BAUncompressed.zip

__MACOSX/._BA Uncompressed

BA Uncompressed/.DS_Store

__MACOSX/BA Uncompressed/._.DS_Store

BA Uncompressed/pom.xml

4.0.0 swsec bank 1.0 jar Banking Application google_checks.xml 2.17 2.6 3.0.1 2.10.2 2.1 1.7 4.12 2.5 1.1.3 2.6 2.6 1.7.12 3.4 1.2.1 UTF-8 ${project.groupId}.${project.ArtifactId}.Runner ${project.artifactId} org.apache.maven.plugins maven-checkstyle-plugin ${checkstyle.version} compile verify-style check true 100 warning org.apache.maven.plugins maven-jar-plugin ${maven.jar.plugin.version} true lib/ ${project.mainClass} org.codehaus.mojo exec-maven-plugin ${exec.maven.plugin.version} test java ${project.mainClass} org.apache.maven.plugins maven-surefire-report-plugin ${surefire.report.version} report-only failsafe-report-only org.codehaus.mojo cobertura-maven-plugin ${cobertura.version} html xml ch.qos.logback logback-classic org.codehaus.mojo findbugs-maven-plugin ${findbugs.version} org.apache.maven.plugins maven-pmd-plugin ${pmd.version} org.codehaus.mojo javancss-maven-plugin ${javancss.version} org.apache.maven.plugins maven-checkstyle-plugin ${checkstyle.version} org.apache.maven.plugins maven-javadoc-plugin ${javadoc.version} org.apache.maven.plugins maven-jxr-plugin ${jxr.version} true com.googlecode.jmockit jmockit ${jmockit.version} test junit junit ${junit.version} test org.slf4j slf4j-api ${org.slf4j.version} ch.qos.logback logback-classic ${logback.version} ch.qos.logback logback-core ${logback.version}

BA Uncompressed/google_checks.xml

BA Uncompressed/admins.txt

admin1 password1 Barak Obama 1234 admin2 password2 Donald Trump 5678

BA Uncompressed/customers.txt

cseaman biscuit 1234 Carolyn Seaman Happy Lane, Pleasantville biscuit cseaman 5678 Biscuit Dog Walkabout, Sydney newone abcdef 0 New Customer New Block, Welcomeville

BA Uncompressed/bank.iml

BA Uncompressed/accounts.txt

1234 305.0 5678 253.0 910 0.00 6615 5005.0

__MACOSX/BA Uncompressed/._src

BA Uncompressed/src/.DS_Store

__MACOSX/BA Uncompressed/src/._.DS_Store

__MACOSX/BA Uncompressed/src/._main

BA Uncompressed/src/main/.DS_Store

__MACOSX/BA Uncompressed/src/main/._.DS_Store

__MACOSX/BA Uncompressed/src/main/._resources

__MACOSX/BA Uncompressed/src/main/._java

BA Uncompressed/src/main/java/.DS_Store

__MACOSX/BA Uncompressed/src/main/java/._.DS_Store

__MACOSX/BA Uncompressed/src/main/java/._swsec

BA Uncompressed/src/main/java/admins.txt

admin1 password1 Barak Obama 1234 admin2 password2 Donald Trump 5678

BA Uncompressed/src/main/java/customers.txt

cseaman biscuit 1234 Carolyn Seaman Happy Lane, Pleasantville biscuit cseaman 5678 Biscuit Dog Walkabout, Sydney newone abcdef 6730 New Customer New Block, Welcomeville

BA Uncompressed/src/main/java/accounts.txt

1234 395.0 5678 253.0 910 0.00 6615 5005.0 6730 3000.0

BA Uncompressed/src/main/java/swsec/.DS_Store

__MACOSX/BA Uncompressed/src/main/java/swsec/._.DS_Store

__MACOSX/BA Uncompressed/src/main/java/swsec/._bank

BA Uncompressed/src/main/java/swsec/bank/.DS_Store

__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._.DS_Store

BA Uncompressed/src/main/java/swsec/bank/Runner.java

BA Uncompressed/src/main/java/swsec/bank/Runner.java

package  swsec . bank ;

import  swsec . bank . services . UiService ;

/** 
 *  This class starts the program and should not be modified.
 */
public   class   Runner   {

   public   static   void  main ( String []  args )   {
     Runnable  start  =   new   UiService ();

    start . run ();
   }
}

BA Uncompressed/src/main/java/swsec/bank/Runner.class

__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._models

__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._exceptions

BA Uncompressed/src/main/java/swsec/bank/cd

__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._controllers

__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._services

BA Uncompressed/src/main/java/swsec/bank/models/Admin.java

BA Uncompressed/src/main/java/swsec/bank/models/Admin.java

package  swsec . bank . models ;

public   class   Admin   {
  
   // Instance variables
   private   String  username ;
   private   String  password ;
   private   String  name ;
   private   String  employeeId ;
   private   boolean  authenticated  =   false ;


   public   Admin ()   {

     // needs to pass in values for all instance variables and assign those values to the variables
   }

   public   Admin ( String  username ,   String  password ,   String  name ,   String  employeeId )   {
     // Use when all attributes are known
     this . username  =  username ;
     this . password  =  password ;
     this . name  =  name ;
     this . employeeId  =  employeeId ;
   }

   public   Admin ( String  name ,   String  employeeId )   {
     //sometimes an Admin object needs to be created before login credentials are known
     this . name  =  name ;
     this . employeeId  =  employeeId ;
   }

   public   void  setCredentials ( String  username ,   String  password )   {
     this . username  =  username ;
     this . password  =  password ;
   }

   public   void  markAuthenticated ()   {
     this . authenticated  =   true ;
   }

   public   String  getUsername ()   {
     return   this . username ;
   }

   public   String  getPassword ()   {
     return   this . password ;
   }

   public   String  getName ()   {
     return   this . name ;
   }

   public   String  getEmployeeId ()   {
     return   this . employeeId ;
   }

   public   boolean  isAuthenticated ()   {
     return   this . authenticated ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/models/Customer.java

BA Uncompressed/src/main/java/swsec/bank/models/Customer.java

package  swsec . bank . models ;

public   class   Customer   {
    
   // Instance variables
   private   String  username ;    //used as a unique identifier
   private   String  password ;
   private   int  accountNum ;
   private   String  name ;
   private   String  address ;
   private   boolean  authenticated  =   false ;

  
   public   Customer ( String  username ,   String  password ,   String  name ,   String  address )   {
     // Use when all attributes are known
     this . username  =  username ;
     this . password  =  password ;
     this . name  =  name ;
     this . address  =  address ;
   }

   public   Customer ( String  username ,   String  password )   {
     //sometimes a Customer object needs to be created in order to retrieve Customer attributes
     this . username  =  username ;
     this . password  =  password ;
   }

   public   void  markAuthenticated ()   {
     // called after the associated Repository object confirms credentials
     this . authenticated  =   true ;
   }

   public   void  setAccountNum ( int  accountNum )   {
     this . accountNum  =  accountNum ;
   }

   public   void  setName ( String  name )   {
     this . name  =  name ;
   }

   public   void  setAddress ( String  address )   {
     this . address  =  address ;
   }

   public   void  setCredentials ( String  username ,   String  password )   {
     this . username  =  username ;  
     this . password  =  password ;
   }

   public   void  logout ()   {
     this . authenticated  =   false ;
   }

   public   String  getUsername ()   {
     return   this . username ;
   }

   public   String  getPassword ()   {
     return   this . password ;
   }

   public   String  getName ()   {
     return   this . name ;
   }

   public   String  getAddress ()   {
     return   this . address ;
   }

   public   int  getAccountNum ()   {
     return   this . accountNum ;
   }

   public   boolean  isAuthenticated ()   {
     return   this . authenticated ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/models/Customer.class

BA Uncompressed/src/main/java/swsec/bank/models/Account.java

BA Uncompressed/src/main/java/swsec/bank/models/Account.java

package  swsec . bank . models ;

public   class   Account   {
  
   // Instance variables
   private   int  accountNum ;
   private   float  currentBalance ;

   public   Account ()   {
     // constructor doesn't do anything, in the case when a new account is being created 
     // because the variables are not known yet. 
   }

   public   Account ( int  accountNum ,   float  currentBalance )   {
     // in the case where an Account object is needed to represent an existing account, 
     // then the instance variables are populated.
     this . accountNum  =  accountNum ;
     this . currentBalance  =  currentBalance ;
   }

   public   void  setAccountNum ( int  accountNum )   {
     this . accountNum  =  accountNum ;
   }

   public   void  setCurrentBalance ( float  currentBalance )   {
     this . currentBalance  =  currentBalance ;
   }

   public   int  getAccountNum ()   {
     return   this . accountNum ;
   }

   public   float  getCurrentBalance ()   {
     return   this . currentBalance ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/models/Admin.class

BA Uncompressed/src/main/java/swsec/bank/models/Person.java

BA Uncompressed/src/main/java/swsec/bank/models/Person.java

package  swsec . bank . models ;

public   abstract   class   Person   {
  
   // Instance variables

   public   Person ()   {
  
   }
  
   // Other constructors
  

   // Getters and Setters
}

BA Uncompressed/src/main/java/swsec/bank/models/Account.class

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNoAccountException.java

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNoAccountException.java

package  swsec . bank . exceptions ;

// Exception thrown by the CustomerController class methods and handled in UiServices
//
public   class   CustomerNoAccountException   extends   Exception   {

   private   String  username ;  

   // constructor
   public   CustomerNoAccountException ( String  username )   {
     super ( "Customer "   +  username  +   " does not have an account." );
     this . username  =  username ;
   }

   public   String  getUsername ()   {
     return  username ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustNotFoundException.class

BA Uncompressed/src/main/java/swsec/bank/exceptions/AdminNotFoundException.class

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNotAuthenticatedException.java

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNotAuthenticatedException.java

package  swsec . bank . exceptions ;

// Exception thrown by the CustomerController class methods and handled in UiServices
//
public   class   CustomerNotAuthenticatedException   extends   Exception   {

   private   String  username ;  

   // constructor
   public   CustomerNotAuthenticatedException ( String  username )   {
     super ( "Customer "   +  username  +   " is not authenticated." );
     this . username  =  username ;
   }

   public   String  getUsername ()   {
     return  username ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNotAuthenticatedException.class

BA Uncompressed/src/main/java/swsec/bank/exceptions/InsufficientFundsException.java

BA Uncompressed/src/main/java/swsec/bank/exceptions/InsufficientFundsException.java

package  swsec . bank . exceptions ;

// Exception thrown by the CustomerController class methods and handled in UiServices
//
public   class   InsufficientFundsException   extends   Exception   {

   private   String  username ;
   private   Float  amount ;  

   // constructor
   public   InsufficientFundsException ( String  username ,   Float  amount )   {
     super ( "Customer "   +  username 
         +   " does not have sufficient funds to cover a withdrawal of "  
         +   Float . toString ( amount ));
     this . username  =  username ;
     this . amount  =  amount ;
   }

   public   Float  getAmount ()   {
     return  amount ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNoAccountException.class

BA Uncompressed/src/main/java/swsec/bank/exceptions/AmountNotVerifiedException.java

BA Uncompressed/src/main/java/swsec/bank/exceptions/AmountNotVerifiedException.java

package  swsec . bank . exceptions ;

// Exception thrown by the CustomerController class methods and handled in UiServices
//
public   class   AmountNotVerifiedException   extends   Exception   {

   private   Float  amount ;  

   // constructor
   public   AmountNotVerifiedException ( Float  amount )   {
     super ( "Amount of "   +  amount  +   " has not been verified." );
     this . amount  =  amount ;
   }

   public   Float  getAmount ()   {
     return  amount ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/exceptions/AdminNotFoundException.java

BA Uncompressed/src/main/java/swsec/bank/exceptions/AdminNotFoundException.java

package  swsec . bank . exceptions ;

// Exception thrown by the AdminRepository class methods and handled in UiServices
//
public   class   AdminNotFoundException   extends   Exception   {

   private   String  username ;  

   // constructor
   public   AdminNotFoundException ( String  username )   {
     super ( "Admin "   +  username  +   " does not exist." );
     this . username  =  username ;
   }

   public   String  getUsername ()   {
     return  username ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/exceptions/AccountNotFoundException.java

BA Uncompressed/src/main/java/swsec/bank/exceptions/AccountNotFoundException.java

package  swsec . bank . exceptions ;

// Exception thrown by the AccountRepository class methods and handled in UiServices
//
public   class   AccountNotFoundException   extends   Exception   {

   private   int  accountNum ;

   // constructor
   public   AccountNotFoundException ( int  accountNum )   {
     super ( "Account "   +   Integer . toString ( accountNum )   +   " does not exist." );
     this . accountNum  =  accountNum ;
   }

   public   int  getAccountNum ()   {
     return  accountNum ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/exceptions/AccountNotFoundException.class

BA Uncompressed/src/main/java/swsec/bank/exceptions/InsufficientFundsException.class

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustNotFoundException.java

BA Uncompressed/src/main/java/swsec/bank/exceptions/CustNotFoundException.java

package  swsec . bank . exceptions ;

// Exception thrown by the CustomerRepository class methods and handled in UiServices
//
public   class   CustNotFoundException   extends   Exception   {

   private   String  username ;  

   // constructor
   public   CustNotFoundException ( String  username )   {
     super ( "Customer "   +  username  +   " does not exist." );
     this . username  =  username ;
   }

   public   String  getUsername ()   {
     return  username ;
   }

}

BA Uncompressed/src/main/java/swsec/bank/exceptions/AmountNotVerifiedException.class

BA Uncompressed/src/main/java/swsec/bank/controllers/AdminController.java

BA Uncompressed/src/main/java/swsec/bank/controllers/AdminController.java

package  swsec . bank . controllers ;

import  swsec . bank . exceptions . AccountNotFoundException ;
import  swsec . bank . models . Admin ;
import  swsec . bank . models . Customer ;
import  swsec . bank . services . repositories . AdminRepository ;
import  swsec . bank . services . repositories . CustomerRepository ;

import  java . io . IOException ;

public   class   AdminController   {

   private   AdminRepository  thisRep ;
   private   Admin  thisAdmin ;

   public   AdminController ()   {
     // every instance of a Controller needs a corresponding Repository and Model object
    thisRep  =   new   AdminRepository ();
    thisAdmin  =   new   Admin ();
   }


   // uses thisRep to look up Admin - if successful, will load Admin attributes into thisAdmin
   // and mark authenticated
   public   boolean  authenticate ( String  username ,   String  password )   {
    thisAdmin . setCredentials ( username ,  password );
     Admin  tempAdmin  =  thisRep . lookup ( thisAdmin );
     if   ( tempAdmin . isAuthenticated ())   {
      thisAdmin  =  tempAdmin ;
       return   ( true );  
     }   else   {
       return   ( false );
     }  
   }

   public   int  requestAccount ( float  initialBalance )   {
     // called by CustomerController
     // needs to create an instance of UiService, which authenticates the Admin
     // then needs to create an instance of an AccountController, which 
     // it uses to create the new account

     // TBD
     // UiService thisUIS = new UiService ();
     // thisUIS.authenticateAdmin ();
     AccountController  thisNewAcct  =   new   AccountController ( 0 );
     return  thisNewAcct . newAccount ( initialBalance );
   }

   public   void  modifyBalance ( int  accountNum ,   float  newBalance )   throws  
     IOException ,   AccountNotFoundException   {
     // checks to make sure this Admin object is authenticated
     // creates an instance of AccountController and uses it to modify the balance
     if   ( thisAdmin . isAuthenticated ())   {
       AccountController  thisAcct  =   new   AccountController ( accountNum );
       try   {
        thisAcct . changeBalance ( newBalance );
       }   catch   ( IOException  ex )   {
         throw   new   IOException ();
       }   catch   ( AccountNotFoundException  acctEx )   {
         throw   new   AccountNotFoundException ( accountNum );
       }
     }   else   {
       System . out . println ( "Admin needs to be authenticated first." );
     }
   }
}

BA Uncompressed/src/main/java/swsec/bank/controllers/CustomerController.java

BA Uncompressed/src/main/java/swsec/bank/controllers/CustomerController.java

package  swsec . bank . controllers ;

import  swsec . bank . exceptions . AccountNotFoundException ;
import  swsec . bank . exceptions . AmountNotVerifiedException ;
import  swsec . bank . exceptions . CustNotFoundException ;
import  swsec . bank . exceptions . CustomerNoAccountException ;
import  swsec . bank . exceptions . CustomerNotAuthenticatedException ;
import  swsec . bank . exceptions . InsufficientFundsException ;
import  swsec . bank . models . Customer ;
import  swsec . bank . services . VerificationSystem ;
import  swsec . bank . services . repositories . CustomerRepository ;

import  java . io . IOException ;

public   class   CustomerController   {

   private   CustomerRepository  thisRep ;   //the repository object associated with this customer
   private   Customer  thisCust ;            // the model object associated with this customer

   // the account controller associated with this customer's account, if the customer has one
   private   AccountController  thisAcct ;  

   private   VerificationSystem  vs  =   new   VerificationSystem ();

   public   boolean  hasAcct  =   false ;    // indicates if this customer has an account yet

   // constructor - called when a customer logs in, so username and password are known, 
   // but no other attributes are yet known
   // Assumes that all customers are created a priori; a new constructor will need to be i
   // added to create a new customer that does not previously exist
   public   CustomerController ( String  username ,   String  password )   throws   CustNotFoundException ,  
          IOException    {
    
     int  accountNum ;

     // every instance of CustomerController needs a thisRep and a thisCust
    thisRep  =   new   CustomerRepository ();
    thisCust  =   new   Customer ( username ,  password );

     //make sure it's a valid Customer
     try   {
      accountNum  =  authenticate ( thisRep ,  thisCust );

     }   catch   ( IOException  ex )   {
       throw   new   IOException ();  
     }
     if   ( accountNum  ==   - 1 )   {        //customer was not found or password wrong
       throw   new   CustNotFoundException ( username );
     }   else   {
       if   ( accountNum  >   0 )   {   //customer has an account 
         //create AccountController object
        hasAcct  =   true ;
        thisAcct  =   new   AccountController ( accountNum );
       }
     }
   }

   public   boolean  hasAcct ()   {

     return   this . hasAcct ;
   }


    
   // uses thisRep to lookup customer - if successful, will load customer attributes into 
   // tempCust and mark authenticated
   public   int  authenticate ( CustomerRepository  thisRep ,   Customer  thisCust )   throws   IOException   {
     Customer  tempCust ;

     try   {
      tempCust  =  thisRep . lookup ( thisCust );    //lookup will also check password

     }   catch   ( IOException  ex )   {
       throw   new   IOException ();
     }

     if   ( tempCust . isAuthenticated ())   {
      thisCust  =  tempCust ;

       return   ( tempCust . getAccountNum ());    //will return 0 if there is no account number
     }   else   {
       return   ( - 1 );
     }
   }
   

   // when a new account is created for this Customer, most of the work is done in AdminController, 
   // but this object has to store the account number in the Customer object.
   public   void  linkAccount ( int  accountNum ,   AccountController  newAcct )   throws   CustNotFoundException ,  
          IOException   {
    thisCust . setAccountNum ( accountNum );
    thisAcct  =  newAcct ;
     try   {
      thisRep . update ( thisCust );
     }   catch   ( IOException  ex )   {
       throw   new   IOException ();
     }   catch   ( CustNotFoundException  ex )   {
       throw   new   CustNotFoundException ( thisCust . getUsername ());
     }
   }


   // returns true if everything goes ok; otherwise throws exceptions
   public   boolean  makeDeposit ( float  amount )   throws   CustomerNoAccountException ,  
          AmountNotVerifiedException ,   CustomerNotAuthenticatedException ,   AccountNotFoundException ,  
          IOException   {

     // checks to make sure thisCust is authenticated
     if   ( thisCust . isAuthenticated ())   {

       // checks verification system to verify amount
       if   ( this . vs . confirmAmount ( amount ))   {

         // check to make sure that this customer actually has an account, in which 
         // case thisAcct is already populated
         if   ( thisCust . getAccountNum ()   >   0 )   {
           try   {
            thisAcct . changeBalance ( thisAcct . getBalance ( thisCust . getAccountNum ())   +  amount );
           }   catch   ( IOException  ex )   {
             throw   new   IOException ()   ;
           }   catch   ( AccountNotFoundException  ex )   {
             throw   new   AccountNotFoundException ( thisCust . getAccountNum ());
           }

           // return true 
           return   ( true );
         }   else   {
           // customer doesn't have an account
           throw   new   CustomerNoAccountException ( thisCust . getUsername ());
         }  
       }   else   {
         // verification system says amount is not correct
         throw   new   AmountNotVerifiedException ( amount );
       }  
     }   else   {
       // customer is not authenticated
       throw   new   CustomerNotAuthenticatedException ( thisCust . getUsername ());
     }
   }


   // returns true if everything goes ok; otherwise throws exceptions
   public   boolean  makeWithdrawal ( float  amount )   throws   CustomerNoAccountException ,  
          AmountNotVerifiedException ,   CustomerNotAuthenticatedException ,   InsufficientFundsException ,  
          AccountNotFoundException ,   IOException   {

     float  currentBalance ;

     // checks to make sure thisCust is authenticated
     if   ( thisCust . isAuthenticated ())   {

       // checks verification system to verify amount
       if   ( this . vs . confirmAmount ( amount ))   {

         // check to make sure that this customer actually has an account, in which case 
         // thisAcct is already populated
         if   ( thisCust . getAccountNum ()   >   0 )   {
           try   {
            currentBalance  =  thisAcct . getBalance ( thisCust . getAccountNum ());
           }   catch   ( IOException  ex )   {
             throw   new   IOException ();
           }   catch   ( AccountNotFoundException  ex )   {
             throw   new   AccountNotFoundException ( thisCust . getAccountNum ());
           }

           if   ( amount  <  currentBalance )   {
             try   {
              thisAcct . changeBalance ( thisAcct . getBalance ( thisCust . getAccountNum ())   -  amount );
             }   catch   ( AccountNotFoundException  ex )   {
               throw   new   AccountNotFoundException ( thisCust . getAccountNum ());
             }

             // return true 
             return   ( true );  
           }   else   {
             // customer doesn't have enough money in the account
             throw   new   InsufficientFundsException ( thisCust . getUsername (),  amount );
           }  
         }   else   {
           // customer doesn't have an account
           throw   new   CustomerNoAccountException ( thisCust . getUsername ());
         }  
       }   else   {
         // verification system says amount is not correct
         throw   new   AmountNotVerifiedException ( amount );
       }  
     }   else   {
       // customer is not authenticated
       throw   new   CustomerNotAuthenticatedException ( thisCust . getUsername ());
     }
   }


   // returns the balance of this customer's account, if the customer is authenticated 
   // and has an account
   public   float  getBalance ()   throws   IOException ,   CustomerNoAccountException ,  
          AccountNotFoundException   {
     float  balance  =   0 ;

     // checks to make sure thisCust is authenticated
     if   ( thisCust . isAuthenticated ())   {

       // check to make sure that this customer actually has an account, in which case 
       // thisAcct is already populated
       if   ( thisCust . getAccountNum ()   >   0 )   {

         try   {
          balance  =  thisAcct . getBalance ( thisCust . getAccountNum ());

         }   catch   ( IOException  ex )   {
           throw   new   IOException ();
         }   catch   ( AccountNotFoundException  ex )   {
           throw   new   AccountNotFoundException ( thisCust . getAccountNum ());
         }

       }   else   {
         // customer doesn't have an account
         throw   new   CustomerNoAccountException ( thisCust . getUsername ());
       }
     }
     return   ( balance );
   }

   //if this customer has an account, returns the AccountController object, 
   //otherwise throws an exception
   public   AccountController  getAcct ()   throws   CustomerNoAccountException   {
     if   ( hasAcct )   {
       return  thisAcct ;
     }   else   {
       throw   new   CustomerNoAccountException ( thisCust . getUsername ());
     }
   }


   // marks a customer as not authenticated
   public   void  logout ()   {
     // marks thisCust as not authenticated
    thisCust . logout ();
   }
}  

BA Uncompressed/src/main/java/swsec/bank/controllers/AccountController.class

BA Uncompressed/src/main/java/swsec/bank/controllers/CustomerController.class

BA Uncompressed/src/main/java/swsec/bank/controllers/AccountController.java

BA Uncompressed/src/main/java/swsec/bank/controllers/AccountController.java

package  swsec . bank . controllers ;

import  swsec . bank . exceptions . AccountNotFoundException ;

import  swsec . bank . models . Account ;
import  swsec . bank . models . Admin ;
import  swsec . bank . services . repositories . AccountRepository ;
import  swsec . bank . services . repositories . AdminRepository ;

import  java . io . IOException ;
import  java . util . Random ;

public   class   AccountController   {

   private   AccountRepository  thisRep ;
   private   Account  thisAccount ;
   private   Random  rnd ;

   public   AccountController ( int  accountNum )   {
     // every instance of a Controller needs a corresponding Repository and Model object
    thisRep  =   new   AccountRepository ();
    thisAccount  =   new   Account ();
    rnd  =   new   Random ();
    thisAccount . setAccountNum ( accountNum );    //might be 0 if there is no acct# yet
   }


   public   void  changeBalance ( float  newBalance )   throws   IOException ,   AccountNotFoundException   {
     this . thisAccount . setCurrentBalance ( newBalance );   //put the new balance in the model object

     try   {
       this . thisRep . modifyBalance ( thisAccount ,  newBalance );    // put the new balance in the repository
     }   catch   ( IOException  ex )   {
       throw   new   IOException ();
     }   catch   ( AccountNotFoundException  accEx )   {
       throw   new   AccountNotFoundException ( thisAccount . getAccountNum ());
     }
   }

   public   int  newAccount ( float  newBalance )   {
     // create new account number and add it to thisAccount
     // use thisRep to write new account to the file
     // return account #

     //produces an integer between 1000 and 9999
     int  newAccountNum  =   1000   +   ( rnd . nextInt ( 8999 ));  
    
    thisAccount . setAccountNum ( newAccountNum );
    thisAccount . setCurrentBalance ( newBalance );
    thisRep . save ( thisAccount );

     return   ( newAccountNum );
  
   }

   public   float  getBalance ( int  accountNum )   throws   IOException ,   AccountNotFoundException   {  
     // look up the account number and return the associated balance
   
     float  balance  =   0 ;
     try   {

      balance  =  thisRep . getBalance ( accountNum );

     }   catch   ( IOException  ex )   {
       throw   new   IOException ();
     }   finally   {
       return   ( balance );
     }
   }

}

BA Uncompressed/src/main/java/swsec/bank/controllers/AdminController.class

__MACOSX/BA Uncompressed/src/main/java/swsec/bank/services/._repositories

BA Uncompressed/src/main/java/swsec/bank/services/VerificationSystem.class

BA Uncompressed/src/main/java/swsec/bank/services/UiService.class

BA Uncompressed/src/main/java/swsec/bank/services/VerificationSystem.java

BA Uncompressed/src/main/java/swsec/bank/services/VerificationSystem.java

package  swsec . bank . services ;

import  java . util . Random ;

/**
 * Created by cseaman on 3/8/2016.
 * This class simulates a physical system (e.g. an ATM or a teller) that can physically verify
 * that money has changed hands. In a real scenario, the verification system would communicate 
 * with the rest of the application over a network, but here we are simulating it with a 
 * simple method call.
 */
public   class   VerificationSystem   {

   Random  rand ;

   public   VerificationSystem ()   {
    rand  =   new   Random ();
   }

   public   boolean  confirmAmount ( float  amount )   {
     return   ( rand . nextInt ( 9 )   >   0 );     // this will return true 90% of the time
   }
}

BA Uncompressed/src/main/java/swsec/bank/services/UiService.java

BA Uncompressed/src/main/java/swsec/bank/services/UiService.java


package  swsec . bank . services ;

import  swsec . bank . controllers . AccountController ;
import  swsec . bank . controllers . AdminController ;
import  swsec . bank . controllers . CustomerController ;

import  swsec . bank . exceptions . AccountNotFoundException ;
import  swsec . bank . exceptions . AdminNotFoundException ;
import  swsec . bank . exceptions . AmountNotVerifiedException ;
import  swsec . bank . exceptions . CustNotFoundException ;
import  swsec . bank . exceptions . CustomerNoAccountException ;
import  swsec . bank . exceptions . CustomerNotAuthenticatedException ;
import  swsec . bank . exceptions . InsufficientFundsException ;

import  java . io . IOException ;
import  java . util . Scanner ;

public   class   UiService   implements   Runnable   {

   CustomerController  thisCust ;     // represents the Customer currently interacting with the UI

   // represents the Account belonging to the customer currently interacting with the UI
   AccountController  thisAcct ;     

   AdminController  thisAdmin ;       // represents the Admin currently interacting with the UI
   VerificationSystem  vs  =   new   VerificationSystem ();

   public   UiService ()   {    //constructor doesn't really do anything
   }

   //This gets called by main() in class Runner
   public   void  run ()   {
    runUi ();
   }


   public   void  runUi ()   {
     Scanner  scanner  =   null ;
     boolean  quit  =   false ;
    quit  =  initialLogin ();   // initialLogin returns true if user wants to quit
     while   ( ! quit )   {
      quit  =  showMenu ();    // showMenu returns true if user wants to quit
     }
     if   ( scanner  !=   null )   {
      scanner . close ();
     }
   }
  
  public   static   boolean  isBlackList ( String  val )   {
    String  BLACK_LIST_INPUT  =   "*[]#$" ;
    if   ( val  ==   null ){
    return   false ;
   }
  
   for   ( int  i = 0 ;  i < val . length ();  i ++ ){
    if   ( BLACK_LIST_INPUT . indexOf ( val . charAt ( i )) >= 0 ){
       return   true ;
    }
   }
  
   return   false ;
  }
  
   public   static   String  stripHtml ( String  inStr ){
      boolean  inTag  =   false ;
      char  c ;
      int  tagPos  =   0 ;
      StringBuffer  outStr  =   new   StringBuffer ();
      int  len  =  inStr . length ();
      for   ( int  i  = 0 ; i < len ;  i ++ ){
         c  =  inStr . charAt ( i );
          if   ( ==   '<' ){
            outStr . append ( "" );
            tagPos  =   0 ;
            inTag  =   true ;
          }
          if   ( inTag  ==   false ){
            outStr . append ( c );
          }
          if   ( ==   '>' ){
            inTag  =   false ;
             if ( tagPos  ==   1 ){
            outStr . append ( "<>" );
             }
          }
         tagPos  +=   1 ;
       }
       return  outStr . toString ();
  }     
      
     

   public   static   boolean  toString cleanseInput ( String  input ){
    if   ( isBlackList ( input ))   {
    System . out . println ( "Your username or password contains an invalid character" );
    return   true ;
    }
   
    if   ( stripHtml ( input )){
    System . out . println ( "Your username or password contains an invalid character" );
    return   true ;
    }

    return   false ;
   
   }

   protected   boolean  initialLogin ()   {
     // allow user to try to log in as many times as they want

     boolean  wantsToQuit  =   false ;
     boolean  loggedIn  =   false ;
     String  inUsername ;     //the username typed in
     String  inPassword ;     // the password typed in
     Scanner  scanner  =   new   Scanner ( System . in ,   "UTF-8" );

      while   ( ! wantsToQuit  &&   ! loggedIn )   {

       System . out . println ( "Please type your username or EXIT to quit:" );

      inUsername  =  scanner . nextLine ();
      
       while   ( cleanseInput ( inUsername )){
       System . out . println ( "Please type your username or EXIT to quit: " );
      inUsername  =  scanner . nextLine ();
       }
            
      wantsToQuit  =   ( inUsername . compareTo ( "EXIT" )   ==   0 );

       if   ( ! wantsToQuit )   {
         System . out . println ( "Please type your password:" );
        inPassword  =  scanner . nextLine ();
        
         while   ( cleanseInput ( inPassword )){
       System . out . println ( "Please type your password : " );
     
      inPassword  =  scanner . nextLine ();
       }

        loggedIn  =   true ;   
        
         // creates a new customer controller object, also authenticates
         try   {
          thisCust  =   new   CustomerController ( inUsername ,  inPassword );
         }   catch   ( IOException  ex )   {
           System . out . println ( "Something went wrong with our database. Let's try again..." );
          loggedIn  =   false ;
         }   catch   ( CustNotFoundException  ex )   {
           System . out . println ( "Username or password not found. Please try again." );
          loggedIn  =   false ;
         }
       }
     }
     if   ( wantsToQuit )   {
       return   true ;
     }   else   {
       return   false ;
     }
   }

   // repeat menu until user wants to log out
   protected   boolean  showMenu ()   {

     Scanner  scanner  =   new   Scanner ( System . in ,   "UTF-8" );

     // show menu, capture user's choice, and call methods to carry out user actions
     System . out . println ( "1. Create a new account" );
     System . out . println ( "2. Make a deposit" );
     System . out . println ( "3. Make a withdrawal" );
     System . out . println ( "4. Get your balance" );
     System . out . println ( "5. Log out" );
     System . out . print ( "What would you like to do? " );

     String  token  =  scanner . nextLine ();

     if   ( token . compareTo ( "1" )   ==   0 )   {
      newAccount ();
     }   else   {
       if   ( token . compareTo ( "2" )   ==   0 )   {
        makeDeposit ();
       }   else   {
         if   ( token . compareTo ( "3" )   ==   0 )   {
          makeWithdrawal ();
         }   else   {
           if   ( token . compareTo ( "4" )   ==   0 )   {
            getBalance ();
           }   else   {
             if   ( token . compareTo ( "5" )   ==   0 )   {
              logout ();
               return   true ;
             }
           }
         }
       }
     }
     return   false ;
   }


   void  newAccount ()   {
  
     Scanner  scanner  =   new   Scanner ( System . in ,   "UTF-8" );
     Float  initialBalance  =   0.0f ;
     int  accountNum ;

     //first check to see if the customer already has an account
     if   ( thisCust . hasAcct )   {
       System . out . println ( "You already have an account. You can only have one." );
       return ;

     }   else   {

       // get the initial balance
       System . out . println ( "What initial balance are you depositing into your new account?" );
      initialBalance  =  scanner . nextFloat ();

       // authenticate the Admin
      thisAdmin  =  authenticateAdmin ();

       if   ( thisAdmin  !=   null ){
         // if the verification system says that the initial balance is right,
         // then create an AccountController object and let it create the new Account
         if   ( vs . confirmAmount ( initialBalance ))   {
           // first create the AccountController object, without an account number
          thisAcct  =   new   AccountController ( 0 );

           // then call newAccount, which creates a new account number
          accountNum  =  thisAcct . newAccount ( initialBalance );

           // then link this new account to the current customer
           try   {
            thisCust . linkAccount ( accountNum ,  thisAcct );
           }   catch   ( IOException  ex )   {
             System . out . println ( "Problem writing to database. Please try again." );
             return ;
           }   catch   ( CustNotFoundException  ex )   {
             System . out . println ( "Customer not found. Please try again." );
             return ;
           }

           // if we get this far, then the account has been created successfully.
           System . out . println ( "Account created successfully." );

         }   else   {
           System . out . println ( "Amount not able to verified. Please try again." );
           return ;
         }
       }
     }
   }


   AdminController  authenticateAdmin ()   {
      
     Scanner  scanner  =   new   Scanner ( System . in ,   "UTF-8" );

     // creates an AdminController object, gets credentials from user,
     // and then authenticates the object
      
     System . out . println ( "Time to authenticate the Administrator. "
         +   "Please let the Administrator type in their credentials..." );
     System . out . println ( "Admin's username: " );
     String  username  =  scanner . nextLine ();
    
     while   ( cleanseInput ( username )){
       System . out . println ( "Please type your username again :" );
      username  =  scanner . nextLine ();
       }

     System . out . println ( "Admin's password: " );
     String  password  =  scanner . nextLine ();
    
     while   ( cleanseInput ( password )){
       System . out . println ( "Please type your password again :" );
      password  =  scanner . nextLine ();
       }


     AdminController  thisAdmin  =   new   AdminController ();
     if   ( thisAdmin . authenticate ( username ,  password ))   {
           return   ( thisAdmin );
     }   else   {
    
       System . out . println ( "Admin not verified." );
       return   ( null );
       }
      }
     
  
    void  makeDeposit ()   {

     Scanner  scanner  =   new   Scanner ( System . in ,   "UTF-8" );
     Float  depositAmount ;
     boolean  successful  =   false ;

     // get the deposit amount 
     System . out . println ( "How much would you like to deposit? " );
    depositAmount  =  scanner . nextFloat ();

     // ask customerController to make the deposit
     try   {
      successful  =  thisCust . makeDeposit ( depositAmount );
     }   catch   ( CustomerNoAccountException  ex )   {
       System . out . println ( "You have to create an account before you can make a deposit." );
     }   catch   ( AmountNotVerifiedException  ex )   {
       System . out . println ( "That amount could not be verified. Please try again." );
     }   catch   ( CustomerNotAuthenticatedException  ex )   {
       System . out . println ( "Customer is not authenticated." );
     }   catch   ( AccountNotFoundException  ex )   {
       System . out . println ( "Account not found." );
     }   catch   ( IOException  ex )   {
       System . out . println ( "Sorry, we had a problem writing to the database. Please try again." );
     }

     if   ( successful )   {
       System . out . println ( "Deposit successful. Thank you." );
     }   else   {  
       System . out . println ( "Deposit not successful. Our apologies" );
     }
   }

   void  makeWithdrawal ()   {
    
     Scanner  scanner  =   new   Scanner ( System . in ,   "UTF-8" );
     Float  withdrawAmount ;
     boolean  successful  =   false ;

     // get the withdrawal amount 
     System . out . println ( "How much would you like to withdraw?" );
    withdrawAmount  =  scanner . nextFloat ();

     // ask customerController to make the withdrawal
     try   {
      successful  =  thisCust . makeWithdrawal ( withdrawAmount );
     }   catch   ( CustomerNoAccountException  ex )   {
       System . out . println ( "You have to create an account before you can make a deposit." );
     }   catch   ( AmountNotVerifiedException  ex )   {
       System . out . println ( "That amount could not be verified. Please try again." );
     }   catch   ( InsufficientFundsException  ex )   {
       System . out . println ( "Sorry, you don't have that much in your account." );
     }   catch   ( CustomerNotAuthenticatedException  ex )   {
       System . out . println ( "Customer is not authenticated." );
     }   catch   ( AccountNotFoundException  ex )   {
       System . out . println ( "Account not found." );
     }   catch   ( IOException  ex )   {
       System . out . println ( "Sorry, we had a problem writing to the database. Please try again." );
     }

     if   ( successful )   {
       System . out . println ( "Withdrawal successful. Thank you." );
     }   else   {  
       System . out . println ( "Withdrawal not successful. Our apologies" );
     }
   }

   void  getBalance ()   {

     Scanner  scanner  =   new   Scanner ( System . in ,   "UTF-8" );
     Float  balance  =   0.0f ;

     try   {
      balance  =  thisCust . getBalance ();

     }   catch   ( IOException  ex )   {
       System . out . println ( "Sorry, we had trouble reading from our database. Please try again." );
     }   catch   ( CustomerNoAccountException  ex )   {
       System . out . println ( "You have to create an account before you can get the balance." );
     }   catch   ( AccountNotFoundException  ex )   {
       System . out . println ( "Your account cannot be found." );
     }

     if   ( balance  >   0 )   {
       System . out . println ( "Your balance is $"   +   Float . toString ( balance ));
     }
   }

   void  logout ()   {
     Scanner  scanner  =   new   Scanner ( System . in ,   "UTF-8" );
    thisCust . logout ();
     System . out . println ( "Goodbye." );
   }
}

__MACOSX/BA Uncompressed/src/main/java/swsec/bank/services/._UiService.java

BA Uncompressed/src/main/java/swsec/bank/services/repositories/CustomerRepository.java

BA Uncompressed/src/main/java/swsec/bank/services/repositories/CustomerRepository.java

package  swsec . bank . services . repositories ;

import  swsec . bank . exceptions . CustNotFoundException ;
import  swsec . bank . models . Customer ;

import  java . io . BufferedReader ;
import  java . io . FileInputStream ;
import  java . io . FileOutputStream ;
import  java . io . IOException ;
import  java . io . InputStreamReader ;
import  java . io . OutputStreamWriter ;


/**
 * This class reads from and writes to the customers.txt file which stores all the
 * customers in the system.
 */
public   class   CustomerRepository   {
  
   private   static   final   String  CUSTOMER_FILE  =   "customers.txt" ;    
  
   public   CustomerRepository ()   {
  
   }
  
  
   public   void  store ( Customer  thisCust )   {
     // write the customer's instance variables to the text file
     // Don't need this for now - we will assume the text file is pre-populated with 
     // all existing customers
   }

   public   void  update ( Customer  thisCust )   throws   IOException ,   CustNotFoundException   {
     // overwrite the information for an existing customer

     try   {

       BufferedReader  br  =   new   BufferedReader ( new   InputStreamReader ( new  
             FileInputStream ( CUSTOMER_FILE ),   "UTF-8" ));

       try   {
         String  line  =   "" ;
         String  text  =   "" ;    //the entire contents of the customer file

         while   (( line  =  br . readLine ())   !=   null )   {

           if   ( line . compareTo ( thisCust . getUsername ())   ==   0 )   {  
             //add all the new instance variables to text
            text  =  text . concat ( line );
            text  =  text . concat ( "\n" );
            text  =  text . concat ( thisCust . getPassword ());
            text  =  text . concat ( "\n" );
            text  =  text . concat ( Integer . toString ( thisCust . getAccountNum ()));
            text  =  text . concat ( "\n" );
            text  =  text . concat ( thisCust . getName ());
            text  =  text . concat ( "\n" );
            text  =  text . concat ( thisCust . getAddress ());
            text  =  text . concat ( "\n" );
            br . readLine ();    //skip over the old values of the instance variables
            br . readLine ();
            br . readLine ();
            br . readLine ();
           }   else   {
            text  =  text . concat ( line );
            text  =  text . concat ( "\n" );
           }
         }

         if   ( text . indexOf ( thisCust . getUsername ())   ==   - 1 )   {
           throw   new   CustNotFoundException ( thisCust . getUsername ());
         }

         try   {
           OutputStreamWriter  os  =   new   OutputStreamWriter ( new   FileOutputStream ( CUSTOMER_FILE ),  
               "UTF-8" );
           try   {
            os . write ( text );    //rewrite the entire file with the "text" string
           }   finally   {
            os . close ();
           }
         }   catch   ( IOException  e )   {
           System . out . println ( "could not write to file" );
         }
       }   finally   {
        br . close ();
       }

     }   catch   ( IOException  e )   {
       System . out . println ( "File could not be read/found." );
     }
   }


   public   Customer  lookup ( Customer  thisCust )   throws   IOException   {
     // use thisCust.username to look up the customer in the text file
     // if found, check stored password against thisCust.password
     // if matched, mark returned Customer object as authenticated and load instance variables
     // assumes instance variables are stored on separate lines in the following order: 
     // username, password, account number, name, address, blank line

     Customer  tempCust  =  thisCust ;    // initialize the temp variable

     try   {

       BufferedReader  br  =   new   BufferedReader ( new   InputStreamReader ( new  
             FileInputStream ( CUSTOMER_FILE ),   "UTF-8" ));

       try   {

         String  line  =   "" ;
         String  lastLine  =   "" ;

         while   (( line  =  br . readLine ())   !=   null )   {

           if   ( line . indexOf ( thisCust . getUsername ())   !=   - 1   &&  lastLine . length ()   ==   0 )   {
             String  pass  =  br . readLine ();

             if   ( pass . compareTo ( thisCust . getPassword ())   ==   0 )   {
              tempCust . markAuthenticated ();
              tempCust . setAccountNum ( Integer . parseInt ( br . readLine ()));
              tempCust . setName ( br . readLine ());
              tempCust . setAddress ( br . readLine ());
             }   else   {
              tempCust . setAccountNum ( - 1 );
             }
           }

          lastLine  =  line ;

         }
       }   finally   {
        br . close ();
       }

     }   catch   ( IOException  e )   {
       System . out . println ( "File could not be read/found." );
     }
     return   ( tempCust );
   }

}

BA Uncompressed/src/main/java/swsec/bank/services/repositories/AdminRepository.class

BA Uncompressed/src/main/java/swsec/bank/services/repositories/AdminRepository.java

BA Uncompressed/src/main/java/swsec/bank/services/repositories/AdminRepository.java

package  swsec . bank . services . repositories ;

import  swsec . bank . models . Admin ;

import  java . io . BufferedReader ;
import  java . io . FileInputStream ;
import  java . io . IOException ;
import  java . io . InputStreamReader ;

/**
 * This class reads from and writes to the admin.txt file which stores all the
 * admins in the system.
 */

public   class   AdminRepository   {
  
   private   static   final   String  ADMIN_FILE  =   "admins.txt" ;

   public   AdminRepository ()   {    //constructor really doesn't do anything
  
   }

  
   // public Admin store(Admin thisAdmin) {
   // write all thisAdmin's instance variables to the text file
   // Don't need this for now - we will assume the text file is pre-populated with all 
   // existing admins
   // }


   public   Admin  lookup ( Admin  thisAdmin )   {
     // use thisAdmin.username to look up the Admin in the text file
     // if found, check stored password against thisAdmin.password
     // if matched, mark returned Admin object as authenticated and load instance variables
     // assumes instance variables are stored on separate lines in the following order: 
     // username, password, name, employee id, blank line

     Admin  tempAdmin  =   new   Admin ( thisAdmin . getUsername (),  thisAdmin . getPassword (),  
        thisAdmin . getName (),  thisAdmin . getEmployeeId ());

     try   {

       BufferedReader  br  =   new   BufferedReader ( new   InputStreamReader ( new  
             FileInputStream ( ADMIN_FILE ),   "UTF-8" ));
       try   {

         String  line  =   "" ;
         String  lastLine  =   "" ;

         while   (( line  =  br . readLine ())   !=   null )   {

           if   ( line . indexOf ( thisAdmin . getUsername ())   !=   - 1   &&  lastLine . length ()   ==   0 )   {
             String  pass  =  br . readLine ();
            
             if   ( pass . compareTo ( thisAdmin . getPassword ())   ==   0 )   {
              tempAdmin . markAuthenticated ();
             }

           }
          lastLine  =  line ;

         }
       }   finally   {
        br . close ();
         return   ( tempAdmin );
       }

     }   catch   ( IOException  e )   {
       System . out . println ( "File could not be read/found." );
       return   ( tempAdmin );
     }
   }
}

BA Uncompressed/src/main/java/swsec/bank/services/repositories/CustomerRepository.class

BA Uncompressed/src/main/java/swsec/bank/services/repositories/AccountRepository.java

BA Uncompressed/src/main/java/swsec/bank/services/repositories/AccountRepository.java

package  swsec . bank . services . repositories ;

import  swsec . bank . exceptions . AccountNotFoundException ;
import  swsec . bank . models . Account ;

import  java . io . BufferedReader ;
import  java . io . FileInputStream ;
import  java . io . FileOutputStream ;
import  java . io . IOException ;
import  java . io . InputStreamReader ;
import  java . io . OutputStreamWriter ;


/**
 * This class reads from and writes to the accounts.txt file which stores all the
 * accounts in the system.
 */

public   class   AccountRepository   {
  
   private   static   final   String  ACCOUNT_FILE  =   "accounts.txt" ;
 
   public   AccountRepository ()   {    //constructor really doesn't do anything
   
   }

   public   void  save ( Account  thisAcct )   {
     // write all thisAcct's instance variables to the text file

     try   {

       BufferedReader  br  =   new   BufferedReader ( new   InputStreamReader ( new  
             FileInputStream ( ACCOUNT_FILE ),   "UTF-8" ));

       try   {
         String  line  =   "" ;
         String  text  =   "" ;   // the entire contents of the accounts file

         // copy all account information into text string
         while   (( line  =  br . readLine ())   !=   null )   {
          text  =  text . concat ( line );
          text  =  text . concat ( "\n" );
         }

         // add new account to end of text string
        text  =  text . concat ( Integer . toString ( thisAcct . getAccountNum ()));
        text  =  text . concat ( "\n" );
        text  =  text . concat ( Float . toString ( thisAcct . getCurrentBalance ()));
        text  =  text . concat ( "\n" );

         try   {
           OutputStreamWriter  os  =   new   OutputStreamWriter ( new   FileOutputStream ( ACCOUNT_FILE ),  
               "UTF-8" );
           try   {
            os . write ( text );    //rewrite the entire file with the "text" string
           }   finally   {
            os . close ();
           }
         }   catch   ( IOException  e )   {
           System . out . println ( "could not write to file" );
         }
       }   finally   {
        br . close ();
       }

     }   catch   ( IOException  e )   {
       System . out . println ( "File could not be read/found" );
     }
   }


   public   void  modifyBalance ( Account  thisAcct ,   float  newBalance )  
     throws   IOException ,   AccountNotFoundException   {

     int  accountNum  =  thisAcct . getAccountNum ();

     // look up thisAcct in the text file and change the associated balance to newBalance

     try   {

       BufferedReader  br  =   new   BufferedReader ( new   InputStreamReader ( new  
             FileInputStream ( ACCOUNT_FILE ),   "UTF-8" ));

       try   {
         String  line  =   "" ;
         String  text  =   "" ;   // the entire contents of the accounts file

         // copy all account information into text string
         while   (( line  =  br . readLine ())   !=   null )   {

           if   ( line . compareTo ( Integer . toString ( accountNum ))   ==   0 )   {

            text  =  text . concat ( line );
            text  =  text . concat ( "\n" );
            text  =  text . concat ( Float . toString ( newBalance ));
            text  =  text . concat ( "\n" );
            line  =  br . readLine ();     //skip next line, which contains old balance
           }   else   {
            text  =  text . concat ( line );
            text  =  text . concat ( "\n" );
           }
         }

         if   ( text . indexOf ( Integer . toString ( accountNum ))   ==   - 1 )   {

           throw   new   AccountNotFoundException ( accountNum );
         }

         try   {
           OutputStreamWriter  os  =   new   OutputStreamWriter ( new   FileOutputStream ( ACCOUNT_FILE ),  
               "UTF-8" );
           try   {
            os . write ( text );     //rewrite the entire file with the "text" string
           }   finally   {
            os . close ();
           }
         }   catch   ( IOException  e )   {
           System . out . println ( "could not write to file" );
         }
       }   finally   {
        br . close ();
       }

     }   catch   ( IOException  e )   {
       System . out . println ( "File could not be read/found." );
     }
   }
                        


   public   float  getBalance ( int  accountNum )   throws   IOException   {
     // look up thisAcct in the text file and return the associated balance

     BufferedReader  br ;
     float  balance  =   0 ;

     try   {
      br  =   new   BufferedReader ( new   InputStreamReader ( new   FileInputStream ( ACCOUNT_FILE ),   "UTF-8" ));

       String  strAccountNum  =   Integer . toString ( accountNum );

       while   ( strAccountNum . compareTo ( br . readLine ()   )   !=   0 )   {}

      balance  =   Float . parseFloat ( br . readLine ());
        
     }   catch   ( IOException  e )   {
       System . out . println ( "File could not be read/found." );
     }   finally   {
       return   ( balance );
     }
   }
}

BA Uncompressed/src/main/java/swsec/bank/services/repositories/AccountRepository.class