// BankBetter.java Copyright (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2004-10-03 File created. // 2005-02-05 Last modification. /* In the javafiles3 folder, there are three .java files which contain a class named BankAccount. These files are BankSimple.java, BankBetter.java, and BankVirtuals.java. Because the BankAccount class is not the same class in BankSimple.java as in BankBetter.java and BankVirtuals.java, it is possible that you encounter problems when you compile and run these programs. Therefore, I would like to advise that, before you attempt to run any of the mentioned programs, you compile the program before running it. One possible problem that can occur is that program BankSimple.java cannot be run after BankBetter.java has been compiled. The reason for this is that the compilation of BankBetter.java (or BankVirtuals.java) replaces the BankAccount.class file produced by the compilation of BankSimple.java with a different BankAccount.class file. */ class BankAccount { String account_owner ; long account_number ; double account_balance ; public BankAccount( String given_account_owner, long given_account_number, double initial_balance ) { account_owner = given_account_owner ; account_number = given_account_number ; account_balance = initial_balance ; } public void show_account_data() { System.out.print( "\n\nB A N K A C C O U N T D A T A : " + "\n Account owner : " + account_owner + "\n Account number: " + account_number + "\n Current balance: " + account_balance ) ; } public void deposit_money( double amount_to_deposit ) { System.out.print( "\n\nTRANSACTION FOR ACCOUNT OF " + account_owner + " (Account number " + account_number + ")" ) ; System.out.print( "\n Amount deposited: " + amount_to_deposit + "\n Old account balance: " + account_balance ) ; account_balance = account_balance + amount_to_deposit ; System.out.print( " New balance: " + account_balance ) ; } public void withdraw_money( double amount_to_withdraw ) { System.out.print( "\n\nTRANSACTION FOR ACCOUNT OF " + account_owner + " (Account number " + account_number + ")" ) ; if ( account_balance < amount_to_withdraw ) { System.out.print("\n -- Transaction not completed: " + "Not enough money to withdraw " + amount_to_withdraw ) ; } else { System.out.print("\n Amount withdrawn: " + amount_to_withdraw + "\n Old account balance: " + account_balance ) ; account_balance = account_balance - amount_to_withdraw ; System.out.print(" New balance: " + account_balance ) ; } } public void transfer_money_to( BankAccount receiving_account, double amount_to_transfer ) { System.out.print( "\n\nTRANSACTION FOR ACCOUNT OF " + account_owner + " (Account number " + account_number + ")" ) ; if ( account_balance >= amount_to_transfer ) { receiving_account.account_balance = receiving_account.account_balance + amount_to_transfer ; System.out.print( "\n " + amount_to_transfer + " was transferred to " + receiving_account.account_owner + " (Account no. " + receiving_account.account_number + ")." + "\n Balance before transfer: " + account_balance ) ; account_balance = account_balance - amount_to_transfer ; System.out.print( " New balance: " + account_balance ) ; } else { System.out.print( "\n -- Not enough money for transfer." ) ; } } } class BankBetter { public static void main( String[] not_in_use ) { BankAccount jazz_player_account = new BankAccount( "Louis Armstrong", 121212, 0 ) ; BankAccount moon_walker_account = new BankAccount( "Neil Armstrong", 191919, 7777.77 ) ; jazz_player_account.deposit_money( 3333.33 ) ; jazz_player_account.withdraw_money( 4444.44 ) ; moon_walker_account.transfer_money_to( jazz_player_account, 2222.22 ) ; moon_walker_account.show_account_data() ; jazz_player_account.show_account_data() ; } }