java programmer only

profileSaMsRa@1
SP2019_PROJECT_Bhusal.zip

SinglyLinkedListPseudoCode.txt

CLASS SinglyLinkedList: set linkedList as Node FUNCTION getLinkedList() return linkedList END FUNCTION FUNCTION add(object) found = find(object) IF found create newNode object using object IF linkList is null set linkedList as newNode ELSE set rear as linkedList WHILE rear is not null IF rear.next is null breaK END IF set rear as rear.next END WHILE rear.next = newNode ELSE END IF return true END IF return false END FUNCTION FUNCTION find(object) IF linkedlist is null return false set iterable as linkedList IF iterable.data is equal to object create newNode object newNode.next = linkedList.nex set linkedList as newNode return true END IF WHILE iterable is not null IF iterable.next is not null IF iterable.next is equal to object set target as iterable.next create newNode object newNode.next = target.next iterable.next = newNode dispose target END IF END IF set iterable as iterable.next END WHILE return false END FUNCTION FUNCTION delete(object) IF linkedlist is null return false set iterable as linkedList IF iterable.data is equal to object set linkedList as iterable.next return true END IF WHILE iterable is not null IF iterable.next is not null IF iterable.next is equal to object set target as iterable.next iterable.next = target.next dispose target END IF END IF set iterable as iterable.next END WHILE return false END FUNCTION FUNCTION traverse() set iterable as linkedList WHILE iterable is not null PRINT(iterable.data) set iterable as iterable.next END WHILE END FUNCTION

Account_Bhusal.java

Account_Bhusal.java

/**
 *  @author  Deepak Bhusal
 * Assignment SP2019_PROJECT
 * Account_Bhusal class represents a bank account for a user and harbours
 * necessary methods for deposit, withdrawal and balance checking. This class is abstract in nature
 * and contain abstract methods that are implemented by child classes
 */
public   abstract   class   Account_Bhusal   {
     protected   String  accountNumber ;
     protected   float  balance ;

     /**
     * Default constructor
     */
     public   Account_Bhusal ()   {
         this . accountNumber = "" ;
         this . balance = 0 ;
     }

     /**
     *  @param  accountNumber
     *  @param  balance
     * Constructor with parameters
     */
     public   Account_Bhusal ( String  accountNumber ,   float  balance )   {
         this . accountNumber  =  accountNumber ;
         this . balance  =  balance ;
     }

     /**
     *  @return
     */
     public   String  getAccountNumber ()   {
         return  accountNumber ;
     }

     /**
     *  @param  accountNumber
     */
     public   void  setAccountNumber ( String  accountNumber )   {
         this . accountNumber  =  accountNumber ;
     }

     /**
     *  @return
     */
     public   float  getBalance ()   {
         return  balance ;
     }

     /**
     *  @param  balance
     */
     public   void  setBalance ( float  balance )   {
         this . balance  =  balance ;
     }

     /**
     *  @param  accountNumber
     *  @param  balance
     * A method to open a new bank account
     */
     public   void  openAccount ( String  accountNumber ,   float  balance ){
         this . accountNumber  =  accountNumber ;
         this . balance  =  balance ;
     }

     /**
     *  @param  amount
     * An abstract method for depositing money into an account
     */
     public   abstract   void  deposit ( float  amount );

     /**
     *  @param  amount
     * An abstract method for withdrawing money from an account
     */
     public   abstract   void  withdraw ( float  amount );

     /**
     * A method to check for balances in an account
     */
     public   void  checkBalance (){
         System . out . println ( "Account Number: "   +   this . accountNumber );
         System . out . println ( "Current Account Balance: "   +   String . valueOf ( this . balance ));
     }

     /**
     * An abstract method to retrieve monthly statements from and account
     */
     public   abstract   void  monthlyStatements ();

     /**
     * Clone the base object
     *  @return
     */
     public   abstract   Account_Bhusal  copy ();

     /**
     *  @return
     */
    @ Override
     public   String  toString ()   {
         return   "Account_Bhusal{"   +
                 "accountNumber='"   +  accountNumber  +   '\''   +
                 ", balance="   +  balance  +
                 '}' ;
     }

}

BankCustomer_Bhusal.java

BankCustomer_Bhusal.java

import  java . io . BufferedWriter ;
import  java . io . FileWriter ;
import  java . io . IOException ;
import  java . util . ArrayList ;
import  java . util . List ;

/**
 *  @author  Deepak Bhusal
 * Assignment SP2019_PROJECT
 * BankCustomer_Bhusal class represents a bank customer
 */
public   class   BankCustomer_Bhusal   implements   Comparable   {
     private   String  id ;
     private   String  firstName ;
     private   String  lastName ;
     private   String  address ;
     private   String  userName ;
     private   String  password ;
     public   List < Account_Bhusal >  account_bhusalList  =   new   ArrayList <> ();

     /**
     * Constructor
     *  @param  id
     *  @param  firstName
     *  @param  lastName
     *  @param  address
     *  @param  userName
     *  @param  password
     */
     public   BankCustomer_Bhusal ( String  id ,   String  firstName ,   String  lastName ,   String  address ,   String  userName ,   String  password )   {
         this . id  =  id ;
         this . firstName  =  firstName ;
         this . lastName  =  lastName ;
         this . address  =  address ;
         this . userName  =  userName ;
         this . password  =  password ;
     }

     /**
     * Empty constructor
     */
     public   BankCustomer_Bhusal ()   {
     }

     /**
     * id accessor
     *  @return
     */
     public   String  getId ()   {
         return  id ;
     }

     /**
     * id mutator
     *  @param  id
     */
     public   void  setId ( String  id )   {
         this . id  =  id ;
     }

     /**
     * first name accessor
     *  @return
     */
     public   String  getFirstName ()   {
         return  firstName ;
     }

     /**
     * first name mutator
     *  @param  firstName
     */
     public   void  setFirstName ( String  firstName )   {
         this . firstName  =  firstName ;
     }

     /**
     * last name accessor
     *  @return
     */
     public   String  getLastName ()   {
         return  lastName ;
     }

     /**
     * last name mutator
     *  @param  lastName
     */
     public   void  setLastName ( String  lastName )   {
         this . lastName  =  lastName ;
     }

     /**
     * address accessor
     *  @return
     */
     public   String  getAddress ()   {
         return  address ;
     }

     /**
     * address mutator
     *  @param  address
     */
     public   void  setAddress ( String  address )   {
         this . address  =  address ;
     }

     /**
     * username accessor
     *  @return
     */
     public   String  getUserName ()   {
         return  userName ;
     }

     /**
     * username mutator
     *  @param  userName
     */
     public   void  setUserName ( String  userName )   {
         this . userName  =  userName ;
     }

     /**
     * password accessor
     *  @return
     */
     public   String  getPassword ()   {
         return  password ;
     }

     /**
     * password mutator
     *  @param  password
     */
     public   void  setPassword ( String  password )   {
         this . password  =  password ;
     }

     /**
     * a method to create a deepcopy of the underlying object
     *  @return
     */
     public   BankCustomer_Bhusal  deepCopy (){
         return   new   BankCustomer_Bhusal ( this . id , this . firstName , this . lastName , this . address , this . userName , this . password );
     }

     /**
     * A method to write object information to a file
     *  @param  fileName
     */
     public   void  writeToFile ( String  fileName ){
         try   {
             BufferedWriter  bufferedWriter  =   new   BufferedWriter ( new   FileWriter ( fileName ));
            bufferedWriter . write ( id + "," + firstName + "," + lastName + "," + userName + "," + password + "," + address );
            bufferedWriter . close ();
         }   catch   ( IOException  e )   {
            e . printStackTrace ();
         }
     }

     public   boolean  openOneAccount ( Account_Bhusal  account_bhusal ){
         if ( ! this . account_bhusalList . contains ( account_bhusal )){
             this . account_bhusalList . add ( account_bhusal );
             return   true ;
         }
         return   false ;
     }

     public   boolean  closeOneAccount ( Account_Bhusal  account_bhusal ){
         if ( this . account_bhusalList . contains ( account_bhusal )){
             this . account_bhusalList . remove ( account_bhusal );
             return   true ;
         }
         return   false ;
     }

     /**
     * toString method
     *  @return
     */
    @ Override
     public   String  toString ()   {
         StringBuilder  stringBuilder  =   new   StringBuilder ();
        stringBuilder . append ( String . format ( "%s%35s\n" , "Customer ID:" , id ));
        stringBuilder . append ( String . format ( "%s%36s\n" , "First Name:" , firstName ));
        stringBuilder . append ( String . format ( "%s%37s\n" , "Last name:" , lastName ));
        stringBuilder . append ( String . format ( "%s%39s\n" , "Address:" , address ));
        stringBuilder . append ( String . format ( "%s%38s\n" , "Username:" , userName ));
         return  stringBuilder . toString ();
     }

     /**
     * A method comparing one object to the other based on id
     *  @param  o
     *  @return
     */
    @ Override
     public   int  compareTo ( Object  o )   {
         BankCustomer_Bhusal  bankCustomer_bhusal  =   ( BankCustomer_Bhusal )  o ;
         return   this . id . compareTo ( bankCustomer_bhusal . getId ());
     }

     /**
     * A method that return the object hashcode
     *  @return
     */
     public   int  hashCode (){
         char []  chars  =   this . id . toCharArray ();
         int  sum = 0 ;
         for ( char  c :  chars ){
            sum += ( int ) c ;
         }
         return  sum % 19 ;
     }
}

BankService_Bhusal.java

BankService_Bhusal.java

import  javax . swing . * ;
import  java . io . * ;
import  java . util . * ;
/**
 *  @author  Deepak Bhusal
 * Assignment SP2019_PROJECT
 * BankService_Bhusal class representing the driver class
 *
 */
public   class   BankService_Bhusal   {
     private   static   SinglyLinkedList  customers  =   new   SinglyLinkedList ();
     private   static   LinkedList < String >  linkedList  =   new   LinkedList <> ();
     private   static   BankCustomer_Bhusal  currentCustomer ;
     private   static   Random  random  =   new   Random ();
     private   static   Scanner  scanner  =   new   Scanner ( System . in );
     private   static   final   String  INPUT_FILE  =   "input/bankCustomer.csv" ;
     private   static   final   String  OUTPUT_FILE  =   "input/bankCustomerout.csv" ;

     /**
     *  @param  args
     */
     public   static   void  main ( String []  args ){
         //read file first
        readCustomersFile ();
        customers . traverse ();
        printLine ( "\n" );
         while   ( true )   {
            showInitialMenu ();
             int  choice  =   Integer . parseInt ( scanner . nextLine ());
             if   ( choice  ==   0 )   {
                writeFileandExit ();
             }   else   if   ( choice  ==   1 )   {
                handleBankEmployeeTasks ();
             } else   if ( choice == 2 ){
                handleBankCustomerTasks ();
             } else {
                printLine ( "Invalid choice" );
             }
         }
     }
     /**
     * A method to show the initial menu
     */
     private   static   void  showInitialMenu ()   {
        printLine ( "COSC2436 FA2018 BANK SERVICE APPLICATION" );
        printLine ( "1. Bank Employee " );
        printLine ( "2. Bank Customer " );
        printLine ( "0. Exit " );
     }

     /**
     * A method to show one submenu
     */
     private   static   void  showOption1Menu ()   {
        printLine ( "TASKS FOR BANK EMPLOYEE" );
        printLine ( "1. Add a new Customer-Open a new account " );
        printLine ( "2. Display a customer with all accounts " );
        printLine ( "3. Open new account for current customer " );
        printLine ( "4. Read one account for one customer " );
        printLine ( "5. Remove one account of current customer " );
        printLine ( "6. Display all customers with their accounts" );
        printLine ( "7. Process monthly statements " );
        printLine ( "0. DONE " );
     }

     /**
     * A method to show one submenu
     */
     private   static   void  showOption2Menu ()   {
        printLine ( "TASKS FOR BANK CUSTOMERS" );
        printLine ( "1. Print information of customer " );
        printLine ( "2. Check Balance " );
        printLine ( "3. Deposit " );
        printLine ( "4. Withdraw " );
        printLine ( "5. Print monthly statement " );
        printLine ( "0. DONE " );
     }

     /**
     * A method to handle employee tasks
     */
     private   static   void  handleBankEmployeeTasks (){
         boolean  run =   true ;
         do {
            showOption1Menu ();
             int  choice  =   Integer . parseInt ( scanner . nextLine ());
             switch   ( choice ){
                 case   1 :
                     BankCustomer_Bhusal  bankCustomer_bhusal  =  createCustomer ();
                     if ( customers . add ( bankCustomer_bhusal )){
                        showMessageBox ( "Customer successfully added" );
                     } else {
                        showMessageBox ( "Customer not added" );
                     }
                     break ;
                 case   2 :
                    findCustomerWithAllAccounts ();
                     break ;
                 case   3 :
                    addAccountToCustomer ();
                     break ;
                 case   4 :
                    readOneAccountCustomer ();
                     break ;
                 case   5 :
                    removeOneAccountFromCustomer ();
                     break ;
                 case   6 :
                    displayCustomerswiththeirAccounts ();
                     break ;
                 case   7 :
                    processMonthlyStatements ();
                     break ;
                 case   0 :
                    run = false ;
                     break ;
             }
         } while ( run );
     }

     /**
     * A method to handle customer tasks
     */
     private   static   void  handleBankCustomerTasks (){
         boolean  run  =   true ;
        introduceCustomer ();
         do {
            showOption2Menu ();
             int  choice  =   Integer . parseInt ( scanner . nextLine ());
             switch   ( choice )   {
                 case   1 :
                    showCustomerInfo ();
                     break ;
                 case   2 :
                    checkBalance ();
                     break ;
                 case   3 :
                    deposit ();
                     break ;
                 case   4 :
                    withdraw ();
                     break ;
                 case   5 :
                    printMonthlyStatement ();
                     break ;
                 case   0 :
                    run = false ;
                     break ;
             }
         } while ( run );
     }

     /**
     * A method to read customer data from files
     */
     private   static   void  readCustomersFile (){
         try   {
             BufferedReader  bufferedReader  =   new   BufferedReader ( new   FileReader ( INPUT_FILE ));
             String  line  =   "" ;
             while   (( line = bufferedReader . readLine ()) != null ){
                 String []  items  =  line . trim (). split ( "," );
                 String  id  =  items [ 0 ];
                 String  firstName  =  items [ 1 ];
                 String  lastName  =  items [ 2 ];
                 String  username  =  items [ 3 ];
                 String  password  =  items [ 4 ];
                 String  address  =  items [ 5 ];
                 BankCustomer_Bhusal  bankCustomer_bhusal  =   new   BankCustomer_Bhusal ( id , firstName , lastName , address , username , password );
                 String  accountNumber1  =  items [ 6 ];
                 float  balance1  =   Float . parseFloat ( items [ 7 ]);
                 float  limit1  =   Float . parseFloat ( items [ 8 ]);
                linkedList . add ( accountNumber1 );
                 if ( Double . parseDouble ( items [ 9 ])   <   1 ){
                     //saving account
                     float  srIr  =   Float . parseFloat ( items [ 9 ]);
                     Account_Bhusal  account_bhusal  =   new   SavingAccount_Bhusal ( srIr , limit1 );
                    account_bhusal . openAccount ( accountNumber1 , balance1 );
                    bankCustomer_bhusal . account_bhusalList . add ( account_bhusal );
                 } else {
                     float  srIr  =   Float . parseFloat ( items [ 9 ]);
                     Account_Bhusal  account_bhusal  =   new   CheckingAccount_Bhusal ( srIr , limit1 );
                    account_bhusal . openAccount ( accountNumber1 , balance1 );
                    bankCustomer_bhusal . account_bhusalList . add ( account_bhusal );
                 }


                 if ( items . length == 14 ){
                     String  accountNumber2  =  items [ 10 ];
                     float  balance2  =   Float . parseFloat ( items [ 11 ]);
                     float  limit2 =   Float . parseFloat ( items [ 12 ]);
                    linkedList . add ( accountNumber2 );
                     if ( Double . parseDouble ( items [ 13 ])   <   1 ){
                         float  srIr2  =   Float . parseFloat ( items [ 9 ]);
                         Account_Bhusal  account_bhusal2  =   new   SavingAccount_Bhusal ( srIr2 , limit2 );
                        account_bhusal2 . openAccount ( accountNumber2 , balance2 );
                        bankCustomer_bhusal . account_bhusalList . add ( account_bhusal2 );
                     } else {
                         float  srIr2  =   Float . parseFloat ( items [ 9 ]);
                         Account_Bhusal  account_bhusal2  =   new   CheckingAccount_Bhusal ( srIr2 , limit2 );
                        account_bhusal2 . openAccount ( accountNumber1 , balance1 );
                        bankCustomer_bhusal . account_bhusalList . add ( account_bhusal2 );
                     }
                 }
                 //printLine("This customer has "+bankCustomer_bhusal.account_bhusalList.size()+" accounts");
                customers . add ( bankCustomer_bhusal );
             }
            bufferedReader . close ();

         }   catch   ( IOException  e )   {
            e . printStackTrace ();
         }
     }

     /**
     * A method to write bank customers to file
     */
     private   static   void  writeFileandExit (){
         try   {
             BufferedWriter  bufferedWriter  =   new   BufferedWriter ( new   FileWriter ( OUTPUT_FILE ));
             Node  current  =  customers . getLinkedList ();
             while   ( current != null ){
                 StringBuilder  stringBuilder  =    new   StringBuilder ();
                 BankCustomer_Bhusal  bankCustomer_bhusal  =  current . getData ();
                stringBuilder . append ( bankCustomer_bhusal . getId ()). append ( "," );
                stringBuilder . append ( bankCustomer_bhusal . getFirstName ()). append ( "," );
                stringBuilder . append ( bankCustomer_bhusal . getLastName ()). append ( "," );
                stringBuilder . append ( bankCustomer_bhusal . getAddress ()). append ( "," );
                stringBuilder . append ( bankCustomer_bhusal . getUserName ()). append ( "," );
                stringBuilder . append ( bankCustomer_bhusal . getPassword ()). append ( "," );

                 for ( Account_Bhusal  account_bhusal : bankCustomer_bhusal . account_bhusalList ){
                     if ( account_bhusal  instanceof   CheckingAccount_Bhusal ){
                         CheckingAccount_Bhusal  obj  =   ( CheckingAccount_Bhusal ) account_bhusal ;
                        stringBuilder . append ( obj . getAccountNumber ()). append ( "," );
                        stringBuilder . append ( obj . getBalance ()). append ( "," );
                        stringBuilder . append ( obj . getLimitAmount ()). append ( "," );
                        stringBuilder . append ( obj . getServiceFee ()). append ( "," );
                     } else   if ( account_bhusal  instanceof    SavingAccount_Bhusal ){
                         SavingAccount_Bhusal  obj  =   ( SavingAccount_Bhusal ) account_bhusal ;
                        stringBuilder . append ( obj . getAccountNumber ()). append ( "," );
                        stringBuilder . append ( obj . getBalance ()). append ( "," );
                        stringBuilder . append ( obj . getLimitAmount ()). append ( "," );
                        stringBuilder . append ( obj . getInterestRate ()). append ( "," );
                     }
                 }
                bufferedWriter . write ( stringBuilder . toString ());
                bufferedWriter . newLine ();
                
                current  =  current . getNext ();
             }
            bufferedWriter . close ();
             System . exit ( 0 );
         }   catch   ( IOException  e )   {
            e . printStackTrace ();
             System . exit ( 1 );
         }
     }

     /**
     * a method to generate a unique account number
     *  @return
     */
     private   static   String  generateUniqueAccountNumber (){
         String  unique  =   String . valueOf ( random . nextInt ( 899999 ) + 100000 );
         while   ( linkedList . contains ( unique )){
            unique  =   String . valueOf ( random . nextInt ( 899999 ) + 100000 );
         }
        linkedList . add ( unique );
         return  unique ;
     }

     /**
     * a method to create customer from user input
     *  @return
     */
     private   static   BankCustomer_Bhusal  createCustomer (){
        printLine ( "Customer Information" );
        printLine ( "============================" );
        printLine ( "Enter customer id: " );
         String  id  =  scanner . nextLine ();
        printLine ( "Enter first name: " );
         String  firstName  =  scanner . nextLine ();
        printLine ( "Enter last name: " );
         String  lastName  =  scanner . nextLine ();
        printLine ( "Enter username: " );
         String  userName  =  scanner . nextLine ();
        printLine ( "Enter password: " );
         String  password  =  scanner . nextLine ();
        printLine ( "Enter address: " );
         String  address  =  scanner . nextLine ();

         BankCustomer_Bhusal  bankCustomer_bhusal  =   new   BankCustomer_Bhusal ( id , firstName , lastName , address , userName , password );
        printLine ( "\n" );

         Account_Bhusal  account_bhusal  =  createAccount ();
        bankCustomer_bhusal . account_bhusalList . add ( account_bhusal );

         return  bankCustomer_bhusal ;
     }

     /**
     * A method to create an account from user input
     *  @return
     */
     private   static   Account_Bhusal  createAccount (){
        printLine ( "Account Information" );
        printLine ( "============================" );
        printLine ( "Select Account Type:1. Checking Account 2. Savings Account " );
         String  accountType  =  scanner . nextLine ();
        printLine ( "Enter the customer account number: " );
         String  accountNumber  =  generateUniqueAccountNumber ();
        printLine ( "Enter the limit amount" );
         float  limit  =   Float . parseFloat ( scanner . nextLine ());
         float  balance  =   0 ;
         while   ( balance  <  limit )   {
            printLine ( "Enter the customer balance [greater than $" +  limit  + "]: " );
            balance  =   Float . parseFloat ( scanner . nextLine ());
         }
         if   ( accountType . equals ( "1" ))   {
            printLine ( "Please enter the services rate: " );
             float  serviceRate  =   Float . parseFloat ( scanner . nextLine ());
             Account_Bhusal  account_bhusal  =   new   CheckingAccount_Bhusal ( serviceRate , limit );
            account_bhusal . openAccount ( accountNumber ,  balance );
             return  account_bhusal ;
         } else {
            printLine ( "Please enter the interest rate: " );
             float  interestRate  =   Float . parseFloat ( scanner . nextLine ());
             Account_Bhusal  account_bhusal  =   new   SavingAccount_Bhusal ( interestRate , limit );
            account_bhusal . openAccount ( accountNumber ,  balance );
             return  account_bhusal ;
         }
     }

     /**
     * a method to find a customer and print all their accounts
     */
     private   static   void  findCustomerWithAllAccounts (){
        printLine ( "Enter the customer id: " );
         String  id  =  scanner . nextLine ();
         BankCustomer_Bhusal  found  =  customers . find ( id , null , "id" );
         if ( found != null ){
            printCustomerAndAccount ( found , false );
         } else {
            showMessageBox ( "Customer not found" );
         }
     }

     /**
     * a method to add account to customer
     */
     public   static   void  addAccountToCustomer (){
        printLine ( "Enter the customer id: " );
         String  id  =  scanner . nextLine ();
         BankCustomer_Bhusal  found  =  customers . find ( id , null , "id" );
         if ( found != null ){
            Account_Bhusal  account_bhusal  =  createAccount ();
           found . account_bhusalList . add ( account_bhusal );
           showMessageBox ( "Open new Account for Customer with id: " + found . getId () + " SUCCESS" );
         } else {
            showMessageBox ( "Customer not found" );
         }
     }

     /**
     * a method to read single account information
     */
     private   static   void  readOneAccountCustomer (){
         BankCustomer_Bhusal  found  =  customerLoginbyIdorUserPassword ();
         if ( found != null ){
            printCustomerAndAccount ( found , true );
         } else {
            showMessageBox ( "Customer cannot be found" );
         }
     }

     /**
     * A method that return a customer based on id or  username/password
     *  @return
     */
     public   static   BankCustomer_Bhusal  customerLoginbyIdorUserPassword (){
        printLine ( "SELECT LOGIN TYPE " );
        printLine ( "1. Customer Id" );
        printLine ( "2. Username and Password" );
        printLine ( "0. DO NOT CONTINUE" );
         BankCustomer_Bhusal  found  =   null ;
         int  choice  =   Integer . parseInt ( scanner . nextLine ());
         if ( choice == 1 ){
            printLine ( "Enter the customer id: " );
             String  id  =  scanner . nextLine ();
            found  =  customers . find ( id , null , "id" );
         } else   if ( choice == 2 ){
            printLine ( "Enter the customer username: " );
             String  username  =  scanner . nextLine ();
            printLine ( "Enter the customer password: " );
             String  password  =  scanner . nextLine ();
            found  =  customers . find ( username , password , "userpassword" );
         } else   if ( choice == 0 ){
             //do nothing
         }

         return  found ;
     }

     /**
     * Method to print customer with single or multiple accounts
     *  @param  bankCustomer_bhusal
     *  @param  justOne
     */
     private   static   void  printCustomerAndAccount ( BankCustomer_Bhusal  bankCustomer_bhusal , boolean  justOne ){
        printLine ( "Customer Information" );
        printLine ( bankCustomer_bhusal . toString ());
        printLine ( "Customer Accounts" );
         for ( Account_Bhusal  account_bhusal :  bankCustomer_bhusal . account_bhusalList ){
            printLine ( account_bhusal . toString ());
             if ( justOne )   {
                 break ;
             }
         }
     }

     /**
     * a method to remove one account from a customer
     */
     private   static   void  removeOneAccountFromCustomer (){
        printLine ( "Enter the customer id: " );
         String  id  =  scanner . nextLine ();
         BankCustomer_Bhusal  found  =  customers . find ( id , null , "id" );
         if ( found != null ){
            printLine ( "Enter Account Number: " );
             String  accountNumber  =  scanner . nextLine ();
             if ( linkedList . contains ( accountNumber )){
                 if ( found . account_bhusalList . size ()   >   1 ){
                    linkedList . remove ( accountNumber );
                     Account_Bhusal  target = null ;
                     for   ( Account_Bhusal  account : found . account_bhusalList )   {
                         if ( account . getAccountNumber (). equals ( accountNumber )){
                            target = account ;
                             break ;
                         }
                     }
                    found . account_bhusalList . remove ( target );
                 } else {
                    printLine ( "The customer only has one account" );
                    printLine ( "Closing this account will remove the customer from the system" );
                    printLine ( "Do you still want to close account (Y/N)?" );
                     String  input  =  scanner . nextLine (). toUpperCase ();
                     if ( input . equals ( "Y" )){
                        customers . delete ( id );
                        linkedList . remove ( accountNumber );
                     }
                 }
             } else {
                showMessageBox ( "The account number cannot be found" );
             }
         } else {
            showMessageBox ( "Customer with " + id + " cannot be found" );
         }
     }

     /**
     * a method to display all customers and their accounts
     */
     private   static   void  displayCustomerswiththeirAccounts (){
         Node  current  =  customers . getLinkedList ();
         while   ( current != null ){
             List < Account_Bhusal >  accountBhusalArrayList  =  current . getData (). account_bhusalList ;
            printLine ( current . getData (). toString ());
            printLine ( "Customer Account\n" );
             for ( Account_Bhusal  account_bhusal : accountBhusalArrayList )   {
                printLine ( account_bhusal . toString ());
             }
            current  =  current . getNext ();
         }
     }

     /**
     * a method to process monthly statements
     */
     private   static   void  processMonthlyStatements (){
         Node  current  =  customers . getLinkedList ();
         while   ( current != null )   {
             List < Account_Bhusal >  accountBhusalArrayList  =  current . getData (). account_bhusalList ;
             for ( Account_Bhusal  account_bhusal : accountBhusalArrayList )   {
                account_bhusal . monthlyStatements ();
             }
            current  =   current . getNext ();
         }
     }

     /**
     * A method to log in and introduce customer
     */
     private   static   void  introduceCustomer (){
         BankCustomer_Bhusal  found  =  customerLoginbyIdorUserPassword ();
         if ( found != null ){
            printLine ( "YOU ARE:" );
            printLine ( "Customer Name: " + found . getFirstName () + ", " + found . getLastName ());
            printLine ( "Customer Id: " + found . getId ());
            printLine ( "Address: " + found . getAddress ());
            printLine ( "\n" );
            currentCustomer  =  found ;
         } else {
            showMessageBox ( "Customer not found" );
         }
     }

     /**
     *
     */
     private   static   void  showCustomerInfo (){
         BankCustomer_Bhusal  found  =  customers . find ( currentCustomer . getId (), null , "id" );
        printCustomerAndAccount ( found , false );
     }

     /**
     * method that return acccount based occount number
     *  @return
     */
     private   static   Account_Bhusal  getAccount (){
         BankCustomer_Bhusal  found  =  customers . find ( currentCustomer . getId (), null , "id" );
        printLine ( "Enter Account Number: " );
         String  accountNumber  =  scanner . nextLine ();
         for ( Account_Bhusal  account_bhusal : found . account_bhusalList )   {
             if   ( account_bhusal . getAccountNumber (). equals ( accountNumber ))   {
                 return  account_bhusal ;
             }
         }
         return   null ;
     }

     /**
     * method to check balance
     */
     private   static   void  checkBalance (){
         Account_Bhusal  account_bhusal  =  getAccount ();
         if ( account_bhusal != null )   {
            account_bhusal . checkBalance ();
         } else {
            showMessageBox ( "Account not found" );
         }
     }

     /**
     * method to perform deposit on specific account
     */
     private   static   void  deposit (){
         Account_Bhusal  account_bhusal  =  getAccount ();
        printLine ( "Enter the amount to deposit:" );
         float  amount  =   Float . parseFloat ( scanner . nextLine ());
         if ( account_bhusal != null )   {
            account_bhusal . deposit ( amount );
         } else {
            showMessageBox ( "Customer not found" );
         }
     }

     /**
     * method to perform withdrawal on specific account
     */
     private   static   void  withdraw (){
         Account_Bhusal  account_bhusal  =  getAccount ();
        printLine ( "Enter the amount to withdraw:" );
         float  amount  =   Float . parseFloat ( scanner . nextLine ());
         if ( account_bhusal != null )   {
            account_bhusal . withdraw ( amount );
         } else {
            showMessageBox ( "Customer not found" );
         }
     }

     /**
     * Method to print monthly statement for specific account
     */
     private   static   void  printMonthlyStatement (){
         Account_Bhusal  account_bhusal  =  getAccount ();
         if ( account_bhusal != null )   {
            account_bhusal . monthlyStatements ();
         } else {
            showMessageBox ( "Customer not found" );
         }
     }


     /**
     *  @param  object
     */
     public   static   void  printLine ( Object  object ){
         System . out . println ( object );
     }

     /**
     *  @param  message A method to show the swing message box
     */
     public   static   void  showMessageBox ( String  message )   {
         JOptionPane . showMessageDialog ( null ,  message );
     }
}

CheckingAccount_Bhusal.java

CheckingAccount_Bhusal.java

import  java . text . DecimalFormat ;

/**
 *  @author  Deepak Bhusal
 * Assignment SP2019_PROJECT
 * CheckingAccount_Bhusal class extends Account_Bhusal and implements its abstract methods. This
 * class represents a Checking Account.
 */
public   class   CheckingAccount_Bhusal   extends   Account_Bhusal   {
     private   float  serviceFee ;
     private   float  limitAmount ;
     private   static   DecimalFormat  decimalFormat  =   new   DecimalFormat ( "$##.##" );

     /**
     *  @param  serviceFee
     * Constructor
     */
     public   CheckingAccount_Bhusal ( float  serviceFee , float  limitAmount ){
         super ();
         this . serviceFee = serviceFee ;
         this . limitAmount  =  limitAmount ;
     }

     /**
     *  @return
     * ServiceFee accessor
     */
     public   double  getServiceFee ()   {
         return  serviceFee ;
     }

     /**
     *  @param  serviceFee
     * ServiceFee mutator
     */
     public   void  setServiceFee ( float  serviceFee )   {
         this . serviceFee  =  serviceFee ;
     }

     /**
     *  @return
     */
     public   float  getLimitAmount ()   {
         return  limitAmount ;
     }

     /**
     *  @param  limitAmount
     */
     public   void  setLimitAmount ( float  limitAmount )   {
         this . limitAmount  =  limitAmount ;
     }

     /**
     *  @param  amount
     * An implemented method for the deposit procedure
     */
    @ Override
     public   void  deposit ( float  amount )   {
         if ( amount  >   0 ){
             this . balance += amount ;
             System . out . println ( "Account Type: Checking Account" );
             System . out . println ( "Account Number: "   +   this . accountNumber );
             System . out . println ( "Deposit Amount: "   +  amount );
             System . out . println ( "New Balance: "   +   String . valueOf ( this . balance ));
         } else {
             System . out . println ( "You cannot enter a negative quantity" );
         }
     }

     /**
     *  @param  amount
     * An implemented method for the withdraw procedure
     */
    @ Override
     public   void  withdraw ( float  amount )   {
         if ( amount  >   0   &&   this . balance - amount  >=   this . limitAmount )   {
             this . balance  -=  amount ;
             System . out . println ( "Account Type: Checking Account" );
             System . out . println ( "Account Number: "   +   this . accountNumber );
             System . out . println ( "Withdraw Amount: "   +   String . valueOf ( amount ));
             System . out . println ( "New Balance: "   +   String . valueOf ( this . balance ));
         } else {
             System . out . println ( "Account Type: Checking Account" );
             System . out . println ( "Account Number: "   +   this . accountNumber );
             System . out . println ( "Withdraw Amount: "   +   String . valueOf ( amount ) + " - Denied" );
             System . out . println ( "New Balance: "   +   String . valueOf ( this . balance ));
         }
     }

     /**
     * An overrided method for checking balances
     */
    @ Override
     public   void  checkBalance (){
         System . out . println ( "Account Type: Checking Account" );
         super . checkBalance ();
     }

     /**
     * An implemented method for retrieving monthly statements
     */
    @ Override
     public   void  monthlyStatements ()   {
         this . balance -= this . serviceFee ;
         System . out . println ( "Account Type: Checking Account" );
         System . out . println ( "Service Fee: $"   +   String . valueOf ( this . serviceFee ));
         System . out . println ( "Account Number: "   +   this . accountNumber );
         System . out . println ( "New Balance: $"   +   String . valueOf ( this . balance ) + "\n" );
     }

     /**
     *  @return
     * A method to clone the existing object
     */
    @ Override
     public   Account_Bhusal  copy ()   {
        Account_Bhusal  account_bhusal =   new   CheckingAccount_Bhusal ( this . serviceFee , this . limitAmount );
       account_bhusal . openAccount ( this . accountNumber , this . balance );
        return  account_bhusal ;
     }

     /**
     *  @return
     * toString method
     */
    @ Override
     public   String  toString ()   {
         StringBuilder  stringBuilder  =   new   StringBuilder ();
        stringBuilder . append ( String . format ( "%s%34s\n" , "Account Type:" , "Checking Account" ));
        stringBuilder . append ( String . format ( "%s%32s\n" , "Account Number:" , accountNumber ));
        stringBuilder . append ( String . format ( "%s%31s\n" , "Current Balance:" , decimalFormat . format ( balance )));
        stringBuilder . append ( String . format ( "%s%34s\n" , "Limit Amount:" , decimalFormat . format ( limitAmount )));
        stringBuilder . append ( String . format ( "%s%35s\n" , "Service Fee:" , decimalFormat . format ( serviceFee )));

         return  stringBuilder . toString ();
     }
}

Node.java

Node.java

/**
 *  @author  Deepak Bhusal
 * Assignment SP2019_PROJECT
 * This is the node class for the linked list
 */
class   Node {
     private   Node  next ;
     private   BankCustomer_Bhusal  data ;

     /**
     * default constructor
     *  @param  data
     */
     public   Node ( BankCustomer_Bhusal  data )   {
         this . data  =  data ;
         this . next  =   null ;
     }

     /**
     * next accessor
     *  @return
     */
     public   Node  getNext ()   {
         return  next ;
     }

     /**
     * next mutator
     *  @param  next
     */
     public   void  setNext ( Node  next )   {
         this . next  =  next ;
     }

     /**
     * data accessor
     *  @return
     */
     public   BankCustomer_Bhusal  getData ()   {
         return  data ;
     }

     /**
     * data mutator
     *  @param  data
     */
     public   void  setData ( BankCustomer_Bhusal  data )   {
         this . data  =  data ;
     }
}

SavingAccount_Bhusal.java

SavingAccount_Bhusal.java

import  java . text . DecimalFormat ;

/**
 *  @author  Deepak Bhusal
 * Assignment SP2019_PROJECT
 * SavingAccount_Bhusal class extends Account_Bhusal and implements its abstract methods. This
 * class represents a Saving Account.
 */

public   class   SavingAccount_Bhusal   extends   Account_Bhusal   {
     private   float  interestRate ;
     private   float  limitAmount ;
     private   static   DecimalFormat  decimalFormat  =   new   DecimalFormat ( "$##.##" );

     /**
     *  @param  interestRate
     * Constructor
     */
     public   SavingAccount_Bhusal ( float  interestRate , float  limitAmount )   {
         super ();
         this . interestRate  =  interestRate ;
         this . limitAmount  =  limitAmount ;
     }

     /**
     *  @return
     * interest rate accessor
     */
     public   double  getInterestRate ()   {
         return  interestRate ;
     }

     /**
     *  @param  interestRate
     * interest rate mutator
     */
     public   void  setInterestRate ( float  interestRate )   {
         this . interestRate  =  interestRate ;
     }

     /**
     *  @return
     */
     public   float  getLimitAmount ()   {
         return  limitAmount ;
     }

     /**
     *  @param  limitAmount
     */
     public   void  setLimitAmount ( float  limitAmount )   {
         this . limitAmount  =  limitAmount ;
     }

     /**
     *  @param  amount
     * An implemented method for the deposit procedure
     */
    @ Override
     public   void  deposit ( float  amount )   {
         if ( amount  >   0 ){
             this . balance += amount ;
             System . out . println ( "Account Type: Saving Account" );
             System . out . println ( "Account Number: "   +   this . accountNumber );
             System . out . println ( "Deposit Amount: "   +  amount );
             System . out . println ( "New Balance: "   +   String . valueOf ( this . balance ));
         } else {
             System . out . println ( "You cannot enter a negative quantity" );
         }
     }

     /**
     *  @param  amount
     * An implemented method for the withdraw procedure
     */
    @ Override
     public   void  withdraw ( float  amount )   {
         if ( amount  >   0   &&   this . balance - amount  >=   this . limitAmount )   {
             this . balance  -=  amount ;
             System . out . println ( "Account Type: Saving Account" );
             System . out . println ( "Account Number: "   +   this . accountNumber );
             System . out . println ( "Withdraw Amount: "   +   String . valueOf ( amount ));
             System . out . println ( "New Balance: "   +   String . valueOf ( this . balance ));
         } else {
             System . out . println ( "Account Type: Saving Account" );
             System . out . println ( "Account Number: "   +   this . accountNumber );
             System . out . println ( "Withdraw Amount: "   +   String . valueOf ( amount ) + " - Denied" );
             System . out . println ( "New Balance: "   +   String . valueOf ( this . balance ));
         }
     }

     /**
     * An overrided method for checking balances
     */
    @ Override
     public   void  checkBalance (){
         System . out . println ( "Account Type: Saving Account" );
         super . checkBalance ();
     }

     /**
     * An implemented method for retrieving monthly statements
     */
    @ Override
     public   void  monthlyStatements ()   {
         double  interest = this . balance * ( this . interestRate / 100 );
         this . balance += interest ;
         System . out . println ( "Account Type: Saving Account" );
         System . out . println ( "Interest Rate: "   +   String . valueOf ( this . interestRate ) + " %" );
         System . out . println ( "Interest Amount: $"   +   String . valueOf ( interest ));
         System . out . println ( "Account Number: "   +   this . accountNumber );
         System . out . println ( "New Balance: $"   +   String . valueOf ( this . balance ) + "\n" );
     }

     /**
     *  @return
     * A method to clone the existing object
     */
    @ Override
     public   Account_Bhusal  copy ()   {
         Account_Bhusal  account_bhusal  =   new   SavingAccount_Bhusal ( this . interestRate , this . limitAmount );
        account_bhusal . openAccount ( this . accountNumber , this . balance );
         return  account_bhusal ;
     }

     /**
     *  @return
     * toString method
     */
    @ Override
     public   String  toString ()   {
         StringBuilder  stringBuilder  =   new   StringBuilder ();
        stringBuilder . append ( String . format ( "%s%34s\n" , "Account Type:" , "Savings Account" ));
        stringBuilder . append ( String . format ( "%s%32s\n" , "Account Number:" , accountNumber ));
        stringBuilder . append ( String . format ( "%s%31s\n" , "Current Balance:" , decimalFormat . format ( balance )));
        stringBuilder . append ( String . format ( "%s%34s\n" , "Limit Amount:" , decimalFormat . format ( limitAmount )));
        stringBuilder . append ( String . format ( "%s%33s" , "Interest Rate:" , interestRate )). append ( "%\n" );
         return  stringBuilder . toString ();
     }
}

SinglyLinkedList.java

SinglyLinkedList.java

/**
 *  @author  Deepak Bhusal
 * Assignment SP2019_PROJECT
 * This is the SinglyLinkedList class
 */
public   class   SinglyLinkedList   {
     private   Node  linkedList ;

     /**
     * linkedlist accessor
     *  @return
     */
     public   Node  getLinkedList ()   {
         return  linkedList ;
     }

     /**
     * A method to add a node to the list
     *  @param  bankCustomer_bhusal
     *  @return
     */
     public   boolean  add ( BankCustomer_Bhusal  bankCustomer_bhusal ){
         BankCustomer_Bhusal  found  =   this . find ( bankCustomer_bhusal . getId (), null , "id" );
         if ( found == null )   {
             if   ( this . linkedList  ==   null )   {
                 this . linkedList  =   new   Node ( bankCustomer_bhusal );
             }   else   {
                 Node  newNode  =   new   Node ( bankCustomer_bhusal );
                 Node  rear  =   this . linkedList ;
                 while   ( rear != null ){
                     if ( rear . getNext () == null ){
                         break ;
                     }
                    rear  =  rear . getNext ();
                 }
                rear . setNext ( newNode );
             }
             return   true ;
         } else {
             return   false ;
         }
     }

     /**
     * A method to find a node in the list
     *  @param  key
     *  @return
     */
     public   BankCustomer_Bhusal  find ( String  key , String  key2 , String  findby ){
         BankCustomer_Bhusal  object  =   null ;
         if ( this . linkedList == null )   return   null ;
         Node  iterable  =   this . linkedList ;
         while   ( iterable != null ){
             if ( findby . equals ( "id" ))   {
                 if   ( iterable . getData (). getId (). equals ( key ))   {
                    object  =  iterable . getData ();
                     break ;
                 }
             } else {
                 if   ( iterable . getData (). getUserName (). equals ( key )   &&  iterable . getData (). getPassword (). equals ( key2 ))   {
                    object  =  iterable . getData ();
                     break ;
                 }
             }
            iterable  =  iterable . getNext ();
         }

         return  object ;
     }

     /**
     * A method to update a node in the list
     *  @param  id
     *  @param  newObject
     *  @return
     */
     public   boolean  update ( String  id ,   BankCustomer_Bhusal  newObject ){
         if ( this . linkedList == null )   return   false ;
         Node  iterable  =   this . linkedList ;
         if ( iterable . getData (). getId (). equals ( id )){
             Node  newNode  =   new   Node ( newObject );
            newNode . setNext ( this . linkedList . getNext ());
             this . linkedList  =  newNode ;
             return   true ;
         }
         while   ( iterable != null )   {
             if   ( iterable . getNext ()   !=   null )   {
                 if   ( iterable . getNext (). getData (). getId (). equals ( id ))   {
                     Node  target  =  iterable . getNext ();
                     Node  newNode  =   new   Node ( newObject );
                    newNode . setNext ( target . getNext ());
                    iterable . setNext ( newNode );
                    target  =   null ;
                     return   true ;
                 }
             }
            iterable  =  iterable . getNext ();
         }

         return   false ;
     }

     /**
     * A method to delete a node from the list
     *  @param  id
     *  @return
     */
     public   boolean  delete ( String  id ){
         if ( this . linkedList == null )   return   false ;
         Node  iterable  =   this . linkedList ;
         //check if item is on top of list
         if ( iterable . getData (). getId (). equals ( id )){
             this . linkedList  =  iterable . getNext ();
             return   true ;
         }
         while   ( iterable != null ){
             if ( iterable . getNext () != null ){
                 if ( iterable . getNext (). getData (). getId (). equals ( id )){
                     Node  deletable  =  iterable . getNext ();
                    iterable . setNext ( deletable . getNext ());
                    deletable  =   null ;
                     return   true ;
                 }
             }
            iterable = iterable . getNext ();
         }

         return   false ;
     }

     /**
     * A method to traverse through the list
     */
     public   void  traverse (){
         Node  iterable  =   this . linkedList ;
         while   ( iterable != null ){
             System . out . println ( iterable . getData (). toString ());;
            iterable  =  iterable . getNext ();
         }
     }
}

Account_Bhusal.class

BankCustomer_Bhusal.class

BankService_Bhusal.class

CheckingAccount_Bhusal.class

Node.class

SavingAccount_Bhusal.class

SinglyLinkedList.class

SP2019_PROJECT_UML.dia

SP2019_PROJECT_UML.dia

#A4# #Account_Bhusal# ## ## #accountNumber# #String# ## ## #customerName# #String# ## ## #balance# #double# ## ## #address# #String# ## ## #Account_Bhusal# ## ## ## #Account_Bhusal# ## ## ## #accountNumber# #String# ## ## #customerName# #String# ## ## #balance# #double# ## ## #address# #String# ## ## #openAccount# ## #void# ## #accountNumber# #String# ## ## #customerName# #String# ## ## #balance# #double# ## ## #address# #String# ## ## #deposit# ## #void# ## #amount# #double# ## ## #withdraw# ## #void# ## #amount# #double# ## ## #checkBalance# ## #void# ## #monthlyStatements# ## #void# ## #copy# ## #Account_Bhusal# ## #toString# ## #String# ## #CheckingAccount_Bhusal# ## ## #serviceFee# #float# ## ## #limitAmount# #float# ## ## #CheckingAccount_Bhusal# ## ## ## #serviceFee# #float# ## ## #limitAmount# #float# ## ## #deposit# ## #void# ## #amount# #float# ## ## #withdraw# ## #void# ## #amount# #float# ## ## #checkBalance# ## #void# ## #monthlyStatements# ## #void# ## #SavingAccount_Bhusal# ## ## #interestRate# #Double# ## ## #limitAmount# #float# ## ## #SavingAccount_Bhusal# ## ## ## #interestRate# #float# ## ## #limitAmount# #float# ## ## #deposit# ## #void# ## #amount# #float# ## ## #withdraw# ## #double# ## #amount# #float# ## ## #checkBalance# ## #void# ## #monthlyStatements# ## #void# ## ## ## ## ## #BankCustomer_Bhusal# ## ## #id# #String# ## ## #firstName# #String# ## ## #lastName# #double# ## ## #username# #String# ## ## #password# #String# ## ## #address# #String# ## ## #account_bhusalList# #List<Account_Bhusal># ## ## #BankCustomer_Bhusal# ## ## ## #BankCustomer_Bhusal# ## ## ## #id# #String# ## ## #firstName# #String# ## ## #lastName# #double# ## ## #username# #String# ## ## #password# #String# ## ## #address# #String# ## ## #openOneAccount# ## #boolean# ## #accountNumber# #Account_Bhusal# ## ## #clostOneAccount# ## #boolean# ## #account_bhusal# #Account_Bhusal# ## ## #deepCopy# ## #BankCustomer_Bhusal# ## #writeToFile# ## #void# ## #toString# ## #String# ## #compareTo# ## #int# ## #object# #Object# ## ## #hashCode# ## #int# ## #toString# ## #String# ## ## ## ## ## ##