1 | Page
Submission Coversheet
Student ID Number
CON16423545
Programme Title Computing Technologies Extended Degree
Module Title Object Oriented Programming
Module Code (listed on
QAC020C152A
Moodle and in LTAFP)
Module Convenor Tendai Mhlanga
Coursework Title Nation Narrow Application
Academic Declaration:
Students are reminded that the electronic copy of their essay may be checked, at
any point during their degree, with Turnitin or other plagiarism detection software
for plagiarised material.
Date
Word Count 1524
Submitted
05/12/2017
CON16423545
2 | Page
Table of Contents
1. Design and development ................................................................3
1.1. Accounts Common Data Class .................................................4
2.2 Subclasses ...................................................................................8
2.3 Enum Classes .............................................................................11
2.4 Transaction Class........................................................................11
2.5 Menu Class .................................................................................13
2.6 Main class ................................................................................... 25
2. Test .............................................................................................. 26
2.1 Initial test ..................................................................................... 26
2.2 Adjustments ................................................................................28
3. References ................................................................................... 30
4. Appendices................................................................................... 30
CON16423545
3 | Page
1. Design and development
Java is an object-oriented programming (OOP) language, one of the
most popular used all over the world, successfully accomplishing the
majority of companies requirements needs, as Deitel (2015) noted.
The image below shows the concept model, represented as a class
diagram for the Nation Narrow program, designed in Star UML (Unified
Modeling Language) a visual representation of software systems
(Banas, 2012).
Figure 1
Figure 1 consists of nine classes, each of it composed of attributes and
behaviours, among which two of them are enum type, one abstract, and
three subclasses. Each class, apart from enums, is encapsulated.
Encapsulation is one of the OOP concepts, where the global variables
are hidden from other classes, represented by “-” in class diagram and
by simple declared private in the source code. In addition, a private
variable has a direct connection with its method, which can be accessed
by other classes(Deitel, 2015).
Next, the key details will be discussed for each class together with
snapshots of code implementation.
CON16423545
4 | Page
1.1. Accounts Common Data Class
Deitel (2015) pointed that an abstract class, also known as a superclass
or parent class, is used as a template for other classes, more specific
subclasses, which inherit from it, however, these cannot instantiate
objects and are incomplete. In addition, the purpose of an abstract class
is to provide common attributes and behaviours for its subclasses. For
example, in Nation Narrow application has been designed the
AccountsCommonData as a superclass seeing that business and
personal accounts have common attributes such as address, account
number, balance etc. as well as actions: deposit money, shows
transactions or access some customer details etc. , all written in figure 2.
Figure 2
Nevertheless, this class intends only to share its variables and
behaviours with its subclasses, yet not to define objects of it.
CON16423545
5 | Page
Figure 3
Figure 3 provides the source code of the parent class variables declared
global as one of the requirements is to capture and store some customer
and accounts details (e.g. address, post code, overdraft …). Although
can be observed, few of the variables and the array list object are
declared final and the balance not, since it needs to be changed every
time the user perform an action such as withdraw, deposit or transfer.
However, a constructor needs to be defined to collect values.
Figure 4
The variables are encapsulated, therefore, getter methods must be
established to access the attributes values.
CON16423545
6 | Page
Figure 6
Figure 5
The requirements for calculating and recording deposits, withdraws and
transfers are achieved through the following methods:
Figure 7
CON16423545
7 | Page
Figure 8
The function transferTo is similarly to withdraw, the only difference is the
transaction type containing transfer value in figure 8 and withdraws
value in figure 7, same for the transferFrom procedure with deposit.
Going back to the transactions object, transactions class is its template,
about which will be discussed in section 2.4 of this report. Besides, the
object is stored in an array list because it is not known how many
transaction will be stored in the system. If a simple array would store this
object, would be necessary to set a fixed number of indexes, conducting
either to a restricted capacity of storage or larger, the last could occupy
more memory space and have empty slots, as well as could slow down
the application at the runtime (Deitel, 2015).
CON16423545
8 | Page
2.2 Subclasses
According to Cadenhead (2018), inheritance is a powerful tool for object-
oriented languages and gives the ability of subclasses to acquire the
attributes and behaviours of the parent class. Once with inheritance, the
polymorphism principle adapts by extending an abstract class,
completing and/or modifying the appearance or behaviour of an object
given to it particular features (Oracle, 2017).
Figure 9
For instance, the image above shows the inheritance hierarchy where
the subclasses take the common data, then new features are added for
each of them (polymorphism).
CON16423545
9 | Page
Figure 10 BusinessAccount
Figure 11 PersonalAccount
CON16423545
10 | P a g e
Figure 12 PersonalAccount
Figure 13 PersonalAccountsUnder16
Figure 14 PersonalAccountsUnder16
CON16423545
11 | P a g e
2.3 Enum Classes
Enum is a special type which can contain only a certain number of static
and unique variables. Moreover, they are constants, therefore are
defined in upper case letters. Using enum type it is always a good
practice when the possible variables are limited (Oracle, 2017).
Figure 15 Figure 16
This application has only three types of transactions and two types of
accounts plus a constraint for the personal account, therefore those
variables are stored into enum type.
Figure 17 Figure 18
2.4 Transaction Class
Figure 19
CON16423545
12 | P a g e
Transaction class contains the data that needs to be stored for each
transaction to meet the requirements of the system, respectively date
when a transaction was accessed, type of transaction, the amount and
the balance after each one.
Figure 20
Figure 21
CON16423545
13 | P a g e
2.5 Menu Class
The menu class has the purpose to display the menu as well as to
perform actions from the classes presented above to give the correct
output to the user.
Figure 22
The account number must be unique in the programme to be able to
distinguish one account from another. One way to achieve this is to
generate it together with all details required from the user in this class.
For this reason was declared global, storing it here when a new account
is created.
In the image above, a hash map has been declared, having the identifier
accounts. According to Cadenhead (2018), a hash map is a data
CON16423545
14 | P a g e
structure composed of two objects, in this case, Long and
AccountsCommonData, having the purpose to retrieve one or the other.
Moreover, the first object is acquainted with the key and second as the
value. In the event of having a large number of accounts, the hashmap
is more efficient and faster than an array list, for example. However, the
disadvantage of it is that does not guaranty that the objects retrieved in
the same order as they have been added (Oracle, 2017).
CON16423545
15 | P a g e
CON16423545
16 | P a g e
CON16423545
17 | P a g e
A special case for personal accounts, if the customer is under 16 years
old, the programme should collect one of its parent’s details as well as
have no overdraft available. For this, a simple if statement can
differentiate these accounts from each other after calculating the age
from date of birth. If the condition is true, the code executes the lines
inside the if statement, otherwise it ignores it and executes the else
code.
CON16423545
18 | P a g e
CON16423545
19 | P a g e
CON16423545
20 | P a g e
CON16423545
21 | P a g e
CON16423545
22 | P a g e
Here, the application must not allow withdrawing more than balance
amount and available overdraft, therefore an if statement is suitable for
this.
CON16423545
23 | P a g e
CON16423545
24 | P a g e
In order to display the right transactions in the right order, an array list
has been used, thus the transactions are easy to search through a for
loop finding the transaction index of the account number entered by the
user and access the transactions class methods.
The last requirement of this project is to display all accounts held by a
customer. In this particular case, inside the value, a unique entry from
customer details, respectively the id document, needs to be accessed
and compared with the input. Therefore, the accounts map has an inner
class to allow to enter the keys and values set. Then for each set is
chosen the value by getValue() method from Map.Entry class and is
compared the id value from accounts common data with the id input. If
these are equal, then all accounts containing that id are
found(Cadenhead, 2018).
CON16423545
25 | P a g e
2.6 Main class
The NationNarrowProject class is the main as it has the main method,
having the purpose to run the application.
CON16423545
26 | P a g e
2. Test
2.1 Initial test
Feature Input Expected output Result
(on screen)
headingMenu n/a heading Successful
principalMenu 1 openAccountSubmenu Successful
2 existingAccountSubmenu Successful
3 findCustomerAccounts Successful
4 Exit Successful
Any no up Error message Successful
to 278
openAccountSubmenu 1 createPAcc Successful
2 createBAcc Successful
3 principalMenu Successful
Any no up Error message Successful
to 278
n/a Open account date Not
Successful
createPAcc Personal personal details Successful
details
Date of age Successful
birth
Initial balance Successful
deposit
n/a account number Successful
n/a account type Successful
CON16423545
27 | P a g e
n/a overdraft = 500 Successful
If(user is under 16) Parents parents details Successful
details
n/a overdraft = 0 Successful
createBAcc Company company details Successful
details
Initial balance Successful
deposit
n/a account number Successful
n/a account type Successful
n/a overdraft = 20000 Successful
existingAccountSubmenu Account account number Successful
number
account type Successful
balance Successful
overdraft Successful
sort code Successful
Withdraw Account number, amount Successful
1, amount withdrawn, current
If(balance+overdraft >
balance
amount)
Else amount Insufficient funds Successful
Deposit Account number, amount Successful
2, amount
deposit, current balance
Transfer Account number transfer Successful
3, account
from, account number
to transfer,
transfer to, amount,
amount
current balance
CON16423545
28 | P a g e
If(balance + overdraft > 3, account Insufficient funds Not
amount) to transfer, Successful
amount
Transactions Initial deposit and the list Successful
transactions: for each
4
display date, type,
amount and balance
5 principalMenu Successful
6 Exit Successful
Any no up Error message Successful
to 278
findCustomerAccounts List accounts: type, Successful
account number, sort
id
code, balance and
overdraft
2.2 Adjustments
Feature Input Expected output Result
(on screen)
1. openAccountSubmenu n/a Open account date Successful
2. Transfer 3, account Insufficient funds Successful
to transfer,
If(balance + overdraft >
amount
amount)
1.
CON16423545
29 | P a g e
2.
CON16423545
30 | P a g e
3. References
Cadenhead R.(2018) Sams Teach Yourself Java in 24 hours.(8th Edition)
USA: Pearson.
Deitel P. and Deitel H.(2015) Java How to Program Early Objects. (10th
Edition) Essex: Pearson. Available at:
https://www.vlebooks.com/vleweb/Product/Index/463272?page=0
(Accessed: 18/11/2017).
Derek Banas (2012) UML 2.0 Class Diagrams [YouTube]. Available at:
https://youtu.be/3cmzqZzwNDM (Accessed: 02/12/2017).
Oracle (2017) The Java Tutorials. Available at:
https://docs.oracle.com/javase/tutorial/java/ (Accessed: 04/12/2017).
4. Appendices
NationNarrowProject. AccountsCommonDat BusinessAccount.java PersonalAccount.java PersonalAccountsUnd
java a.java er16.java
Transactions.java Menu.java
NationNarrowProject.
rar
CON16423545