Samir
Samir
CS4001NI Programming
Assessment Type
30 % Individual Coursework
Semester
2022-23 Autumn
I confirm that I understand my coursework needs to be submitted online via My Second Teacher under
the relevant module page before the deadline in order for my assignment to be accepted and marked. I
am fully aware that late submissions will be treated as non-submission and a mark of zero will be
awarded.
Table Of Contents
1. Introduction....................................................................................................................1
About Java.....................................................................................................................1
3. Class Diagrams.............................................................................................................4
4. Pseudocode...................................................................................................................9
5. Method Descriptions....................................................................................................13
6. Testing.........................................................................................................................14
8. Conclusion...................................................................................................................26
Appendix..........................................................................................................................27
List Of Figures
Figure 1: BlueJ Logo..........................................................................................................2
Table of Tables
Table 1: Test 1.................................................................................................................11
1. Introduction
The assignment is to use the Java programming language to create an application for
the Bank. A GUI is required in this project for debit and credit transactions. Several GUI
elements, including Jframe, Jlabel, Jpanel, Jtextfield, Jbutton, and Jcombobox, are used
to form the GUI. These elements, each of which serves a certain purpose, were
employed to finish the coursework. Several methods were used in this training. Object
casting and exception handling were used. Try and catch blocks were also used, kind of
the how the format exceptions were handled. Araylist was correctly implemented as
well.
About Java
Samir Timalsina
CS4001NI PROGRAMMING
BlueJ:
MS-Word
Samir Timalsina
CS4001NI PROGRAMMING
Draw.io
Draw.io, created by Seibert Media, is proprietary software for creating diagrams and
charts. You can use the software's automated layout option or design a custom layout.
They provide a wide range of shapes and hundreds of graphic components to let you
create a one-of-a-kind diagram or chart. The drag-and-drop tool makes it easy to
construct a visually appealing diagram or chart (Hope, 2020).
Samir Timalsina
CS4001NI PROGRAMMING
3. Class Diagrams
A class diagram is like a flowchart in that classes are represented as boxes, each with
three rectangles within. The top rectangle holds the class's name; the middle rectangle
contains the class's properties; and the bottom rectangle contains the class's methods,
commonly known as operations.
Samir Timalsina
CS4001NI PROGRAMMING
Samir Timalsina
CS4001NI PROGRAMMING
Samir Timalsina
CS4001NI PROGRAMMING
Samir Timalsina
CS4001NI PROGRAMMING
Samir Timalsina
CS4001NI PROGRAMMING
4. Pseudocode
DO
CREATE an ARRAYLIST
DO
INITIALIZE JFrame
SET Bounds
SET Bounds
END DO
Samir Timalsina
CS4001NI PROGRAMMING
DO
END IF
DO
condition is executed
DO
10
Samir Timalsina
CS4001NI PROGRAMMING
equals to empty OR bankAcc text field is equals to empty OR CardID text field is
equals to empty OR
ELSE
DO
TRY
DO
DO
ELSE
DO
11
Samir Timalsina
CS4001NI PROGRAMMING
END DO
END DO
END DO
END DO
END DO
END DO
12
Samir Timalsina
CS4001NI PROGRAMMING
5. Method Descriptions
Add Debit Card: This retrieves data from the GUI, then creates a debit card object and
adds it to an array list named bankcard.
Withdraw: Obtains information from the GUI, checks the ID and balance, and then
subtracts the requested amount from the available balance.
Add Credit Card: This function generated the credit card object and also updated the
bankcard array list with the information it had gleaned from the GUI.
Set: Before establishing the credit limit, this pulls data from the GUI.
Cancel: The GUI is used to access the data, the ID is checked, and the card is then
removed from the array list.
13
Samir Timalsina
CS4001NI PROGRAMMING
6. Testing
6.1. Test 1
Test No: 1
Table 1: Test 1.
14
Samir Timalsina
CS4001NI PROGRAMMING
6.2. Test 2
Test no: 2
Conclusion. Successful.
Table 2: Test 2.
15
Samir Timalsina
CS4001NI PROGRAMMING
16
Samir Timalsina
CS4001NI PROGRAMMING
17
Samir Timalsina
CS4001NI PROGRAMMING
18
Samir Timalsina
CS4001NI PROGRAMMING
19
Samir Timalsina
CS4001NI PROGRAMMING
20
Samir Timalsina
CS4001NI PROGRAMMING
6.3 Test 3
Test no: 3
Conclusion. Successful.
Table 3: Test 3.
21
Samir Timalsina
CS4001NI PROGRAMMING
22
Samir Timalsina
CS4001NI PROGRAMMING
Syntax errors are faults in language usage. Missing a comma or a quote mark, or
misreading a word, are examples of syntax mistakes. MATLAB will identify syntax
mistakes and display an error notice.
Error Detection
public Credit_Card()
Error Correction
23
Samir Timalsina
CS4001NI PROGRAMMING
A program with a semantic mistake can be compiled and run, but the outcome is
inaccurate. A missing semicolon in a program is an example of a syntax mistake
because the compiler will detect and report the issue.
Error Detection
Error Correction
24
Samir Timalsina
CS4001NI PROGRAMMING
A logic mistake is a bug in a program's source code that causes unexpected and
erroneous behaviour. A logic error is a sort of runtime fault that can cause a program to
provide inaccurate output. It may also cause the software to crash while in use.
Error Detection
Error Correction
25
Samir Timalsina
CS4001NI PROGRAMMING
8. Conclusion
Writing code and mastering programming languages are both aspects of programming.
The world employs a wide range of programming languages. Programmers construct
programs in several programming languages. Python, Java, and Oracle are just a
handful of the programming languages that are employed. This programming curriculum
completely covered the java programming language.
The GUI system is used in this course. This work has improved my understanding of
project management and programming. This has also helped me understand how a
business program operates. There were many questions and misconceptions during
this venture. The GUI components' proportions were also wrong. These concerns were
handled through internet research and discussions with academics. It was simpler to
define dimensions while using the Moqups online app. Initially, the scenario was
frequently ignored. It was not identified prior to the development of the code. This
strategy has been proved to be effective in increasing our understanding of how a
system works.
26
Samir Timalsina
CS4001NI PROGRAMMING
References
27
Samir Timalsina
CS4001NI PROGRAMMING
Appendix
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.*;
import java.awt.event.ActionListener;
// Make ArrayList
JFrame DebitCard,Credit_Card;
28
Samir Timalsina
CS4001NI PROGRAMMING
gotocreditbutton;
creditdisplay, creditclear;
JComboBox DwithdrawalDate1,DwithdrawalDate2,DwithdrawalDate3;
tfCgraceperiod;
public BankGUI()
DebitCard.setVisible(true);
DebitCard.setLayout(null);
Samir Timalsina
CS4001NI PROGRAMMING
Debit_Title.setBounds(420,10,350,52);
Dcardid.setBounds(89,105,58,20);
tfDcardid11.setBounds(231,100,208,32);
Dclientname.setBounds(89,150,94,20);
tfDclientname.setBounds(231,150,208,32);
Dbankaccount.setBounds(89,200,110,20);
tfDbankaccount.setBounds(231,200,208,32);
DissuerBank.setBounds(89,250,94,20);
tfDissuerBank.setBounds(231,250,208,32);
30
Samir Timalsina
CS4001NI PROGRAMMING
Dbalance.setBounds(89,300,129,20);
tfDbalance.setBounds(231,300,208,32);
D_pin.setBounds(89,350,88,20);
tfD_pin.setBounds(231,350,208,32);
Dwithdrawamt.setBounds(550,260,150,20);
tfDwithdrawamt.setBounds(700,260,208,32);
Dcardid1.setBounds(550,105,58,15);
tfDcardid111.setBounds(700,100,208,32);
DwithdrawalDate.setBounds(550,185,200,20);
31
Samir Timalsina
CS4001NI PROGRAMMING
String[] DayDebit =
{"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"};
DwithdrawalDate1.setBounds(700,185,72,32);
String[] MonthDebit =
{"January","February","March","April","May","June","July","August","September","Octobe
r","November","December"};
DwithdrawalDate2.setBounds(780,185,72,32);
DwithdrawalDate3.setBounds(860,185,72,32);
adddebitcard.setBounds(230,430,160,32);
withdrawfromdebitcard.setBounds(615,330,160,32);
debitdisplay.setBounds(591,430,150,32);
32
Samir Timalsina
CS4001NI PROGRAMMING
debitclear.setBounds(764,430,150,32);
gotocreditbutton.setBounds(410,500,200,32);
DebitCard.add(Debit_Title);
DebitCard.add(Dcardid);
DebitCard.add(Dclientname);
DebitCard.add(Dbankaccount);
DebitCard.add(DissuerBank);
DebitCard.add(Dbalance);
DebitCard.add(D_pin);
DebitCard.add(Dwithdrawamt);
DebitCard.add(Dcardid1);
DebitCard.add(DwithdrawalDate);
DebitCard.add(tfDcardid11);
DebitCard.add(tfDclientname);
DebitCard.add(tfDbankaccount);
DebitCard.add(tfDbalance);
DebitCard.add(tfDissuerBank);
DebitCard.add(tfD_pin);
33
Samir Timalsina
CS4001NI PROGRAMMING
DebitCard.add(tfDwithdrawamt);
DebitCard.add(tfDcardid111);
DebitCard.add(DwithdrawalDate1);
DebitCard.add(DwithdrawalDate2);
DebitCard.add(DwithdrawalDate3);
DebitCard.add(adddebitcard);
DebitCard.setBackground(new Color(243,243,234));
DebitCard.add(withdrawfromdebitcard);
DebitCard.add(debitdisplay);
DebitCard.add(debitclear);
DebitCard.add(gotocreditbutton);
gotocreditbutton.addActionListener(this);
adddebitcard.addActionListener(this);
withdrawfromdebitcard.addActionListener(this);
debitdisplay.addActionListener(this);
debitclear.addActionListener(this);
DebitCard.setSize(1000,600);
}
34
Samir Timalsina
CS4001NI PROGRAMMING
Credit_Card.setLayout(null);
Credit_Card.setVisible(true);
Credit_Title.setBounds(370,13,350,52);
CcardID.setBounds(89,95,58,20);
tfCcardID.setBounds(231,90,208,32);
C_clientNAme.setBounds(89,140,94,20);
tfC_clientNAme.setBounds(231,140,208,32);
Cbankaccount.setBounds(89,190,110,20);
Samir Timalsina
CS4001NI PROGRAMMING
tfCbankaccount.setBounds(231,190,208,32);
creditissuerbank.setBounds(89,240,94,20);
tfcreditissuerbank.setBounds(231,240,208,32);
Cbalance.setBounds(89,290,129,20);
tfCbalance.setBounds(231,290,205,32);
C_CVC.setBounds(89,340,88,20);
tfC_CVC.setBounds(231,340,205,32);
Cinterestrate.setBounds(93,390,105,20);
tfCinterestrate.setBounds(231,390,208,32);
CexpiryDate.setBounds(93,440,124,20);
36
Samir Timalsina
CS4001NI PROGRAMMING
String[] DayCredit =
{"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"};
CexpiryDate1.setBounds(230,440,82,32);
String[] MonthCredit =
{"January","February","March","April","May","June","July","August","September","Octobe
r","November","December"};
CexpiryDate2.setBounds(310,440,82,32);
CexpiryDate3.setBounds(390,440,82,32);
CcardID1.setBounds(532,95,58,20);
tfCcardID1.setBounds(650,95,208,32);
C_limit.setBounds(532,150,92,20);
Samir Timalsina
CS4001NI PROGRAMMING
tfC_limit.setBounds(650,150,208,32);
Cgraceperiod.setBounds(532,200,107,20);
tfCgraceperiod.setBounds(650,200,208,32);
addCredit_Card.setBounds(175,510,219,32);
setCredit_Limit.setBounds(520,280,150,32);
cancelCredit_Card.setBounds(710,280,170,32);
creditdisplay.setBounds(590,400,120,32);
creditclear.setBounds(780,400,120,32);
Credit_Card.add(Credit_Title);
Credit_Card.add(CcardID);
38
Samir Timalsina
CS4001NI PROGRAMMING
Credit_Card.add(C_clientNAme);
Credit_Card.add(Cbankaccount);
Credit_Card.add(creditissuerbank);
Credit_Card.add(Cbalance);
Credit_Card.add(C_CVC);
Credit_Card.add(Cinterestrate);
Credit_Card.add(CexpiryDate);
Credit_Card.add(CcardID1);
Credit_Card.add(C_limit);
Credit_Card.add(Cbankaccount);
Credit_Card.add(Cgraceperiod);
Credit_Card.add(tfCcardID);
Credit_Card.add(tfC_clientNAme);
Credit_Card.add(tfCbankaccount);
Credit_Card.add(tfcreditissuerbank);
Credit_Card.add(tfCbalance);
Credit_Card.add(tfC_CVC);
Credit_Card.add(tfCinterestrate);
Credit_Card.add(tfCcardID1);
Credit_Card.add(tfC_limit);
Credit_Card.add(tfCgraceperiod);
39
Samir Timalsina
CS4001NI PROGRAMMING
Credit_Card.add(CexpiryDate1);
Credit_Card.add(CexpiryDate2);
Credit_Card.add(CexpiryDate3);
Credit_Card.add(addCredit_Card);
Credit_Card.add(setCredit_Limit);
Credit_Card.add(cancelCredit_Card);
Credit_Card.add(creditdisplay);
Credit_Card.add(creditclear);
addCredit_Card.addActionListener(this);
setCredit_Limit.addActionListener(this);
cancelCredit_Card.addActionListener(this);
cancelCredit_Card.addActionListener(this);
creditclear.addActionListener(this);
Credit_Card.setResizable(false);
Credit_Card.setSize(1000,600);
// Event handeling
if(e.getSource()==gotocreditbutton)
40
Samir Timalsina
CS4001NI PROGRAMMING
Credit_Card();
if(e.getSource()==adddebitcard)
int cardid = 0;
int PIN = 0;
int balance = 0;
JOptionPane.showMessageDialog(DebitCard,"Empty Fields","Warning",
JOptionPane.WARNING_MESSAGE);
else
41
Samir Timalsina
CS4001NI PROGRAMMING
try
{ // convertig datatype
cardid = Integer.parseInt(CardID);
PIN = Integer.parseInt(PINnumber);
balance = Integer.parseInt(balanceAmt);
if(list.getCardId() == cardid)
isadded= true;
break;
if(isadded== true)
JOptionPane.showMessageDialog(DebitCard,"Card in use");
else
bList.add(card);
JOptionPane.showMessageDialog(DebitCard,"Card Added");
42
Samir Timalsina
CS4001NI PROGRAMMING
catch(NumberFormatException c)
int cardid = 0;
int PIN = 0;
int balance = 0;
43
Samir Timalsina
CS4001NI PROGRAMMING
JOptionPane.showMessageDialog(DebitCard,"Empty Fields!!","Warning",
JOptionPane.WARNING_MESSAGE);
else
try
// Converting datatype
cardid = Integer.parseInt(CardID);
PIN = Integer.parseInt(PINnumber);
balance = Integer.parseInt(withdrawnAmt);
if(bList.isEmpty()) //
else
44
Samir Timalsina
CS4001NI PROGRAMMING
if(dca.getCardId() == cardid)
if(dca.getHasWithdrawn() == true)
JOptionPane.showMessageDialog(DebitCard,"Card is already
used");
break;
dca.withdraw(balance,withdrawnDate,PIN);
JOptionPane.showMessageDialog(DebitCard,"Your withdrawal
request is done");
break;
else
JOptionPane.showMessageDialog(DebitCard,"Card not
found.","Warning", JOptionPane.WARNING_MESSAGE);
45
Samir Timalsina
CS4001NI PROGRAMMING
catch(NumberFormatException c)
else if(e.getSource()==debitdisplay)
DebitCard d = (DebitCard)list;
d.display();
46
Samir Timalsina
CS4001NI PROGRAMMING
tfDcardid111.setText("");
tfD_pin.setText("");
tfDcardid11.setText("");
tfDbankaccount.setText("");
tfDbankaccount.setText("");
tfDbalance.setText("");
tfDclientname.setText("");
tfDissuerBank.setText("");
tfDwithdrawamt.setText("");
DwithdrawalDate1.setSelectedIndex(0);
DwithdrawalDate2.setSelectedIndex(0);
DwithdrawalDate3.setSelectedIndex(0);
else if(e.getSource()==addCredit_Card)
Samir Timalsina
CS4001NI PROGRAMMING
int cardid = 0;
int Cvc = 0;
int balance = 0;
double Rate = 0;
JOptionPane.showMessageDialog(Credit_Card,"Empty fields!!","Warning",
JOptionPane.WARNING_MESSAGE);
else
try
// Converting datatype
cardid = Integer.parseInt(CardID);
48
Samir Timalsina
CS4001NI PROGRAMMING
Cvc = Integer.parseInt(CVC);
balance = Integer.parseInt(balanceAmt);
Rate = Double.parseDouble(interestRate);
if(list.getCardId() == cardid)
isadded= true;
break;
if(isadded== true)
else
bList.add(card);
JOptionPane.showMessageDialog(Credit_Card,"Card added");
49
Samir Timalsina
CS4001NI PROGRAMMING
catch(NumberFormatException c)
int cardid = 0;
double Limit = 0;
int Period = 0;
JOptionPane.showMessageDialog(Credit_Card,"Empty fields!!","Warning",
JOptionPane.WARNING_MESSAGE);
else
try
50
Samir Timalsina
CS4001NI PROGRAMMING
// Converting datatype
cardid = Integer.parseInt(CardID);
Period = Integer.parseInt(GracePeriod);
Limit = Double.parseDouble(CardLimit);
if(bList.isEmpty())
else
CreditCard b = (CreditCard)list;
if(b.getCardId() == cardid)
if(b.getIsGranted() == true)
JOptionPane.showMessageDialog(Credit_Card,"The card
limit reached");
51
Samir Timalsina
CS4001NI PROGRAMMING
break;
b.setCreditLimit(Limit,Period);
JOptionPane.showMessageDialog(Credit_Card,"Card limit
set");
break;
else
catch(NumberFormatException c)
52
Samir Timalsina
CS4001NI PROGRAMMING
int cardid = 0;
if(tfCcardID1.getText().isEmpty())
else
try
cardid = Integer.parseInt(CardID);
if(bList.isEmpty())
else
53
Samir Timalsina
CS4001NI PROGRAMMING
if(cancel.getCardId()==(cardid))
if(cancel.getIsGranted() == true)
cancel.cancelCreditCard();
break;
else
catch(NumberFormatException c)
54
Samir Timalsina
CS4001NI PROGRAMMING
else if(e.getSource()==creditdisplay)
CreditCard cd = (CreditCard)list;
cd.display();
JOptionPane.showMessageDialog(Credit_Card, "Displayed in
console");
tfCcardID1.setText("");
55
Samir Timalsina
CS4001NI PROGRAMMING
tfCgraceperiod.setText("");
tfCcardID.setText("");
tfC_clientNAme.setText("");
tfCbankaccount.setText("");
tfcreditissuerbank.setText("");
tfC_CVC.setText("");
tfCbalance.setText("");
tfCinterestrate.setText("");
tfCcardID1.setText("");
tfC_limit.setText("");
CexpiryDate1.setSelectedIndex(0);
CexpiryDate2.setSelectedIndex(0);
CexpiryDate3.setSelectedIndex(0);
new BankGUI();
56
Samir Timalsina