-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankDatabase.java
More file actions
108 lines (92 loc) · 4.46 KB
/
BankDatabase.java
File metadata and controls
108 lines (92 loc) · 4.46 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
// 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[10]; // 10 accounts
accounts[0] = new Account(11111, 11111, 1000.35, 1000.35);
accounts[1] = new Account(22222, 22222, 25234.50, 25234.50);
accounts[2] = new Account(43121, 43121, 50000.75, 50000.75);
accounts[3] = new Account(33333, 33333, 150000.90, 150000.90);
accounts[4] = new Account(56425, 56425, 3000.20, 3000.20);
accounts[5] = new Account(72343, 72343, 7500.10, 7500.10);
accounts[6] = new Account(66535, 66535, 12000.80, 12000.80);
accounts[7] = new Account(11451, 11451, 114514.60, 114514.60);
accounts[8] = new Account(88888, 88888, 60833.95, 60833.95);
accounts[9] = new Account(99999, 99999, 90350.45, 90350.45);
} // 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
// 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 boolean isValidAccount(int currentAccountNumber)
{
boolean isValid = false;
// loop through accounts searching for matching account number
for ( Account currentAccount : accounts )
{
// return current account if match found
if ( currentAccount.getAccountNumber() == currentAccountNumber ) {
isValid = true;
}
}
return isValid;
}
} // end class BankDatabase
/**************************************************************************
* (C) Copyright 1992-2007 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
*************************************************************************/