-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiff5.txt
More file actions
886 lines (850 loc) · 32 KB
/
Copy pathdiff5.txt
File metadata and controls
886 lines (850 loc) · 32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
diff --git a/ATMsource/ATM.java b/ATMsource/ATM.java
index 17143c4..11c542e 100644
--- a/ATMsource/ATM.java
+++ b/ATMsource/ATM.java
@@ -3,159 +3,247 @@
public class ATM
{
- private boolean userAuthenticated; // whether user is authenticated
- private int currentAccountNumber; // current user's account number
- private Screen screen; // ATM's screen
- private Keypad keypad; // ATM's keypad
- private CashDispenser cashDispenser; // ATM's cash dispenser
- //private DepositSlot depositSlot; // ATM's deposit slot
- private BankDatabase bankDatabase; // account information database
-
- // constants corresponding to main menu options
- private static final int BALANCE_INQUIRY = 1;
- private static final int WITHDRAWAL = 2;
- // private static final int DEPOSIT = 3;
-
- // added new main menu option
- private static final int TRANSFER = 3;
- // changed to last option 5
- private static final int EXIT = 4;
+ private boolean userAuthenticated; // whether user is authenticated
+ private int currentAccountNumber; // current user's account number
+ private Screen screen; // ATM's screen
+ private Keypad keypad; // ATM's keypad
+ private CashDispenser cashDispenser; // ATM's cash dispenser
+ //private DepositSlot depositSlot; // ATM's deposit slot
+ private BankDatabase bankDatabase; // account information database
+
+ // constants corresponding to main menu options
+ private static final int BALANCE_INQUIRY = 1;
+ private static final int WITHDRAWAL = 2;
+ // private static final int DEPOSIT = 3;
+
+ // added new main menu option
+ private static final int TRANSFER = 3;
+
+ // fourth option of different account types are,
+ // saving account: set compund frequency
+ // chequing account: set cheque limit
+ // general accout: exit
+ private static final int FORTH_OPTION = 4;
+
+ // exit option for cheque and saving account
+ private static final int EXIT = 5;
-
+ // used as switch option
+ private final String GENERALTYPE = "General account";
+ private final String SAVINGTYPE = "Saving account";
+ private final String CHEQUEINGTYPE = "Cheque account";
// no-argument ATM constructor initializes instance variables
- public ATM()
- {
- userAuthenticated = false; // user is not authenticated to start
- currentAccountNumber = 0; // no current account number to start
- screen = new Screen(); // create screen
- keypad = new Keypad(); // create keypad
- cashDispenser = new CashDispenser(); // create cash dispenser
- //depositSlot = new DepositSlot(); // create deposit slot
- bankDatabase = new BankDatabase(); // create acct info database
- } // end no-argument ATM constructor
-
- // start ATM
- public void run()
- {
- // welcome and authenticate user; perform transactions
- while ( true )
- {
- // loop while user is not yet authenticated
- while ( !userAuthenticated )
- {
- screen.displayMessageLine( "\nWelcome!" );
- authenticateUser(); // authenticate user
- } // end while
+ public ATM()
+ {
+ userAuthenticated = false; // user is not authenticated to start
+ currentAccountNumber = 0; // no current account number to start
+ screen = new Screen(); // create screen
+ keypad = new Keypad(); // create keypad
+ cashDispenser = new CashDispenser(); // create cash dispenser
+ //depositSlot = new DepositSlot(); // create deposit slot
+ bankDatabase = new BankDatabase(); // create acct info database
+ } // end no-argument ATM constructor
+
+ // start ATM
+ public void run()
+ {
+ // welcome and authenticate user; perform transactions
+ while ( true )
+ {
+ // loop while user is not yet authenticated
+ while ( !userAuthenticated )
+ {
+ screen.displayMessageLine( "\nWelcome!" );
+ authenticateUser(); // authenticate user
+ } // end while
- performTransactions(); // user is now authenticated
- userAuthenticated = false; // reset before next ATM session
- currentAccountNumber = 0; // reset before next ATM session
- screen.displayMessageLine( "\nThank you! Goodbye!" );
- } // end while
- } // end method run
-
- // attempts to authenticate user against database
- private void authenticateUser()
- {
- screen.displayMessage( "\nPlease enter your account number: " );
- int accountNumber = keypad.getInput(); // input account number
- screen.displayMessage( "\nEnter your PIN: " ); // prompt for PIN
- int pin = keypad.getInput(); // input PIN
-
- // set userAuthenticated to boolean value returned by database
- userAuthenticated =
- bankDatabase.authenticateUser( accountNumber, pin );
-
- // check whether authentication succeeded
- if ( userAuthenticated )
- {
- currentAccountNumber = accountNumber; // save user's account #
- } // end if
- else
- screen.displayMessageLine(
- "Invalid account number or PIN. Please try again." );
- } // end method authenticateUser
-
- // display the main menu and perform transactions
- private void performTransactions()
- {
- // local variable to store transaction currently being processed
- Transaction currentTransaction = null;
+ performTransactions(); // user is now authenticated
+ userAuthenticated = false; // reset before next ATM session
+ currentAccountNumber = 0; // reset before next ATM session
+ screen.displayMessageLine( "\nThank you! Goodbye!" );
+ } // end while
+ } // end method run
+
+ // attempts to authenticate user against database
+ private void authenticateUser()
+ {
+ screen.displayMessage( "\nPlease enter your account number: " );
+ int accountNumber = keypad.getInput(); // input account number
+ screen.displayMessage( "\nEnter your PIN: " ); // prompt for PIN
+ int pin = keypad.getInput(); // input PIN
+
+ // set userAuthenticated to boolean value returned by database
+ userAuthenticated =
+ bankDatabase.authenticateUser( accountNumber, pin );
+
+ // check whether authentication succeeded
+ if ( userAuthenticated )
+ {
+ currentAccountNumber = accountNumber; // save user's account #
+ } // end if
+ else
+ screen.displayMessageLine(
+ "Invalid account number or PIN. Please try again." );
+ } // end method authenticateUser
+
+ private boolean transactions(int mainMenuSelection, String ACtype) {
+
+ Transaction currentTransaction = null;
+
+ boolean exitSignal = false;
+
+ while (!exitSignal ) {
+
+ switch ( mainMenuSelection )
+ {
+ // user chose to perform one of three transaction types
+ case BALANCE_INQUIRY:
+ case WITHDRAWAL:
+ //case DEPOSIT:
+ case TRANSFER:
+ case FORTH_OPTION:
+
+ // initialize as new object of chosen type
+ currentTransaction =
+ createTransaction( mainMenuSelection, ACtype );
+
+ if (currentTransaction != null) {
+ currentTransaction.execute(); // execute transaction when is not exit signal of general account
+ }
+ return exitSignal;
+ //break;
+ case EXIT: // user chose to terminate session
+ screen.displayMessageLine( "\nExiting the system..." );
+ exitSignal = true; // this ATM session should end
+ return exitSignal;
+
+ //break;
+ default: // user did not enter an integer from 1-4
+ screen.displayMessageLine(
+ "\nYou did not enter a valid selection. Try again." );
+ return exitSignal;
+ //break;
+ } // end switch
+ }
+ return exitSignal;
+ }
+
+ // display the main menu and perform transactions
+ private void performTransactions(){
+
+ // Transaction currentTransaction = null;
- boolean userExited = false; // user has not chosen to exit
-
- // loop while user has not chosen option to exit system
- while ( !userExited )
- {
- // show main menu and get user selection
- int mainMenuSelection = displayMainMenu();
-
- // decide how to proceed based on user's menu selection
- switch ( mainMenuSelection )
- {
- // user chose to perform one of three transaction types
- case BALANCE_INQUIRY:
- case WITHDRAWAL:
- //case DEPOSIT:
- case TRANSFER:
-
- // initialize as new object of chosen type
- currentTransaction =
- createTransaction( mainMenuSelection );
-
- currentTransaction.execute(); // execute transaction
- break;
- case EXIT: // user chose to terminate session
- screen.displayMessageLine( "\nExiting the system..." );
- userExited = true; // this ATM session should end
- break;
- default: // user did not enter an integer from 1-4
- screen.displayMessageLine(
- "\nYou did not enter a valid selection. Try again." );
- break;
- } // end switch
- } // end while
- } // end method performTransactions
+ boolean userExited = false; // user has not chosen to exit
+
+ //int mainMenuSelection = displayMainMenu();
+
+ String type = bankDatabase.getAccountTypeString(currentAccountNumber);
+
+ while (!userExited) {
+ int mainMenuSelection = displayMainMenu();
+
+ userExited = transactions(mainMenuSelection, type);
+ }
+ }
- // display the main menu and return an input selection
- private int displayMainMenu()
- {
- screen.displayMessageLine( "\nMain menu:" );
- screen.displayMessageLine( "1 - View my balance" );
- screen.displayMessageLine( "2 - Withdraw cash" );
- screen.displayMessageLine( "3 - Transfer funds" );
- screen.displayMessageLine( "4 - Exit\n" );
- screen.displayMessage( "Enter a choice: " );
- return keypad.getInput(); // return user's selection
- } // end method displayMainMenu
+ // display the main menu and return an input selection
+ private int displayMainMenu()
+ {
+ String type = bankDatabase.getAccountTypeString(currentAccountNumber);
+
+ int selection = 0;
+
+ // showing which type of current account
+ screen.displayMessageLine("\nYour account type is: " + type);
+
+ switch (type) {
+ case SAVINGTYPE:
+ displayMainMenuSaving();
+ selection = keypad.getInput();// return user's selection
+ break;
+ case CHEQUEINGTYPE:
+ displayMainMenuCheque();
+ selection = keypad.getInput();// return user's selection
+ break;
+ case GENERALTYPE:
+ displayMainMenuGeneral();
+ selection = keypad.getInput();// return user's selection
+ break;
+ }
+
+ return selection;
+ } // end method displayMainMenu
+
+ // menu for general account
+ private void displayMainMenuGeneral() {
+ screen.displayMessageLine( "\nMain menu:" );
+ screen.displayMessageLine( "1 - View my balance" );
+ screen.displayMessageLine( "2 - Withdraw cash" );
+ screen.displayMessageLine( "3 - Transfer funds" );
+ screen.displayMessageLine( "4 - Exit\n" );
+
+ screen.displayMessageLine("Please enter your choice: ");
+ }
+
+ // menu for saving account
+ private void displayMainMenuSaving() {
+ screen.displayMessageLine( "\nMain menu:" );
+ screen.displayMessageLine( "1 - View my balance" );
+ screen.displayMessageLine( "2 - Withdraw cash" );
+ screen.displayMessageLine( "3 - Transfer funds" );
+ screen.displayMessageLine( "4 - Set Compound Frequency" );
+ screen.displayMessageLine( "5 - Exit\n" );
+ screen.displayMessageLine("Please enter your choice: ");
+
+ }
+
+ // menu for chequeing account
+ private void displayMainMenuCheque() {
+ screen.displayMessageLine( "\nMain menu:" );
+ screen.displayMessageLine( "1 - View my balance" );
+ screen.displayMessageLine( "2 - Withdraw cash" );
+ screen.displayMessageLine( "3 - Transfer funds" );
+ screen.displayMessageLine( "4 - Set cheque limit" );
+ screen.displayMessageLine( "5 - Exit\n" );
+
+ screen.displayMessageLine("Please enter your choice: ");
+ }
// return object of specified Transaction subclass
- private Transaction createTransaction( int type )
- {
- Transaction temp = null; // temporary Transaction variable
-
- // determine which type of Transaction to create
- switch ( type )
- {
- case BALANCE_INQUIRY: // create new BalanceInquiry transaction
- temp = new BalanceInquiry(
- currentAccountNumber, screen, bankDatabase );
- break;
- case WITHDRAWAL: // create new Withdrawal transaction
- temp = new Withdrawal( currentAccountNumber, screen,
- bankDatabase, keypad, cashDispenser );
- break;
- case TRANSFER: // create new Deposit transaction
- temp = new Transfer( currentAccountNumber, screen,
- bankDatabase, keypad);
- break;
-
- } // end switch
+ private Transaction createTransaction( int type , String ACType)
+ {
+ Transaction temp = null; // temporary Transaction variable
+
+ // determine which type of Transaction to create
+ switch ( type )
+ {
+ case BALANCE_INQUIRY: // create new BalanceInquiry transaction
+ temp = new BalanceInquiry(
+ currentAccountNumber, screen, bankDatabase );
+ break;
+ case WITHDRAWAL: // create new Withdrawal transaction
+ temp = new Withdrawal( currentAccountNumber, screen,
+ bankDatabase, keypad, cashDispenser );
+ break;
+ case TRANSFER: // create new Deposit transaction
+ temp = new Transfer( currentAccountNumber, screen,
+ bankDatabase, keypad);
+ break;
+ case FORTH_OPTION:
+ if (ACType == SAVINGTYPE) {
+ temp = new SetComFre(currentAccountNumber, screen, bankDatabase, keypad);
+ }
+ if (ACType == CHEQUEINGTYPE) {
+ temp = new SetLimit(currentAccountNumber, screen, bankDatabase, keypad);
+ }else{
+ break;
+ }
+ } // end switch
return temp; // return the newly created object
- } // end method createTransaction
+ } // end method createTransaction
} // end class ATM
diff --git a/ATMsource/Account.java b/ATMsource/Account.java
index c308eca..3c0bbf3 100644
--- a/ATMsource/Account.java
+++ b/ATMsource/Account.java
@@ -3,60 +3,68 @@
public class Account
{
- private int accountNumber; // account number
- private int pin; // PIN for authentication
- private double availableBalance; // funds available for withdrawal
- private double totalBalance; // funds available + pending deposits
+ private int accountNumber; // account number
+ private int pin; // PIN for authentication
+ private double availableBalance; // funds available for withdrawal
+ private double totalBalance; // funds available + pending deposits
- // Account constructor initializes attributes
- public Account( int theAccountNumber, int thePIN,
- double theAvailableBalance, double theTotalBalance )
- {
- accountNumber = theAccountNumber;
- pin = thePIN;
- availableBalance = theAvailableBalance;
- totalBalance = theTotalBalance;
- } // end Account constructor
+ // we assume existing accounts remain it original type, until the owner requests for changing
+ private static final String TYPE = "General account";
- // determines whether a user-specified PIN matches PIN in Account
- public boolean validatePIN( int userPIN )
- {
- if ( userPIN == pin )
- return true;
- else
- return false;
- } // end method validatePIN
-
- // returns available balance
- public double getAvailableBalance()
- {
- return availableBalance;
- } // end getAvailableBalance
+ // Account constructor initializes attributes
+ public Account( int theAccountNumber, int thePIN,
+ double theAvailableBalance, double theTotalBalance )
+ {
+ accountNumber = theAccountNumber;
+ pin = thePIN;
+ availableBalance = theAvailableBalance;
+ totalBalance = theTotalBalance;
+ } // end Account constructor
- // returns the total balance
- public double getTotalBalance()
- {
- return totalBalance;
- } // end method getTotalBalance
+ // determines whether a user-specified PIN matches PIN in Account
+ public boolean validatePIN( int userPIN )
+ {
+ if ( userPIN == pin )
+ return true;
+ else
+ return false;
+ } // end method validatePIN
+
+ // returns available balance
+ public double getAvailableBalance()
+ {
+ return availableBalance;
+ } // end getAvailableBalance
- // credits an amount to the account
- public void credit( double amount )
- {
- totalBalance += amount; // add to total balance
- } // end method credit
+ // returns the total balance
+ public double getTotalBalance()
+ {
+ return totalBalance;
+ } // end method getTotalBalance
- // debits an amount from the account
- public void debit( double amount )
- {
- availableBalance -= amount; // subtract from available balance
- totalBalance -= amount; // subtract from total balance
- } // end method debit
+ // credits an amount to the account
+ public void credit( double amount )
+ {
+ totalBalance += amount; // add to total balance
+ } // end method credit
- // returns account number
- public int getAccountNumber()
- {
- return accountNumber;
- } // end method getAccountNumber
+ // debits an amount from the account
+ public void debit( double amount )
+ {
+ availableBalance -= amount; // subtract from available balance
+ totalBalance -= amount; // subtract from total balance
+ } // end method debit
+
+ // returns account number
+ public int getAccountNumber()
+ {
+ return accountNumber;
+ } // end method getAccountNumber
+
+ // returns account type
+ public String getType() {
+ return TYPE;
+ }
} // end class Account
diff --git a/ATMsource/BankDatabase.java b/ATMsource/BankDatabase.java
index dab337b..936fc36 100644
--- a/ATMsource/BankDatabase.java
+++ b/ATMsource/BankDatabase.java
@@ -1,89 +1,114 @@
+
// BankDatabase.java
// Represents the bank account information database
public class BankDatabase
{
- private Account accounts[]; // array of Accounts
-
- // no-argument BankDatabase constructor initializes accounts
- public BankDatabase()
- {
- accounts = new Account[ 4 ]; // just 2 accounts for testing
- accounts[ 0 ] = new Account( 12345, 54321, 1000.0, 1200.0 );
- accounts[ 1 ] = new Account( 98765, 56789, 200.0, 200.0 );
-
- // new accounts of checque account and saving account
- accounts[ 2 ] = new ChecqueAccount(23456, 65432, 500, 1000);
- accounts[ 3 ] = new SavingAccount(34567, 76543, 2000, 2500);
- } // end no-argument BankDatabase constructor
-
- // retrieve Account object containing specified account number
- private Account getAccount( int accountNumber )
- {
- // loop through accounts searching for matching account number
- for ( Account currentAccount : accounts )
- {
- // return current account if match found
- if ( currentAccount.getAccountNumber() == accountNumber )
- return currentAccount;
- } // end for
-
- return null; // if no matching account was found, return null
- } // end method getAccount
-
- // determine whether user-specified account number and PIN match
- // those of an account in the database
- public boolean authenticateUser( int userAccountNumber, int userPIN )
- {
- // attempt to retrieve the account with the account number
- Account userAccount = getAccount( userAccountNumber );
-
- // if account exists, return result of Account method validatePIN
- if ( userAccount != null )
- return userAccount.validatePIN( userPIN );
- else
- return false; // account number not found, so return false
- } // end method authenticateUser
-
- // to check whether the account is exists in the database
- public boolean accountExists(int ACnumber){
-
- int acFound = 0;
-
- // loop through accounts searching for matching account number
- for ( Account currentAccount : accounts )
- {
- if(currentAccount.getAccountNumber() == ACnumber)
- acFound += 1;
- } // end for
-
- // return true when only one account is matched with ACnumber
- return acFound==1;
-
- }
- // return available balance of Account with specified account number
- public double getAvailableBalance( int userAccountNumber )
- {
- return getAccount( userAccountNumber ).getAvailableBalance();
- } // end method getAvailableBalance
-
- // return total balance of Account with specified account number
- public double getTotalBalance( int userAccountNumber )
- {
- return getAccount( userAccountNumber ).getTotalBalance();
- } // end method getTotalBalance
-
- // credit an amount to Account with specified account number
- public void credit( int userAccountNumber, double amount )
- {
- getAccount( userAccountNumber ).credit( amount );
- } // end method credit
-
- // debit an amount from of Account with specified account number
- public void debit( int userAccountNumber, double amount )
- {
- getAccount( userAccountNumber ).debit( amount );
- } // end method debit
+ private Account accounts[]; // array of Accounts
+
+ // no-argument BankDatabase constructor initializes accounts
+ public BankDatabase()
+ {
+ accounts = new Account[ 4 ]; // just 2 accounts for default testing, and 2 for account types testing
+ accounts[ 0 ] = new Account( 12345, 54321, 1000.0, 1200.0 );
+ accounts[ 1 ] = new Account( 98765, 56789, 200.0, 200.0 );
+
+ // new accounts of checque account and saving account
+ accounts[ 2 ] = new ChequeAccount(2, 2, 500, 1000);
+ accounts[ 3 ] = new SavingAccount(3, 3, 2000, 2500);
+
+ } // end no-argument BankDatabase constructor
+
+ // retrieve Account object containing specified account number
+ private Account getAccount( int accountNumber )
+ {
+ // loop through accounts searching for matching account number
+ for ( Account currentAccount : accounts )
+ {
+ // return current account if match found
+ if ( currentAccount.getAccountNumber() == accountNumber )
+ return currentAccount;
+ } // end for
+
+ return null; // if no matching account was found, return null
+ } // end method getAccount
+
+ // determine whether user-specified account number and PIN match
+ // those of an account in the database
+ public boolean authenticateUser( int userAccountNumber, int userPIN )
+ {
+ // attempt to retrieve the account with the account number
+ Account userAccount = getAccount( userAccountNumber );
+
+ // if account exists, return result of Account method validatePIN
+ if ( userAccount != null )
+ return userAccount.validatePIN( userPIN );
+ else
+ return false; // account number not found, so return false
+ } // end method authenticateUser
+
+ // to check whether the account is exists in the database
+ public boolean accountExists(int ACnumber){
+
+ int acFound = 0;
+
+ // loop through accounts searching for matching account number
+ for ( Account currentAccount : accounts )
+ {
+ if(currentAccount.getAccountNumber() == ACnumber)
+ acFound += 1;
+ } // end for
+
+ // return true when only one account is matched with ACnumber
+ return acFound==1;
+
+ }
+ // return available balance of Account with specified account number
+ public double getAvailableBalance( int userAccountNumber )
+ {
+ return getAccount( userAccountNumber ).getAvailableBalance();
+ } // end method getAvailableBalance
+
+ // return total balance of Account with specified account number
+ public double getTotalBalance( int userAccountNumber )
+ {
+ return getAccount( userAccountNumber ).getTotalBalance();
+ } // end method getTotalBalance
+
+ // credit an amount to Account with specified account number
+ public void credit( int userAccountNumber, double amount )
+ {
+ getAccount( userAccountNumber ).credit( amount );
+ } // end method credit
+
+ // debit an amount from of Account with specified account number
+ public void debit( int userAccountNumber, double amount )
+ {
+ getAccount( userAccountNumber ).debit( amount );
+ } // end method debit
+
+ public void setChequeLimit(int userAccountNumber, double amount) {
+
+ // downcasting current account to ChequeAccount for setting limit
+ ChequeAccount temp = (ChequeAccount) getAccount(userAccountNumber);
+ temp.setLimit(amount);
+ }
+
+ // return user's account tyoe in string
+ public String getAccountTypeString(int userAccountNumber) {
+ return getAccount(userAccountNumber).getType();
+ }
+
+ public void setFrequency(int currentAccountNumber, int FreSelection) {
+ SavingAccount temp = (SavingAccount) getAccount(currentAccountNumber);
+ temp.setFrequency(FreSelection);
+ }
+
+ public double getCurrentRate(int currentAccountNumber) {
+ SavingAccount temp = (SavingAccount) getAccount(currentAccountNumber);
+ double rate = temp.getInterestRate();
+ return rate;
+ }
} // end class BankDatabase
diff --git a/ATMsource/ChecqueAccount.java b/ATMsource/ChecqueAccount.java
deleted file mode 100644
index d65fab1..0000000
--- a/ATMsource/ChecqueAccount.java
+++ /dev/null
@@ -1,19 +0,0 @@
-public class ChecqueAccount extends Account {
-
- private double LimitPerCheque;
-
- public ChecqueAccount(int theAccountNumber, int thePIN,
- double theAvailableBalance, double theTotalBalance) {
-
- super(theAccountNumber, thePIN, theAvailableBalance, theTotalBalance);
- LimitPerCheque = 10000;
- }
-
- public void setLimit(double limit) {
- LimitPerCheque = limit;
- }
-
- public double getLimit(){
- return LimitPerCheque;
- }
-}
diff --git a/ATMsource/Keypad.java b/ATMsource/Keypad.java
index cd035c7..e3a47c7 100644
--- a/ATMsource/Keypad.java
+++ b/ATMsource/Keypad.java
@@ -4,19 +4,19 @@ import java.util.Scanner; // program uses Scanner to obtain user input
public class Keypad
{
- private Scanner input; // reads data from the command line
-
- // no-argument constructor initializes the Scanner
- public Keypad()
- {
- input = new Scanner( System.in );
- } // end no-argument Keypad constructor
+ private Scanner input; // reads data from the command line
+
+ // no-argument constructor initializes the Scanner
+ public Keypad()
+ {
+ input = new Scanner( System.in );
+ } // end no-argument Keypad constructor
- // return an integer value entered by user
- public int getInput()
- {
- return input.nextInt(); // we assume that user enters an integer
- } // end method getInput
+ // return an integer value entered by user
+ public int getInput()
+ {
+ return input.nextInt(); // we assume that user enters an integer
+ } // end method getInput
} // end class Keypad
diff --git a/ATMsource/SavingAccount.java b/ATMsource/SavingAccount.java
index a334429..0fde98b 100644
--- a/ATMsource/SavingAccount.java
+++ b/ATMsource/SavingAccount.java
@@ -2,6 +2,10 @@ public class SavingAccount extends Account{
private double interestRate;
+ private static final String TYPE = "Saving account";
+ private int FREQUENCY;
+
+
public SavingAccount(int theAccountNumber, int thePIN,
double theAvailableBalance, double theTotalBalance){
@@ -10,11 +14,21 @@ public class SavingAccount extends Account{
interestRate = 0.001;
}
- public void setInterestRate(double rate) {
- interestRate = rate;
- }
-
public double getInterestRate() {
return interestRate;
}
+
+ public double getFre() {
+ return FREQUENCY;
+ }
+
+ // returns account type
+ @Override
+ public String getType() {
+ return TYPE;
+ }
+
+ public void setFrequency(int freSelection) {
+ FREQUENCY = freSelection;
+ }
}
diff --git a/ATMsource/Transaction.java b/ATMsource/Transaction.java
index 508fea8..8d79c29 100644
--- a/ATMsource/Transaction.java
+++ b/ATMsource/Transaction.java
@@ -1,6 +1,8 @@
// Transaction.java
// Abstract superclass Transaction represents an ATM transaction
+//import java.lang.Math;
+
public abstract class Transaction
{
private int accountNumber; // indicates account involved
diff --git a/ATMsource/Transfer.java b/ATMsource/Transfer.java
index b70dc59..2fa53c7 100644
--- a/ATMsource/Transfer.java
+++ b/ATMsource/Transfer.java
@@ -45,13 +45,21 @@ public class Transfer extends Transaction {
target = keypad.getInput();
screen.displayMessage("Please enter amount: ");
- amount = keypad.getInput();
+ try {
+ amount = keypad.getInput();
- if (isSufficientTransfer(amount, availableBalance) && bankDatabase.accountExists(target) && target != currentAccountNumber) {
+ } catch (Exception e) {
+
+ // to maintain all inputs are integer, fund with cents are not considered
+ screen.displayMessageLine("Input mismatch! $0 will be transfered.");
+ amount = 0;
+ }
+
+ if (isSufficientTransfer(amount, availableBalance) && bankDatabase.accountExists(target) && target != currentAccountNumber) {
bankDatabase.debit(currentAccountNumber, amount);
bankDatabase.credit(target, amount);
- }else{
+ }else{
screen.displayMessageLine("Availavle balance is lower than transfer amount or target account unavailable.");
screen.displayMessageLine("Progress aborted.");
diff --git a/ATMsource/cp/ATM.class b/ATMsource/cp/ATM.class
index 8be722f..7393661 100644
Binary files a/ATMsource/cp/ATM.class and b/ATMsource/cp/ATM.class differ
diff --git a/ATMsource/cp/Account.class b/ATMsource/cp/Account.class
index d6f406c..b1cbd00 100644
Binary files a/ATMsource/cp/Account.class and b/ATMsource/cp/Account.class differ
diff --git a/ATMsource/cp/BankDatabase.class b/ATMsource/cp/BankDatabase.class
index 3349273..b55de8e 100644
Binary files a/ATMsource/cp/BankDatabase.class and b/ATMsource/cp/BankDatabase.class differ
diff --git a/ATMsource/cp/CashDispenser.class b/ATMsource/cp/CashDispenser.class
index aa7c0c9..5ea19b5 100644
Binary files a/ATMsource/cp/CashDispenser.class and b/ATMsource/cp/CashDispenser.class differ
diff --git a/ATMsource/cp/Transaction.class b/ATMsource/cp/Transaction.class
index f8b658d..70a3b36 100644
Binary files a/ATMsource/cp/Transaction.class and b/ATMsource/cp/Transaction.class differ
diff --git a/ATMsource/cp/Transfer.class b/ATMsource/cp/Transfer.class
index 89cc4e2..07624bd 100644
Binary files a/ATMsource/cp/Transfer.class and b/ATMsource/cp/Transfer.class differ
diff --git a/ATMsource/cp/Withdrawal.class b/ATMsource/cp/Withdrawal.class
index 39fb9eb..797c5f3 100644
Binary files a/ATMsource/cp/Withdrawal.class and b/ATMsource/cp/Withdrawal.class differ
diff --git a/ATMsource/cp/checqueAccount.class b/ATMsource/cp/checqueAccount.class
index 37c81f0..94360f1 100644
Binary files a/ATMsource/cp/checqueAccount.class and b/ATMsource/cp/checqueAccount.class differ
diff --git a/ATMsource/cp/savingAccount.class b/ATMsource/cp/savingAccount.class
index 0c9122b..9a32855 100644
Binary files a/ATMsource/cp/savingAccount.class and b/ATMsource/cp/savingAccount.class differ