java programmer only
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
;
}