Strip HTML
__MACOSX/._BA Uncompressed
BA Uncompressed/.DS_Store
__MACOSX/BA Uncompressed/._.DS_Store
BA Uncompressed/pom.xml
4.0.0 swsec bank 1.0 jar Banking Application google_checks.xml 2.17 2.6 3.0.1 2.10.2 2.1 1.7 4.12 2.5 1.1.3 2.6 2.6 1.7.12 3.4 1.2.1 UTF-8 ${project.groupId}.${project.ArtifactId}.Runner ${project.artifactId} org.apache.maven.plugins maven-checkstyle-plugin ${checkstyle.version} compile verify-style check true 100 warning org.apache.maven.plugins maven-jar-plugin ${maven.jar.plugin.version} true lib/ ${project.mainClass} org.codehaus.mojo exec-maven-plugin ${exec.maven.plugin.version} test java ${project.mainClass} org.apache.maven.plugins maven-surefire-report-plugin ${surefire.report.version} report-only failsafe-report-only org.codehaus.mojo cobertura-maven-plugin ${cobertura.version} html xml ch.qos.logback logback-classic org.codehaus.mojo findbugs-maven-plugin ${findbugs.version} org.apache.maven.plugins maven-pmd-plugin ${pmd.version} org.codehaus.mojo javancss-maven-plugin ${javancss.version} org.apache.maven.plugins maven-checkstyle-plugin ${checkstyle.version} org.apache.maven.plugins maven-javadoc-plugin ${javadoc.version} org.apache.maven.plugins maven-jxr-plugin ${jxr.version} true com.googlecode.jmockit jmockit ${jmockit.version} test junit junit ${junit.version} test org.slf4j slf4j-api ${org.slf4j.version} ch.qos.logback logback-classic ${logback.version} ch.qos.logback logback-core ${logback.version}
BA Uncompressed/google_checks.xml
BA Uncompressed/admins.txt
admin1 password1 Barak Obama 1234 admin2 password2 Donald Trump 5678
BA Uncompressed/customers.txt
cseaman biscuit 1234 Carolyn Seaman Happy Lane, Pleasantville biscuit cseaman 5678 Biscuit Dog Walkabout, Sydney newone abcdef 0 New Customer New Block, Welcomeville
BA Uncompressed/bank.iml
BA Uncompressed/accounts.txt
1234 305.0 5678 253.0 910 0.00 6615 5005.0
__MACOSX/BA Uncompressed/._src
BA Uncompressed/src/.DS_Store
__MACOSX/BA Uncompressed/src/._.DS_Store
__MACOSX/BA Uncompressed/src/._main
BA Uncompressed/src/main/.DS_Store
__MACOSX/BA Uncompressed/src/main/._.DS_Store
__MACOSX/BA Uncompressed/src/main/._resources
__MACOSX/BA Uncompressed/src/main/._java
BA Uncompressed/src/main/java/.DS_Store
__MACOSX/BA Uncompressed/src/main/java/._.DS_Store
__MACOSX/BA Uncompressed/src/main/java/._swsec
BA Uncompressed/src/main/java/admins.txt
admin1 password1 Barak Obama 1234 admin2 password2 Donald Trump 5678
BA Uncompressed/src/main/java/customers.txt
cseaman biscuit 1234 Carolyn Seaman Happy Lane, Pleasantville biscuit cseaman 5678 Biscuit Dog Walkabout, Sydney newone abcdef 6730 New Customer New Block, Welcomeville
BA Uncompressed/src/main/java/accounts.txt
1234 395.0 5678 253.0 910 0.00 6615 5005.0 6730 3000.0
BA Uncompressed/src/main/java/swsec/.DS_Store
__MACOSX/BA Uncompressed/src/main/java/swsec/._.DS_Store
__MACOSX/BA Uncompressed/src/main/java/swsec/._bank
BA Uncompressed/src/main/java/swsec/bank/.DS_Store
__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._.DS_Store
BA Uncompressed/src/main/java/swsec/bank/Runner.java
BA Uncompressed/src/main/java/swsec/bank/Runner.java
package
swsec
.
bank
;
import
swsec
.
bank
.
services
.
UiService
;
/**
* This class starts the program and should not be modified.
*/
public
class
Runner
{
public
static
void
main
(
String
[]
args
)
{
Runnable
start
=
new
UiService
();
start
.
run
();
}
}
BA Uncompressed/src/main/java/swsec/bank/Runner.class
__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._models
__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._exceptions
BA Uncompressed/src/main/java/swsec/bank/cd
__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._controllers
__MACOSX/BA Uncompressed/src/main/java/swsec/bank/._services
BA Uncompressed/src/main/java/swsec/bank/models/Admin.java
BA Uncompressed/src/main/java/swsec/bank/models/Admin.java
package
swsec
.
bank
.
models
;
public
class
Admin
{
// Instance variables
private
String
username
;
private
String
password
;
private
String
name
;
private
String
employeeId
;
private
boolean
authenticated
=
false
;
public
Admin
()
{
// needs to pass in values for all instance variables and assign those values to the variables
}
public
Admin
(
String
username
,
String
password
,
String
name
,
String
employeeId
)
{
// Use when all attributes are known
this
.
username
=
username
;
this
.
password
=
password
;
this
.
name
=
name
;
this
.
employeeId
=
employeeId
;
}
public
Admin
(
String
name
,
String
employeeId
)
{
//sometimes an Admin object needs to be created before login credentials are known
this
.
name
=
name
;
this
.
employeeId
=
employeeId
;
}
public
void
setCredentials
(
String
username
,
String
password
)
{
this
.
username
=
username
;
this
.
password
=
password
;
}
public
void
markAuthenticated
()
{
this
.
authenticated
=
true
;
}
public
String
getUsername
()
{
return
this
.
username
;
}
public
String
getPassword
()
{
return
this
.
password
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
String
getEmployeeId
()
{
return
this
.
employeeId
;
}
public
boolean
isAuthenticated
()
{
return
this
.
authenticated
;
}
}
BA Uncompressed/src/main/java/swsec/bank/models/Customer.java
BA Uncompressed/src/main/java/swsec/bank/models/Customer.java
package
swsec
.
bank
.
models
;
public
class
Customer
{
// Instance variables
private
String
username
;
//used as a unique identifier
private
String
password
;
private
int
accountNum
;
private
String
name
;
private
String
address
;
private
boolean
authenticated
=
false
;
public
Customer
(
String
username
,
String
password
,
String
name
,
String
address
)
{
// Use when all attributes are known
this
.
username
=
username
;
this
.
password
=
password
;
this
.
name
=
name
;
this
.
address
=
address
;
}
public
Customer
(
String
username
,
String
password
)
{
//sometimes a Customer object needs to be created in order to retrieve Customer attributes
this
.
username
=
username
;
this
.
password
=
password
;
}
public
void
markAuthenticated
()
{
// called after the associated Repository object confirms credentials
this
.
authenticated
=
true
;
}
public
void
setAccountNum
(
int
accountNum
)
{
this
.
accountNum
=
accountNum
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
public
void
setCredentials
(
String
username
,
String
password
)
{
this
.
username
=
username
;
this
.
password
=
password
;
}
public
void
logout
()
{
this
.
authenticated
=
false
;
}
public
String
getUsername
()
{
return
this
.
username
;
}
public
String
getPassword
()
{
return
this
.
password
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
String
getAddress
()
{
return
this
.
address
;
}
public
int
getAccountNum
()
{
return
this
.
accountNum
;
}
public
boolean
isAuthenticated
()
{
return
this
.
authenticated
;
}
}
BA Uncompressed/src/main/java/swsec/bank/models/Customer.class
BA Uncompressed/src/main/java/swsec/bank/models/Account.java
BA Uncompressed/src/main/java/swsec/bank/models/Account.java
package
swsec
.
bank
.
models
;
public
class
Account
{
// Instance variables
private
int
accountNum
;
private
float
currentBalance
;
public
Account
()
{
// constructor doesn't do anything, in the case when a new account is being created
// because the variables are not known yet.
}
public
Account
(
int
accountNum
,
float
currentBalance
)
{
// in the case where an Account object is needed to represent an existing account,
// then the instance variables are populated.
this
.
accountNum
=
accountNum
;
this
.
currentBalance
=
currentBalance
;
}
public
void
setAccountNum
(
int
accountNum
)
{
this
.
accountNum
=
accountNum
;
}
public
void
setCurrentBalance
(
float
currentBalance
)
{
this
.
currentBalance
=
currentBalance
;
}
public
int
getAccountNum
()
{
return
this
.
accountNum
;
}
public
float
getCurrentBalance
()
{
return
this
.
currentBalance
;
}
}
BA Uncompressed/src/main/java/swsec/bank/models/Admin.class
BA Uncompressed/src/main/java/swsec/bank/models/Person.java
BA Uncompressed/src/main/java/swsec/bank/models/Person.java
package
swsec
.
bank
.
models
;
public
abstract
class
Person
{
// Instance variables
public
Person
()
{
}
// Other constructors
// Getters and Setters
}
BA Uncompressed/src/main/java/swsec/bank/models/Account.class
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNoAccountException.java
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNoAccountException.java
package
swsec
.
bank
.
exceptions
;
// Exception thrown by the CustomerController class methods and handled in UiServices
//
public
class
CustomerNoAccountException
extends
Exception
{
private
String
username
;
// constructor
public
CustomerNoAccountException
(
String
username
)
{
super
(
"Customer "
+
username
+
" does not have an account."
);
this
.
username
=
username
;
}
public
String
getUsername
()
{
return
username
;
}
}
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustNotFoundException.class
BA Uncompressed/src/main/java/swsec/bank/exceptions/AdminNotFoundException.class
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNotAuthenticatedException.java
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNotAuthenticatedException.java
package
swsec
.
bank
.
exceptions
;
// Exception thrown by the CustomerController class methods and handled in UiServices
//
public
class
CustomerNotAuthenticatedException
extends
Exception
{
private
String
username
;
// constructor
public
CustomerNotAuthenticatedException
(
String
username
)
{
super
(
"Customer "
+
username
+
" is not authenticated."
);
this
.
username
=
username
;
}
public
String
getUsername
()
{
return
username
;
}
}
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNotAuthenticatedException.class
BA Uncompressed/src/main/java/swsec/bank/exceptions/InsufficientFundsException.java
BA Uncompressed/src/main/java/swsec/bank/exceptions/InsufficientFundsException.java
package
swsec
.
bank
.
exceptions
;
// Exception thrown by the CustomerController class methods and handled in UiServices
//
public
class
InsufficientFundsException
extends
Exception
{
private
String
username
;
private
Float
amount
;
// constructor
public
InsufficientFundsException
(
String
username
,
Float
amount
)
{
super
(
"Customer "
+
username
+
" does not have sufficient funds to cover a withdrawal of "
+
Float
.
toString
(
amount
));
this
.
username
=
username
;
this
.
amount
=
amount
;
}
public
Float
getAmount
()
{
return
amount
;
}
}
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustomerNoAccountException.class
BA Uncompressed/src/main/java/swsec/bank/exceptions/AmountNotVerifiedException.java
BA Uncompressed/src/main/java/swsec/bank/exceptions/AmountNotVerifiedException.java
package
swsec
.
bank
.
exceptions
;
// Exception thrown by the CustomerController class methods and handled in UiServices
//
public
class
AmountNotVerifiedException
extends
Exception
{
private
Float
amount
;
// constructor
public
AmountNotVerifiedException
(
Float
amount
)
{
super
(
"Amount of "
+
amount
+
" has not been verified."
);
this
.
amount
=
amount
;
}
public
Float
getAmount
()
{
return
amount
;
}
}
BA Uncompressed/src/main/java/swsec/bank/exceptions/AdminNotFoundException.java
BA Uncompressed/src/main/java/swsec/bank/exceptions/AdminNotFoundException.java
package
swsec
.
bank
.
exceptions
;
// Exception thrown by the AdminRepository class methods and handled in UiServices
//
public
class
AdminNotFoundException
extends
Exception
{
private
String
username
;
// constructor
public
AdminNotFoundException
(
String
username
)
{
super
(
"Admin "
+
username
+
" does not exist."
);
this
.
username
=
username
;
}
public
String
getUsername
()
{
return
username
;
}
}
BA Uncompressed/src/main/java/swsec/bank/exceptions/AccountNotFoundException.java
BA Uncompressed/src/main/java/swsec/bank/exceptions/AccountNotFoundException.java
package
swsec
.
bank
.
exceptions
;
// Exception thrown by the AccountRepository class methods and handled in UiServices
//
public
class
AccountNotFoundException
extends
Exception
{
private
int
accountNum
;
// constructor
public
AccountNotFoundException
(
int
accountNum
)
{
super
(
"Account "
+
Integer
.
toString
(
accountNum
)
+
" does not exist."
);
this
.
accountNum
=
accountNum
;
}
public
int
getAccountNum
()
{
return
accountNum
;
}
}
BA Uncompressed/src/main/java/swsec/bank/exceptions/AccountNotFoundException.class
BA Uncompressed/src/main/java/swsec/bank/exceptions/InsufficientFundsException.class
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustNotFoundException.java
BA Uncompressed/src/main/java/swsec/bank/exceptions/CustNotFoundException.java
package
swsec
.
bank
.
exceptions
;
// Exception thrown by the CustomerRepository class methods and handled in UiServices
//
public
class
CustNotFoundException
extends
Exception
{
private
String
username
;
// constructor
public
CustNotFoundException
(
String
username
)
{
super
(
"Customer "
+
username
+
" does not exist."
);
this
.
username
=
username
;
}
public
String
getUsername
()
{
return
username
;
}
}
BA Uncompressed/src/main/java/swsec/bank/exceptions/AmountNotVerifiedException.class
BA Uncompressed/src/main/java/swsec/bank/controllers/AdminController.java
BA Uncompressed/src/main/java/swsec/bank/controllers/AdminController.java
package
swsec
.
bank
.
controllers
;
import
swsec
.
bank
.
exceptions
.
AccountNotFoundException
;
import
swsec
.
bank
.
models
.
Admin
;
import
swsec
.
bank
.
models
.
Customer
;
import
swsec
.
bank
.
services
.
repositories
.
AdminRepository
;
import
swsec
.
bank
.
services
.
repositories
.
CustomerRepository
;
import
java
.
io
.
IOException
;
public
class
AdminController
{
private
AdminRepository
thisRep
;
private
Admin
thisAdmin
;
public
AdminController
()
{
// every instance of a Controller needs a corresponding Repository and Model object
thisRep
=
new
AdminRepository
();
thisAdmin
=
new
Admin
();
}
// uses thisRep to look up Admin - if successful, will load Admin attributes into thisAdmin
// and mark authenticated
public
boolean
authenticate
(
String
username
,
String
password
)
{
thisAdmin
.
setCredentials
(
username
,
password
);
Admin
tempAdmin
=
thisRep
.
lookup
(
thisAdmin
);
if
(
tempAdmin
.
isAuthenticated
())
{
thisAdmin
=
tempAdmin
;
return
(
true
);
}
else
{
return
(
false
);
}
}
public
int
requestAccount
(
float
initialBalance
)
{
// called by CustomerController
// needs to create an instance of UiService, which authenticates the Admin
// then needs to create an instance of an AccountController, which
// it uses to create the new account
// TBD
// UiService thisUIS = new UiService ();
// thisUIS.authenticateAdmin ();
AccountController
thisNewAcct
=
new
AccountController
(
0
);
return
thisNewAcct
.
newAccount
(
initialBalance
);
}
public
void
modifyBalance
(
int
accountNum
,
float
newBalance
)
throws
IOException
,
AccountNotFoundException
{
// checks to make sure this Admin object is authenticated
// creates an instance of AccountController and uses it to modify the balance
if
(
thisAdmin
.
isAuthenticated
())
{
AccountController
thisAcct
=
new
AccountController
(
accountNum
);
try
{
thisAcct
.
changeBalance
(
newBalance
);
}
catch
(
IOException
ex
)
{
throw
new
IOException
();
}
catch
(
AccountNotFoundException
acctEx
)
{
throw
new
AccountNotFoundException
(
accountNum
);
}
}
else
{
System
.
out
.
println
(
"Admin needs to be authenticated first."
);
}
}
}
BA Uncompressed/src/main/java/swsec/bank/controllers/CustomerController.java
BA Uncompressed/src/main/java/swsec/bank/controllers/CustomerController.java
package
swsec
.
bank
.
controllers
;
import
swsec
.
bank
.
exceptions
.
AccountNotFoundException
;
import
swsec
.
bank
.
exceptions
.
AmountNotVerifiedException
;
import
swsec
.
bank
.
exceptions
.
CustNotFoundException
;
import
swsec
.
bank
.
exceptions
.
CustomerNoAccountException
;
import
swsec
.
bank
.
exceptions
.
CustomerNotAuthenticatedException
;
import
swsec
.
bank
.
exceptions
.
InsufficientFundsException
;
import
swsec
.
bank
.
models
.
Customer
;
import
swsec
.
bank
.
services
.
VerificationSystem
;
import
swsec
.
bank
.
services
.
repositories
.
CustomerRepository
;
import
java
.
io
.
IOException
;
public
class
CustomerController
{
private
CustomerRepository
thisRep
;
//the repository object associated with this customer
private
Customer
thisCust
;
// the model object associated with this customer
// the account controller associated with this customer's account, if the customer has one
private
AccountController
thisAcct
;
private
VerificationSystem
vs
=
new
VerificationSystem
();
public
boolean
hasAcct
=
false
;
// indicates if this customer has an account yet
// constructor - called when a customer logs in, so username and password are known,
// but no other attributes are yet known
// Assumes that all customers are created a priori; a new constructor will need to be i
// added to create a new customer that does not previously exist
public
CustomerController
(
String
username
,
String
password
)
throws
CustNotFoundException
,
IOException
{
int
accountNum
;
// every instance of CustomerController needs a thisRep and a thisCust
thisRep
=
new
CustomerRepository
();
thisCust
=
new
Customer
(
username
,
password
);
//make sure it's a valid Customer
try
{
accountNum
=
authenticate
(
thisRep
,
thisCust
);
}
catch
(
IOException
ex
)
{
throw
new
IOException
();
}
if
(
accountNum
==
-
1
)
{
//customer was not found or password wrong
throw
new
CustNotFoundException
(
username
);
}
else
{
if
(
accountNum
>
0
)
{
//customer has an account
//create AccountController object
hasAcct
=
true
;
thisAcct
=
new
AccountController
(
accountNum
);
}
}
}
public
boolean
hasAcct
()
{
return
this
.
hasAcct
;
}
// uses thisRep to lookup customer - if successful, will load customer attributes into
// tempCust and mark authenticated
public
int
authenticate
(
CustomerRepository
thisRep
,
Customer
thisCust
)
throws
IOException
{
Customer
tempCust
;
try
{
tempCust
=
thisRep
.
lookup
(
thisCust
);
//lookup will also check password
}
catch
(
IOException
ex
)
{
throw
new
IOException
();
}
if
(
tempCust
.
isAuthenticated
())
{
thisCust
=
tempCust
;
return
(
tempCust
.
getAccountNum
());
//will return 0 if there is no account number
}
else
{
return
(
-
1
);
}
}
// when a new account is created for this Customer, most of the work is done in AdminController,
// but this object has to store the account number in the Customer object.
public
void
linkAccount
(
int
accountNum
,
AccountController
newAcct
)
throws
CustNotFoundException
,
IOException
{
thisCust
.
setAccountNum
(
accountNum
);
thisAcct
=
newAcct
;
try
{
thisRep
.
update
(
thisCust
);
}
catch
(
IOException
ex
)
{
throw
new
IOException
();
}
catch
(
CustNotFoundException
ex
)
{
throw
new
CustNotFoundException
(
thisCust
.
getUsername
());
}
}
// returns true if everything goes ok; otherwise throws exceptions
public
boolean
makeDeposit
(
float
amount
)
throws
CustomerNoAccountException
,
AmountNotVerifiedException
,
CustomerNotAuthenticatedException
,
AccountNotFoundException
,
IOException
{
// checks to make sure thisCust is authenticated
if
(
thisCust
.
isAuthenticated
())
{
// checks verification system to verify amount
if
(
this
.
vs
.
confirmAmount
(
amount
))
{
// check to make sure that this customer actually has an account, in which
// case thisAcct is already populated
if
(
thisCust
.
getAccountNum
()
>
0
)
{
try
{
thisAcct
.
changeBalance
(
thisAcct
.
getBalance
(
thisCust
.
getAccountNum
())
+
amount
);
}
catch
(
IOException
ex
)
{
throw
new
IOException
()
;
}
catch
(
AccountNotFoundException
ex
)
{
throw
new
AccountNotFoundException
(
thisCust
.
getAccountNum
());
}
// return true
return
(
true
);
}
else
{
// customer doesn't have an account
throw
new
CustomerNoAccountException
(
thisCust
.
getUsername
());
}
}
else
{
// verification system says amount is not correct
throw
new
AmountNotVerifiedException
(
amount
);
}
}
else
{
// customer is not authenticated
throw
new
CustomerNotAuthenticatedException
(
thisCust
.
getUsername
());
}
}
// returns true if everything goes ok; otherwise throws exceptions
public
boolean
makeWithdrawal
(
float
amount
)
throws
CustomerNoAccountException
,
AmountNotVerifiedException
,
CustomerNotAuthenticatedException
,
InsufficientFundsException
,
AccountNotFoundException
,
IOException
{
float
currentBalance
;
// checks to make sure thisCust is authenticated
if
(
thisCust
.
isAuthenticated
())
{
// checks verification system to verify amount
if
(
this
.
vs
.
confirmAmount
(
amount
))
{
// check to make sure that this customer actually has an account, in which case
// thisAcct is already populated
if
(
thisCust
.
getAccountNum
()
>
0
)
{
try
{
currentBalance
=
thisAcct
.
getBalance
(
thisCust
.
getAccountNum
());
}
catch
(
IOException
ex
)
{
throw
new
IOException
();
}
catch
(
AccountNotFoundException
ex
)
{
throw
new
AccountNotFoundException
(
thisCust
.
getAccountNum
());
}
if
(
amount
<
currentBalance
)
{
try
{
thisAcct
.
changeBalance
(
thisAcct
.
getBalance
(
thisCust
.
getAccountNum
())
-
amount
);
}
catch
(
AccountNotFoundException
ex
)
{
throw
new
AccountNotFoundException
(
thisCust
.
getAccountNum
());
}
// return true
return
(
true
);
}
else
{
// customer doesn't have enough money in the account
throw
new
InsufficientFundsException
(
thisCust
.
getUsername
(),
amount
);
}
}
else
{
// customer doesn't have an account
throw
new
CustomerNoAccountException
(
thisCust
.
getUsername
());
}
}
else
{
// verification system says amount is not correct
throw
new
AmountNotVerifiedException
(
amount
);
}
}
else
{
// customer is not authenticated
throw
new
CustomerNotAuthenticatedException
(
thisCust
.
getUsername
());
}
}
// returns the balance of this customer's account, if the customer is authenticated
// and has an account
public
float
getBalance
()
throws
IOException
,
CustomerNoAccountException
,
AccountNotFoundException
{
float
balance
=
0
;
// checks to make sure thisCust is authenticated
if
(
thisCust
.
isAuthenticated
())
{
// check to make sure that this customer actually has an account, in which case
// thisAcct is already populated
if
(
thisCust
.
getAccountNum
()
>
0
)
{
try
{
balance
=
thisAcct
.
getBalance
(
thisCust
.
getAccountNum
());
}
catch
(
IOException
ex
)
{
throw
new
IOException
();
}
catch
(
AccountNotFoundException
ex
)
{
throw
new
AccountNotFoundException
(
thisCust
.
getAccountNum
());
}
}
else
{
// customer doesn't have an account
throw
new
CustomerNoAccountException
(
thisCust
.
getUsername
());
}
}
return
(
balance
);
}
//if this customer has an account, returns the AccountController object,
//otherwise throws an exception
public
AccountController
getAcct
()
throws
CustomerNoAccountException
{
if
(
hasAcct
)
{
return
thisAcct
;
}
else
{
throw
new
CustomerNoAccountException
(
thisCust
.
getUsername
());
}
}
// marks a customer as not authenticated
public
void
logout
()
{
// marks thisCust as not authenticated
thisCust
.
logout
();
}
}
BA Uncompressed/src/main/java/swsec/bank/controllers/AccountController.class
BA Uncompressed/src/main/java/swsec/bank/controllers/CustomerController.class
BA Uncompressed/src/main/java/swsec/bank/controllers/AccountController.java
BA Uncompressed/src/main/java/swsec/bank/controllers/AccountController.java
package
swsec
.
bank
.
controllers
;
import
swsec
.
bank
.
exceptions
.
AccountNotFoundException
;
import
swsec
.
bank
.
models
.
Account
;
import
swsec
.
bank
.
models
.
Admin
;
import
swsec
.
bank
.
services
.
repositories
.
AccountRepository
;
import
swsec
.
bank
.
services
.
repositories
.
AdminRepository
;
import
java
.
io
.
IOException
;
import
java
.
util
.
Random
;
public
class
AccountController
{
private
AccountRepository
thisRep
;
private
Account
thisAccount
;
private
Random
rnd
;
public
AccountController
(
int
accountNum
)
{
// every instance of a Controller needs a corresponding Repository and Model object
thisRep
=
new
AccountRepository
();
thisAccount
=
new
Account
();
rnd
=
new
Random
();
thisAccount
.
setAccountNum
(
accountNum
);
//might be 0 if there is no acct# yet
}
public
void
changeBalance
(
float
newBalance
)
throws
IOException
,
AccountNotFoundException
{
this
.
thisAccount
.
setCurrentBalance
(
newBalance
);
//put the new balance in the model object
try
{
this
.
thisRep
.
modifyBalance
(
thisAccount
,
newBalance
);
// put the new balance in the repository
}
catch
(
IOException
ex
)
{
throw
new
IOException
();
}
catch
(
AccountNotFoundException
accEx
)
{
throw
new
AccountNotFoundException
(
thisAccount
.
getAccountNum
());
}
}
public
int
newAccount
(
float
newBalance
)
{
// create new account number and add it to thisAccount
// use thisRep to write new account to the file
// return account #
//produces an integer between 1000 and 9999
int
newAccountNum
=
1000
+
(
rnd
.
nextInt
(
8999
));
thisAccount
.
setAccountNum
(
newAccountNum
);
thisAccount
.
setCurrentBalance
(
newBalance
);
thisRep
.
save
(
thisAccount
);
return
(
newAccountNum
);
}
public
float
getBalance
(
int
accountNum
)
throws
IOException
,
AccountNotFoundException
{
// look up the account number and return the associated balance
float
balance
=
0
;
try
{
balance
=
thisRep
.
getBalance
(
accountNum
);
}
catch
(
IOException
ex
)
{
throw
new
IOException
();
}
finally
{
return
(
balance
);
}
}
}
BA Uncompressed/src/main/java/swsec/bank/controllers/AdminController.class
__MACOSX/BA Uncompressed/src/main/java/swsec/bank/services/._repositories
BA Uncompressed/src/main/java/swsec/bank/services/VerificationSystem.class
BA Uncompressed/src/main/java/swsec/bank/services/UiService.class
BA Uncompressed/src/main/java/swsec/bank/services/VerificationSystem.java
BA Uncompressed/src/main/java/swsec/bank/services/VerificationSystem.java
package
swsec
.
bank
.
services
;
import
java
.
util
.
Random
;
/**
* Created by cseaman on 3/8/2016.
* This class simulates a physical system (e.g. an ATM or a teller) that can physically verify
* that money has changed hands. In a real scenario, the verification system would communicate
* with the rest of the application over a network, but here we are simulating it with a
* simple method call.
*/
public
class
VerificationSystem
{
Random
rand
;
public
VerificationSystem
()
{
rand
=
new
Random
();
}
public
boolean
confirmAmount
(
float
amount
)
{
return
(
rand
.
nextInt
(
9
)
>
0
);
// this will return true 90% of the time
}
}
BA Uncompressed/src/main/java/swsec/bank/services/UiService.java
BA Uncompressed/src/main/java/swsec/bank/services/UiService.java
package
swsec
.
bank
.
services
;
import
swsec
.
bank
.
controllers
.
AccountController
;
import
swsec
.
bank
.
controllers
.
AdminController
;
import
swsec
.
bank
.
controllers
.
CustomerController
;
import
swsec
.
bank
.
exceptions
.
AccountNotFoundException
;
import
swsec
.
bank
.
exceptions
.
AdminNotFoundException
;
import
swsec
.
bank
.
exceptions
.
AmountNotVerifiedException
;
import
swsec
.
bank
.
exceptions
.
CustNotFoundException
;
import
swsec
.
bank
.
exceptions
.
CustomerNoAccountException
;
import
swsec
.
bank
.
exceptions
.
CustomerNotAuthenticatedException
;
import
swsec
.
bank
.
exceptions
.
InsufficientFundsException
;
import
java
.
io
.
IOException
;
import
java
.
util
.
Scanner
;
public
class
UiService
implements
Runnable
{
CustomerController
thisCust
;
// represents the Customer currently interacting with the UI
// represents the Account belonging to the customer currently interacting with the UI
AccountController
thisAcct
;
AdminController
thisAdmin
;
// represents the Admin currently interacting with the UI
VerificationSystem
vs
=
new
VerificationSystem
();
public
UiService
()
{
//constructor doesn't really do anything
}
//This gets called by main() in class Runner
public
void
run
()
{
runUi
();
}
public
void
runUi
()
{
Scanner
scanner
=
null
;
boolean
quit
=
false
;
quit
=
initialLogin
();
// initialLogin returns true if user wants to quit
while
(
!
quit
)
{
quit
=
showMenu
();
// showMenu returns true if user wants to quit
}
if
(
scanner
!=
null
)
{
scanner
.
close
();
}
}
public
static
boolean
isBlackList
(
String
val
)
{
String
BLACK_LIST_INPUT
=
"*[]#$"
;
if
(
val
==
null
){
return
false
;
}
for
(
int
i
=
0
;
i
<
val
.
length
();
i
++
){
if
(
BLACK_LIST_INPUT
.
indexOf
(
val
.
charAt
(
i
))
>=
0
){
return
true
;
}
}
return
false
;
}
public
static
String
stripHtml
(
String
inStr
){
boolean
inTag
=
false
;
char
c
;
int
tagPos
=
0
;
StringBuffer
outStr
=
new
StringBuffer
();
int
len
=
inStr
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++
){
c
=
inStr
.
charAt
(
i
);
if
(
c
==
'<'
){
outStr
.
append
(
""
);
tagPos
=
0
;
inTag
=
true
;
}
if
(
inTag
==
false
){
outStr
.
append
(
c
);
}
if
(
c
==
'>'
){
inTag
=
false
;
if
(
tagPos
==
1
){
outStr
.
append
(
"<>"
);
}
}
tagPos
+=
1
;
}
return
outStr
.
toString
();
}
public
static
boolean
toString cleanseInput
(
String
input
){
if
(
isBlackList
(
input
))
{
System
.
out
.
println
(
"Your username or password contains an invalid character"
);
return
true
;
}
if
(
stripHtml
(
input
)){
System
.
out
.
println
(
"Your username or password contains an invalid character"
);
return
true
;
}
return
false
;
}
protected
boolean
initialLogin
()
{
// allow user to try to log in as many times as they want
boolean
wantsToQuit
=
false
;
boolean
loggedIn
=
false
;
String
inUsername
;
//the username typed in
String
inPassword
;
// the password typed in
Scanner
scanner
=
new
Scanner
(
System
.
in
,
"UTF-8"
);
while
(
!
wantsToQuit
&&
!
loggedIn
)
{
System
.
out
.
println
(
"Please type your username or EXIT to quit:"
);
inUsername
=
scanner
.
nextLine
();
while
(
cleanseInput
(
inUsername
)){
System
.
out
.
println
(
"Please type your username or EXIT to quit: "
);
inUsername
=
scanner
.
nextLine
();
}
wantsToQuit
=
(
inUsername
.
compareTo
(
"EXIT"
)
==
0
);
if
(
!
wantsToQuit
)
{
System
.
out
.
println
(
"Please type your password:"
);
inPassword
=
scanner
.
nextLine
();
while
(
cleanseInput
(
inPassword
)){
System
.
out
.
println
(
"Please type your password : "
);
inPassword
=
scanner
.
nextLine
();
}
loggedIn
=
true
;
// creates a new customer controller object, also authenticates
try
{
thisCust
=
new
CustomerController
(
inUsername
,
inPassword
);
}
catch
(
IOException
ex
)
{
System
.
out
.
println
(
"Something went wrong with our database. Let's try again..."
);
loggedIn
=
false
;
}
catch
(
CustNotFoundException
ex
)
{
System
.
out
.
println
(
"Username or password not found. Please try again."
);
loggedIn
=
false
;
}
}
}
if
(
wantsToQuit
)
{
return
true
;
}
else
{
return
false
;
}
}
// repeat menu until user wants to log out
protected
boolean
showMenu
()
{
Scanner
scanner
=
new
Scanner
(
System
.
in
,
"UTF-8"
);
// show menu, capture user's choice, and call methods to carry out user actions
System
.
out
.
println
(
"1. Create a new account"
);
System
.
out
.
println
(
"2. Make a deposit"
);
System
.
out
.
println
(
"3. Make a withdrawal"
);
System
.
out
.
println
(
"4. Get your balance"
);
System
.
out
.
println
(
"5. Log out"
);
System
.
out
.
print
(
"What would you like to do? "
);
String
token
=
scanner
.
nextLine
();
if
(
token
.
compareTo
(
"1"
)
==
0
)
{
newAccount
();
}
else
{
if
(
token
.
compareTo
(
"2"
)
==
0
)
{
makeDeposit
();
}
else
{
if
(
token
.
compareTo
(
"3"
)
==
0
)
{
makeWithdrawal
();
}
else
{
if
(
token
.
compareTo
(
"4"
)
==
0
)
{
getBalance
();
}
else
{
if
(
token
.
compareTo
(
"5"
)
==
0
)
{
logout
();
return
true
;
}
}
}
}
}
return
false
;
}
void
newAccount
()
{
Scanner
scanner
=
new
Scanner
(
System
.
in
,
"UTF-8"
);
Float
initialBalance
=
0.0f
;
int
accountNum
;
//first check to see if the customer already has an account
if
(
thisCust
.
hasAcct
)
{
System
.
out
.
println
(
"You already have an account. You can only have one."
);
return
;