2.Instruction Then it will display the number of

2.Instruction to run
program

2.1 Open project

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

Open project Bank System then click on run proyect or press F6
on your keyboard.

 

2.2 Program choice

As it is a console run program a
window will appear and prompt the user to enter a choice number:

    
  1- CREATE A BANK ACCOUNT

       2- PRINT ALL ACCOUNTS

       3- DELETE ACCOUNT

       4- DEPOSIT SOME MONEY

       5- WITHDRAW SOME MONEY

       6- PRINT TRANSACTIONS

       0- EXIT

 

2.3 Create bank account

To create a new bank account press
number 1If choose 1 the program will prompt the user to enter a new account
number, name, address and opening balance. Then it will display a message This
account with account no: … is now opened and active…

Your account balance is now …

 

2.4 Print all accounts

To print all accounts, press number
2. It will display every account details that is stored (name, account number,
address, status, current balance and opening date).

 

2.5 Delete account

To delete an account press number
3. It will prompt the user to enter account number the user wants to delete. It
will display Deletion successful.

 

 

2.6 Deposit money

To make a deposit press number 4.
It will prompt the user to enter account number the user wants to deposit money
and the amount. Once finish it will display a message “Transaction added
successful”.

 

2.7 Withdraw money

To withdraw money press number 5 It
will prompt the user to enter account number the user wants to withdraw money
and the amount. Once finish it will display a message “Transaction added
successful”.

 

2.8 Print transactions

To print last six transactions
press number 6. It will prompt the user to enter from which account number the
user wants to display the transactions. Then it will display the number of
transactions, type, mount, before and after the transaction, date.

 

2.9 Exit

To exit the program, press 0. It
will display a message “Good Bye”.

 

 

 

 

 

 

 

 

 

 

 

 

 

3. Description

3.1 Bank Class

The Bank class is the interface of the program, it uses the TreeMap data structure to store new
accounts in ascending order created by the user input. TreeMap is a map implementation that keeps its entries sorted
according to the natural ordering of its keys or better still using a comparator if provided by the user at
construction time.

• private TreeMap accounts = new TreeMap() is a variable for creating new accounts.

•public void setAccounts(TreeMap
accounts) and public Account • getAccount(Integer
accountNumber) They serve to set and get values from class variables that
are defined as ‘private’, but these method are defined as ‘public’ because
security issues. 

• 
public TreeMap openNewAccount(TreeMap accounts, Account account) and public TreeMap removeAccount(TreeMap
accounts, Account account) will create and remove
new accounts and will be stored in the variable
account.  accounts.put(account.getAccountNo(), account).

•Treemap has a Set keyset() method that I used to store the account number from the user input.
The set cannot store duplicate values. The keyset will return a set view of the
keys contained in this map.

• The Bank class uses Scanner class which is a text scanner that can parse primitive
types and strings using regular expressions in other words it will allow the
user to read values of various types. •  Scanner class is used to read input from the keyboard. “system.in” is InputStream is connected to keyboard
input of console program, in this case Java.

• Scanner scan = new Scanner(System.in); it
is the constructor of Scanner with
argument System.in and will return a
reference to newly constructed object.

• I
used different methods of the Scanner class like nextInt() scans the next token of the input as a int.  , nextDouble()
scans the next token of the input as a double. and nextLine()
returns the rest of the current line, excluding any line separator
at the end.

• I
have created a set of instructions that will prompt the user to press a number
for each action they wish to proceed (from 0 to 6)

I
am using the Switch statement which
is mostly used with break statement it allows a variable to be tested for
equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.

Case 0: 
is System.exit(0) wich was set
up against a while loop, while the input wasn’t 0 it would do other statement
but if the input is 0 it will terminate the program with a “Good Bye” display.

Case 1: there is Boolean flag = false
to start the case. If false you can
proceed in create a new account number accountNo = scan.nextInt() which is
saved in the variable accountNo and Set
keySet =
bank.accounts.keySet() which is a Treemap
method, keyset will be stored in the
variable key. Once entered the
account holder name, address, balance the new account will be saved in the variable account. If flag true accountNo.equals(key) which means there is already a account number
with the same number. After the new account is created a message display will
appear “This account with account number:… is now opened and active, your
balance is…”

Case 2: is keySet =
bank.accounts.keySet() which will display all existing accounts, the for loop
will search for every keyset that is stored in the variable key that is saved in the accounts Treemap. It will also display the
position of the keyset.

Case 3: it starts with Boolean flag =
false to start the case. If false I
need to enter the account number I wish to delete from the system. The
for loop will search for the key, for(Integer
key: keySet) and if it matches a key
stored in the accounts variable (Treemap) then bank.removeAccounts(bank.removeAccount(bank.getAccounts(),
account))  it will remove the key.

If
flag = true which means id did not find the key it will display a message  “Account number is not present”.

Case 4:  If
false I need to enter the account number you wish to deposit money, the for
loop will search for every keyset that is stored in the variable key that is saved in the accounts Treemap. Once it founds the key if(accountNo.equals(key)) you need to
enter amount you wish to deposit and is stored in account.deposit(account, depositAmount). If Flag = true  it means the key doesn’t match so it will go
and a display message “Account number is not present”.

Case 5: If false I need to enter the account number you wish to withdraw
money, the for loop will search for every keyset that is stored in the variable
key that is saved in the accounts Treemap. Once it founds the key if(accountNo.equals(key)) you need to
enter amount you wish to withdraw and is stored in account.withdraw(account, withdrawtAmount). If Flag = true  it means the key doesn’t match so it will go
and a display message “Account number is not present”.

Case 6: will display last 6 transactions if (bank.accounts.containsKey(accountNo)) matches the key the user
just entered then it will display transaction details of that key (account.transactions).

Else will print “Input Error, enter
correct account number”.

 

 

3.2 Account Class

The Account class is where transactions are stored in the program, it
uses the LinkedList which
is a linear data structure where each element is a separate object. LinkedList is implementation
of the List.

• Queue
transactions = new LinkedList() is where new tranactions are
stored in the LinkedList

• Queue is a data structure interface
and is a subtype of the Collection interface. It represents an ordered list of
objects just like a List, but its intended use is slightly different. A queue
is designed to have elements inserted at the end of the queue, and elements
removed from the beginning of the queue (FIFO).

• The java.util.Date will allow me
to record the time the account was created.

• Is in this class where the
operations of the transactions are made like account balance, deposit withdraw
and where the program keeps the last 6 transactions.

• I started by importing
java.util.collections, Date, LinkedList, List and Queue and by creating
variables for account holder’s name(String), address(String), number(int),
status(String), balance(double) and date() then constructor and set and get
methods for the account Holder. Also get and set for Queue.

• @Override annotation is used when
we override a method.

• The toString() method returns the string representation of the
object to represent any object as string.

• public void
addTransaction(Transaction transaction) will add a new transacation to
transactions variable. If transactions size
is greater than five, the Queue method poll
retrieves and removes the head of the queue or returns null if queue is
empty. If not, the Queue method offer inserts an element to the queue.

• The deposit method will allow the user to deposit money it will
create variable transaction for new transaction then it will set the
transactions Id, type, amount and balance. If deposit is less than 0 it will display a message “amount should be greater than
0”. If not it will set the current balance which would be accountBalance +
depositAmount .

• transaction.setMoneyAfterTransaction(getAccountBalance())
will retrieve the new account balance.

• addTransaction(transaction) will
add the new transaction.

• Collections.sort((List)
transactions) will sort the transactions by the amount.

• The withdraw method is pretty much the same as the deposit method wthe only difference is
in accountBalance – withdrawAmount it will substract against the account
balance.

 

 

3.3 Transaction Account

public class Transaction implements
Comparable

The Transaction account is where
the program sorts the Transaction by implementing comparable interface. As you
can see I have implemented the Comparable interface in my Transaction class
because I want to sort the objects of this class.

• I have imported java.util.Date as
is required by specification to add a transaction date and by creating variables
for transaction’s description(String),
amount(double), Id(int), money before
transaction(double), money after
transaction(double) and date()
then constructor and set and get methods for the Transactions.

• this.transactionId =
transactionId +1 will start with number 
1 to display list when called otherwise will start with 0.

• The toString() method returns the string representation of the
object to represent any object as string.

• public int compareTo(Transaction
otherTransaction)

• Transaction other = (Transaction)
otherTransaction it will create a variable other and compare to transaction.

• return (int)
(other.amount-this.amount) will return the amount in descending order.

 

 

3.4 Purpose

The purpose of the bank class was
to be the interface o the program and where the accounts where stored.

The purpose of the account class
was to create the account details and is there where the transactions are
stored, and transactions operations are performed.

The purpose of the transaction
class is to create the transaction details and is there where the sorting of
the transaction by amount is done.

I have used different data
structure because I believe it give me a better outcome like I chose queue because
it would use the method FIFO and LinkedList will allow me to stored the
transactions.

Also I chose to use Treemap  because is a data structure to store new
accounts in ascending order created by the user input.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4. Testing (screen
shots)

4.1 Create new account

•Screen shot of program choices.
User have chosen to create a new account
by pressing 1.

 

 

 • New
account created.

 

 

 

 

4.2 Print all accounts

•Screen shot of all accounts. User have
chosen to print all accounts by
pressing 2.

 

 

 

 

 

 

 

4.3 Delete account

•Screen shot of deleted account.
User have chosen to delete account
by pressing 3.

•In this case the user chose to delete account number 2.

 

 

 

4.4 Deposit money

•Screen shot of deposit money. User
have chosen to deposit money into account
by pressing 4.

•In this case the user chose to deposit money into account number1 with amount 500.

 

 

 

 

 

 

 

4.5 Withdraw money

•Screen shot of withdraw money.
User have chosen to withdraw money into account
by pressing 5.

•In this case the user chose to withdraw money into account number1 with amount 50.

 

4.6 Print transactions
(Descending order)

•Screen shot of print transactions.
User have chosen to print transactions by
pressing 6.

•In this case there are 2
transactions one deposit and one withdraw sorted by transaction amount.

 

4.7 Exit

•Screen shot of exit program. User have
chosen to exit program by pressing 0.

 

 

 

4.8 Sorting (2nd
part)

•Screen shot of exit program
running the sorting algorithm (Bubble sort)

 

 

 

 

 

 

 

 

5. Implementation of data structure
and                     algorithm (2nd
part)

I created two classes for this 2nd
part of the coursework and I called them My
Queue and My Queue Test.  I chose to use LinkedList as a data
structure and I started from scratch as it was required.

• queue = new LinkedList(): I named my
variable queue.

• public int size(): to retrieve
number of elements on queue.

• public Integer first(): to get first
element on queue.

 • public Integer dequeue(): to remove first
element on queue.

• public void enqueue(Integer N): to
add element on queue.

 • for (Integer queue1 : queue) this loop will
print every  value in queue.

 

I also chose to use the Bubble Sort algorithm as is a simple
algorithm that works by constantly swapping the adjacent elements if they are
not in the correct order.

I used two specifics sources to do
this part of the coursework one exercise from the workshop and the other one
from the website which I will add them below.

 

GeeksforGeeks.
(2018). Bubble Sort – GeeksforGeeks. online Available at:
https://www.geeksforgeeks.org/bubble-sort/ Accessed 5 Jan. 2018.

 

Exercise 22.26 Solution: ListTest.java-Program
allows insertion and deletion anywhere in a linked list.

 

 

6. Reflection

I believe this is the most challenging
task I have been given in term of coursework for the complexity of the program
itself I have struggled a lot to make the classes work combinedly. I chose to
use the scanner class but I’m questioning myself if I made the correct decision
by not using GUI as per previous experience I felt I was more confident by
using it.  One of the problems I had when
using Queue was Collections.sort(transactions)
in account class it throws an error argument mismatch (queue cannot convert to list) to correct this error I had to Cast transactions to List. Furthermore,
I have encountered lots of problems trying to write a code that will reflect
what I was asked from the information provided in the coursework I believe I
could have probably wrote the code differently maybe more efficiently, but this
is a learning curve to me and I know a lot more now than I did before I started
this coursework. All classes are my work, but I have used loads of sources
mainly from the net where I saw some samples. I will add them bellow but because
they are a lot I will be adding some.

 

Reference

Java, C.,
I/O, J., Tutorial, C. and Singh, C. (2018). TreeMap in Java with Example.
online beginnersbook.com. Available at:
https://beginnersbook.com/2013/12/treemap-in-java-with-example/ Accessed 4
Jan. 2018.

www.javatpoint.com.
(2018). Java Comparable – javatpoint. online Available at:
https://www.javatpoint.com/Comparable-interface-in-collection-framework
Accessed 4 Jan. 2018.

www.javatpoint.com.
(2018). Java Map – javatpoint. online Available at:
https://www.javatpoint.com/java-map Accessed 4 Jan. 2018.

Java, C.,
I/O, J., Tutorial, C. and Singh, C. (2018). Comparable Interface in Java
with example. online beginnersbook.com. Available at: https://beginnersbook.com/2017/08/comparable-interface-in-java-with-example/
Accessed 4 Jan. 2018.

GeeksforGeeks.
(2018). Queue | Set 2 (Linked List Implementation) – GeeksforGeeks.
online Available at:
https://www.geeksforgeeks.org/queue-set-2-linked-list-implementation/ Accessed
4 Jan. 2018.

www.tutorialspoint.com.
(2018). Java The TreeMap Class. online Available at:
https://www.tutorialspoint.com/java/java_treemap_class.htm Accessed 4 Jan.
2018.

www.tutorialspoint.com.
(2018). java.util.TreeMap.keySet() Method Example. online Available
at: https://www.tutorialspoint.com/java/util/treemap_keyset.htm Accessed 4
Jan. 2018.

Codejava.net.
(2018). Java Map Collection Tutorial and Examples. online Available
at: http://www.codejava.net/java-core/collections/java-map-collection-tutorial-and-examples
Accessed 4 Jan. 2018.

Codejava.net.
(2018). Java Queue Collection Tutorial and Examples. online Available
at:
http://www.codejava.net/java-core/collections/java-queue-collection-tutorial-and-examples
Accessed 4 Jan. 2018.

scratch, C.
(2018). Creating a LinkedList class from scratch. online
Stackoverflow.com. Available at:
https://stackoverflow.com/questions/4066729/creating-a-linkedlist-class-from-scratch
Accessed 4 Jan. 2018.

Tutorials.jenkov.com.
(2018). Cite a Website – Cite This For Me. online Available at:
http://tutorials.jenkov.com/java-collections/queue.html Accessed 4 Jan. 2018.

java?, H.
(2018). How do I instantiate a Queue object in java?. online
Stackoverflow.com. Available at: https://stackoverflow.com/questions/4626812/how-do-i-instantiate-a-queue-object-in-java
Accessed 4 Jan. 2018.