0% found this document useful (0 votes)
25 views60 pages

Samir

This document appears to be a coursework assignment submitted by Samir Timalsina for the CS4001NI Programming module. It includes an introduction about Java, descriptions of the tools used (BlueJ, MS Word, Draw.io), class diagrams, pseudocode, method descriptions, testing details, and discussions of error detection. The assignment involves creating a GUI application for a bank using Java that implements debit and credit card transactions.

Uploaded by

alin basnet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views60 pages

Samir

This document appears to be a coursework assignment submitted by Samir Timalsina for the CS4001NI Programming module. It includes an introduction about Java, descriptions of the tools used (BlueJ, MS Word, Draw.io), class diagrams, pseudocode, method descriptions, testing details, and discussions of error detection. The assignment involves creating a GUI application for a bank using Java that implements debit and credit card transactions.

Uploaded by

alin basnet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 60

Module Code & Module Title

CS4001NI Programming

Assessment Type
30 % Individual Coursework

Semester
2022-23 Autumn

Student Name: Samir Timalsina


London Met ID:
College ID:
Assignment Due Date:
Assignment Submission Date:
Submitted To: Ujjwal Subedi

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

2. Tools used in this coursework.......................................................................................2

3. Class Diagrams.............................................................................................................4

3.1. Class Diagram of BankCard Class:........................................................................4

3.2. Class Diagram of DebitCard Class:........................................................................5

3.3. Class Diagram of CreditCard Class:.......................................................................6

3.4. Class Diagram of BankGUI:....................................................................................7

3.5 Class Diagram of Combined Classes:.....................................................................8

4. Pseudocode...................................................................................................................9

5. Method Descriptions....................................................................................................13

5.1. Method Description of BankGUI...........................................................................13

6. Testing.........................................................................................................................14

6.1. Test 1....................................................................................................................14

6.2. Test 2....................................................................................................................15

6.3 Test 3.....................................................................................................................21

7. Error Detection and Correction....................................................................................23

7.1. Syntax Error..........................................................................................................23

7.2. Semantic Error......................................................................................................24

7.3. Logical Error..........................................................................................................25

8. Conclusion...................................................................................................................26

Appendix..........................................................................................................................27

List Of Figures
Figure 1: BlueJ Logo..........................................................................................................2

Figure 2: Word Logo..........................................................................................................3

Figure 3: Draw.io Logo......................................................................................................3

Figure 4: Class Diagram of Bankcard................................................................................4

Figure 5: Class Diagram of DebitCard Class....................................................................5

Figure 6: Credit Class Diagram.........................................................................................6

Figure 7: Class diagram of BankGUI.................................................................................7

Figure 8: Combined class Diagram...................................................................................8

Figure 9: Command Prompt............................................................................................14

Figure 10: Adding Debit Card..........................................................................................16

Figure 11: Withdrawal......................................................................................................17

Figure 12: Card Added....................................................................................................18

Figure 13: Credit Limit Set...............................................................................................19

Figure 14: Card Cancelled...............................................................................................20

Figure 15: Card Not Available.........................................................................................22

Figure 16: Syntax Error....................................................................................................23

Figure 17: Syntax Error Correction..................................................................................23

Figure 18: Semantic Error...............................................................................................24

Figure 19: Semantic Error Correction..............................................................................24

Figure 20: Logical Error...................................................................................................25

Figure 21: Logical Error Correction.................................................................................25

Table of Tables
Table 1: Test 1.................................................................................................................11

Table 2: Test 2.................................................................................................................12

Table 3: Test 3.................................................................................................................18


CS4001NI PROGRAMMING

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

Java is a general-purpose, class-based, object-oriented programming language with low


implementation requirements. It is a computer platform for developing applications. As a
result, Java is quick, secure, and dependable. It is extensively utilized for Java
application development in laptops, data centers, gaming consoles, scientific
supercomputers, mobile phones, and other devices (Hartman, 2023).

Samir Timalsina
CS4001NI PROGRAMMING

2. Tools used in this coursework

BlueJ:

BlueJ is a Java integrated development environment. It was designed to teach


computer science students Object Oriented programming. It offers a user-friendly
interface for developing Java programs in an interactive visual environment. BlueJ users
may build new projects and import classes from other files. As with many of these
programs, source code is displayed with icons on other layers of the UI (knowledgeboat,
2022).

Figure 1: BlueJ Logo.

MS-Word

Microsoft hired Charles Simonyi in 1981 to create a word-processing program. The


original version came out in 1983. MS Word was initially unpopular due to its
significantly different appearance from WordPerfect, the leading word processor at the
time. However, Microsoft continuously improved Word throughout the years, including a
1985 version that could operate on a Mac. Word's second major version, in 1987,
offered a substantial feature increase as well as additional functionality such as support
for rich text format (RTF). With the debut of Windows 95 and Office 95, which included a
combined suite of office productivity software, Microsoft expanded its market share in
the word processor sector in 1995 (Rouse, 2022).
2

Samir Timalsina
CS4001NI PROGRAMMING

Figure 2: Word Logo.

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).

Figure 3: Draw.io Logo.

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.

3.1. Class Diagram of BankCard Class:

Figure 4: Class Diagram of Bankcard.

Samir Timalsina
CS4001NI PROGRAMMING

3.2. Class Diagram of DebitCard Class:

Yo pani paila bata

Figure 5: Class Diagram of DebitCard Class.

Samir Timalsina
CS4001NI PROGRAMMING

3.3. Class Diagram of CreditCard Class:

Yo pani paila bata

Figure 6: Credit Class Diagram

Samir Timalsina
CS4001NI PROGRAMMING

3.4. Class Diagram of BankGUI:

Figure 7: Class diagram of BankGUI

Samir Timalsina
CS4001NI PROGRAMMING

3.5 Class Diagram of Combined Classes:

Figure 8: Combined class Diagram

Samir Timalsina
CS4001NI PROGRAMMING

4. Pseudocode

Pseudocode is a fictitious and informal language that aids programmers in the


development of algorithms. Pseudocode is a "text-based" (algorithmic) detail design
tool. The rules of Pseudocode are rather simple. All statements demonstrating
"dependency" must be indented.

IMPORT javax swing IMPORT java awt IMPORT java.awt event

CREATE a class BankGUI which implements the interface ActionListener

DO

CREATE an ARRAYLIST

INITALIZE JFrame as jf INITALIZE JLabels INITALIZE JTextFields INITALIZE


JButtons INITALIZE JComboBoxes

CREATE a constructor as BankGUI

DO

INITIALIZE JFrame

INITIALIZE new JTextFields

SET Bounds

INITIALIZE new JComboBoxes

SET Bounds

INITIALIZE new JButtons

CALL addActionListener method of Button and pass the current object as a


parameter.

END DO

CREATE a method ActionPerfored with parameter ActionEvent e


9

Samir Timalsina
CS4001NI PROGRAMMING

DO

IF (e.getSource() is equals to jb1)

SET instrument _Name textfield value to instrument SET chargePerDay textfield


value to chargePerDay SET foundException is false

SET isRented is false

SHOW message saying, “Please fill up all the empty fields.”

END IF

DO

IF the source of the event is adddebitcard button then the following

condition is executed

DO

DECLARE a String variable ClientName and GET the text from

text field tfDclientname

DECLARE a String variable issuerBank and GET the text from

text field tfDissuerBank

DECLARE a String variable bankAcc and GET the text from

text field tfDbankaccount

DECLARE a String variable CardID and GET the text from

text field tfDcardid11

DECLARE a String variable PINnumber and GET the text from

text field tfD_pin

DECLARE a String variable balanceAmt and GET the text from

text field tfDbalance

DECLARE an int variable cardid and SET its initial value as 0

10

Samir Timalsina
CS4001NI PROGRAMMING

DECLARE an int variable PIN and SET its initial value as 0

DECLARE an int variable balance and SET its initial value as 0

DECLARE a boolean variable isadded and SET its value as false

IF ClientName textfield is equals to empty OR issuerBank text field is

equals to empty OR bankAcc text field is equals to empty OR CardID text field is
equals to empty OR

PINnumber text field is equals to empty OR balanceAmt text field is equals to


empty

GENERATE a warning dialog box

ELSE

DO

TRY

DO

PARSE CardID text field to int and SET cardid variable

PARSE PINnumber text field to int and SET PIN variable

PARSE balanceAmt text field to int and SET balance variable

FOR EACH BankCard object list in bList

DO

IF list's CardId is equals to cardid

SET isadded variable as true and BREAK the loop

IF isadded variable is equals to true

GENERATE a warning dialog box

ELSE

DO

11

Samir Timalsina
CS4001NI PROGRAMMING

CALL DebitCard object card equals to new DebitCard with parameters

balance, cardid, bankAcc, issuerBank, ClientName, and PIN

ADD object card to an arraylist bList

GENERATE a message dialog box as "Card Added"

CATCH NumberFormatException exception

GENERATE a warning dialog box as "Enter a valid value"

END DO

END DO

END DO

END DO

CREATE a main method

DO CREATE an object of class BankGUI

END DO

END DO

12

Samir Timalsina
CS4001NI PROGRAMMING

5. Method Descriptions

5.1. Method Description of BankGUI

Add Debit Card: This retrieves data from the GUI, then creates a debit card object and
adds it to an array list named bankcard.

Clear: This clears the fields.

Display: Console information about a connected class is provided.

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

Objective: First, Using the command prompt, verify


that the program can be compiled and
executed.

Action: To compile the code from the command


line. To execute the code.

Expected Result: Open the GUI

Actual Result: GUI opened.

Conclusion: Test is successful.

Table 1: Test 1.

Figure 9: Command Prompt

14

Samir Timalsina
CS4001NI PROGRAMMING

6.2. Test 2

Test no: 2

Objective: Adding a credit card, deleting a credit


card, setting a limit on a credit card, and
adding a debit card.

Action: Get all require field from GUI.

Expected Result: When a button is clicked, the GUI's input


value must be executed, and a popup
message must appear.

Actual Result When a button is clicked, the entered


value in the GUI is executed, and a
popup message is shown.

Conclusion. Successful.

Table 2: Test 2.

15

Samir Timalsina
CS4001NI PROGRAMMING

Figure 10: Adding Debit Card.

16

Samir Timalsina
CS4001NI PROGRAMMING

Figure 11: Withdrawal

17

Samir Timalsina
CS4001NI PROGRAMMING

Figure 12: Card Added.

18

Samir Timalsina
CS4001NI PROGRAMMING

Figure 13: Credit Limit Set

19

Samir Timalsina
CS4001NI PROGRAMMING

Figure 14: Card Cancelled

20

Samir Timalsina
CS4001NI PROGRAMMING

6.3 Test 3

Test no: 3

Objective: To see if the right dialog box displays


when no values are entered into the GUI
and when a string value is inserted into a
text field that accepts numeric values.

Action: Required values were entered in the


fields.

Expected Result: Dialog box will appear.

Actual Result The dialog box appears.

Conclusion. Successful.

Table 3: Test 3.

21

Samir Timalsina
CS4001NI PROGRAMMING

Figure 15: Card Not Available.

22

Samir Timalsina
CS4001NI PROGRAMMING

7. Error Detection and Correction

7.1. Syntax Error

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

The return type of the method was not mentioned.

public Credit_Card()

Figure 16: Syntax Error

Error Correction

It was corrected by adding return type.

public void Credit_Card()

Figure 17: Syntax Error Correction

23

Samir Timalsina
CS4001NI PROGRAMMING

7.2. Semantic Error

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

Datatypes were not mentioned.

Figure 18: Semantic Error

Error Correction

Datatypes for the particular methods were mentioned.

Figure 19: Semantic Error Correction

24

Samir Timalsina
CS4001NI PROGRAMMING

7.3. Logical Error

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

In place of semicolon other thing was inserted.

Figure 20: Logical Error

Error Correction

After semicolon is used.

Figure 21: Logical 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

Hartman, J., 2023. Guru99. [Online]


Available at: https://www.guru99.com/java-platform.html
[Accessed 07 05 2023].

Hope, C., 2020. Computer Hope. [Online]


Available at: https://www.computerhope.com/jargon/d/drawio.htm
[Accessed 07 05 2023].

knowledgeboat, 2022. knowledgeboat. [Online]


Available at: https://www.knowledgeboat.com/learn/icse-computer-applications-bluej-
class-10/lecture/ELKR8/bluej-introduction
[Accessed 07 05 2023].

Rouse, M., 2022. techopedia. [Online]


Available at: https://www.techopedia.com/definition/3840/microsoft-word
[Accessed 07 05 2023].

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;

public class BankGUI implements ActionListener

// Make ArrayList

ArrayList <BankCard> bList = new ArrayList <BankCard> ();

// Adding Components in frame

JFrame DebitCard,Credit_Card;

JLabel Debit_Title, Dcardid, Dclientname, Dbankaccount, Dbalance,

DissuerBank, D_pin, Dwithdrawamt, Dcardid1, DwithdrawalDate;

JLabel Credit_Title, CcardID, C_clientNAme, Cbankaccount, creditissuerbank,

Cbalance, C_CVC, Cinterestrate, CexpiryDate,

CcardID1, C_limit, Cgraceperiod;

28

Samir Timalsina
CS4001NI PROGRAMMING

JButton adddebitcard, withdrawfromdebitcard, debitdisplay, debitclear,

gotocreditbutton;

JButton addCredit_Card, setCredit_Limit, cancelCredit_Card,

creditdisplay, creditclear;

JComboBox CexpiryDate1, CexpiryDate2, CexpiryDate3;

JComboBox DwithdrawalDate1,DwithdrawalDate2,DwithdrawalDate3;

JTextField tfDcardid11, tfDclientname, tfDbankaccount, tfDbalance,

tfDissuerBank, tfD_pin, tfDwithdrawamt, tfDcardid111;

JTextField tfCcardID, tfC_clientNAme, tfCbankaccount, tfcreditissuerbank,

tfCbalance, tfC_CVC, tfCinterestrate, tfCcardID1, tfC_limit,

tfCgraceperiod;

// constructor created for GUI

public BankGUI()

DebitCard = new JFrame("DebitCard");

DebitCard.setVisible(true);

DebitCard.setLayout(null);

// GUI for Debit Card


29

Samir Timalsina
CS4001NI PROGRAMMING

Debit_Title = new JLabel("DEBIT CARD");

Debit_Title.setBounds(420,10,350,52);

Debit_Title.setFont(new Font("", Font.BOLD, 30));

Dcardid = new JLabel("Card ID");

Dcardid.setBounds(89,105,58,20);

tfDcardid11 = new JTextField();

tfDcardid11.setBounds(231,100,208,32);

Dclientname = new JLabel("Client Name");

Dclientname.setBounds(89,150,94,20);

tfDclientname = new JTextField();

tfDclientname.setBounds(231,150,208,32);

Dbankaccount = new JLabel("Bank Account");

Dbankaccount.setBounds(89,200,110,20);

tfDbankaccount = new JTextField();

tfDbankaccount.setBounds(231,200,208,32);

DissuerBank = new JLabel("Issuer Bank");

DissuerBank.setBounds(89,250,94,20);

tfDissuerBank = new JTextField();

tfDissuerBank.setBounds(231,250,208,32);

30

Samir Timalsina
CS4001NI PROGRAMMING

Dbalance = new JLabel("Balance balance");

Dbalance.setBounds(89,300,129,20);

tfDbalance = new JTextField();

tfDbalance.setBounds(231,300,208,32);

D_pin = new JLabel("PIN Number");

D_pin.setBounds(89,350,88,20);

tfD_pin = new JTextField();

tfD_pin.setBounds(231,350,208,32);

Dwithdrawamt = new JLabel("Withdrawal balance");

Dwithdrawamt.setBounds(550,260,150,20);

tfDwithdrawamt = new JTextField();

tfDwithdrawamt.setBounds(700,260,208,32);

Dcardid1 = new JLabel("Card ID");

Dcardid1.setBounds(550,105,58,15);

tfDcardid111 = new JTextField();

tfDcardid111.setBounds(700,100,208,32);

DwithdrawalDate = new JLabel("Date Of Withdrawal");

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 = new JComboBox(DayDebit);

DwithdrawalDate1.setBounds(700,185,72,32);

String[] MonthDebit =
{"January","February","March","April","May","June","July","August","September","Octobe
r","November","December"};

DwithdrawalDate2 = new JComboBox(MonthDebit);

DwithdrawalDate2.setBounds(780,185,72,32);

String[] YearDebit = {"2018","2019","2020","2021","2022","2023","2024"};

DwithdrawalDate3 = new JComboBox(YearDebit);

DwithdrawalDate3.setBounds(860,185,72,32);

adddebitcard = new JButton("Add Card");

adddebitcard.setBounds(230,430,160,32);

withdrawfromdebitcard = new JButton("Withdraw");

withdrawfromdebitcard.setBounds(615,330,160,32);

debitdisplay = new JButton("Display");

debitdisplay.setBounds(591,430,150,32);

32

Samir Timalsina
CS4001NI PROGRAMMING

debitclear = new JButton("Clear");

debitclear.setBounds(764,430,150,32);

gotocreditbutton = new JButton("Credit Card ➔");

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

// method for credit frame

public void Credit_Card()

Credit_Card = new JFrame("Credit_Card");

Credit_Card.setLayout(null);

Credit_Card.setVisible(true);

Credit_Title = new JLabel("CREDIT CARD");

Credit_Title.setBounds(370,13,350,52);

Credit_Title.setFont(new Font("", Font.BOLD, 30));

CcardID = new JLabel("Card ID");

CcardID.setBounds(89,95,58,20);

tfCcardID = new JTextField();

tfCcardID.setBounds(231,90,208,32);

C_clientNAme = new JLabel("Client Name");

C_clientNAme.setBounds(89,140,94,20);

tfC_clientNAme = new JTextField();

tfC_clientNAme.setBounds(231,140,208,32);

Cbankaccount = new JLabel("Bank Account");

Cbankaccount.setBounds(89,190,110,20);

tfCbankaccount = new JTextField();


35

Samir Timalsina
CS4001NI PROGRAMMING

tfCbankaccount.setBounds(231,190,208,32);

creditissuerbank = new JLabel("Issuer Bank");

creditissuerbank.setBounds(89,240,94,20);

tfcreditissuerbank = new JTextField();

tfcreditissuerbank.setBounds(231,240,208,32);

Cbalance = new JLabel("Balance balance");

Cbalance.setBounds(89,290,129,20);

tfCbalance = new JTextField();

tfCbalance.setBounds(231,290,205,32);

C_CVC = new JLabel("CVC Number");

C_CVC.setBounds(89,340,88,20);

tfC_CVC = new JTextField();

tfC_CVC.setBounds(231,340,205,32);

Cinterestrate = new JLabel("Interest Rate");

Cinterestrate.setBounds(93,390,105,20);

tfCinterestrate = new JTextField();

tfCinterestrate.setBounds(231,390,208,32);

CexpiryDate = new JLabel("Expiry Rate");

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 = new JComboBox(DayCredit);

CexpiryDate1.setBounds(230,440,82,32);

String[] MonthCredit =
{"January","February","March","April","May","June","July","August","September","Octobe
r","November","December"};

CexpiryDate2 = new JComboBox(MonthCredit);

CexpiryDate2.setBounds(310,440,82,32);

String[] YearCredit = {"2018","2019","2020","2021","2022","2023","2024"};

CexpiryDate3 = new JComboBox(YearCredit);

CexpiryDate3.setBounds(390,440,82,32);

CcardID1 = new JLabel("Card ID");

CcardID1.setBounds(532,95,58,20);

tfCcardID1 = new JTextField();

tfCcardID1.setBounds(650,95,208,32);

C_limit = new JLabel("Credit Limit");

C_limit.setBounds(532,150,92,20);

tfC_limit = new JTextField();


37

Samir Timalsina
CS4001NI PROGRAMMING

tfC_limit.setBounds(650,150,208,32);

Cgraceperiod = new JLabel("Grace Period");

Cgraceperiod.setBounds(532,200,107,20);

tfCgraceperiod = new JTextField();

tfCgraceperiod.setBounds(650,200,208,32);

addCredit_Card = new JButton("Add Card");

addCredit_Card.setBounds(175,510,219,32);

setCredit_Limit = new JButton("Set Limit");

setCredit_Limit.setBounds(520,280,150,32);

cancelCredit_Card = new JButton("Cancel Card");

cancelCredit_Card.setBounds(710,280,170,32);

creditdisplay = new JButton("Display");

creditdisplay.setBounds(590,400,120,32);

creditclear = new JButton("Clear All");

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

public void actionPerformed(ActionEvent e)

if(e.getSource()==gotocreditbutton)
40

Samir Timalsina
CS4001NI PROGRAMMING

Credit_Card();

// Debit card event handeling for add button

if(e.getSource()==adddebitcard)

String ClientName = tfDclientname.getText();

String issuerBank = tfDissuerBank.getText();

String bankAcc = tfDbankaccount.getText();

String CardID = tfDcardid11.getText();

String PINnumber = tfD_pin.getText();

String balanceAmt = tfDbalance.getText();

int cardid = 0;

int PIN = 0;

int balance = 0;

boolean isadded= false;

if (ClientName.equals("") || (issuerBank.equals("")) || (bankAcc.equals("")) ||


(CardID.equals("")) || (PINnumber.equals("")) || (balanceAmt.equals("")))

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);

for(BankCard list : bList)

if(list.getCardId() == cardid)

isadded= true;

break;

if(isadded== true)

JOptionPane.showMessageDialog(DebitCard,"Card in use");

else

DebitCard card = new


DebitCard(balance,cardid,bankAcc,issuerBank,ClientName,PIN);

bList.add(card);

JOptionPane.showMessageDialog(DebitCard,"Card Added");

42

Samir Timalsina
CS4001NI PROGRAMMING

catch(NumberFormatException c)

JOptionPane.showMessageDialog(DebitCard, "Enter a valid value");

// Debit card event handeling for withdraw button

else if(e.getSource()== withdrawfromdebitcard)

String CardID = tfDcardid111.getText();

String withdrawnAmt = tfDwithdrawamt.getText();

String PINnumber = tfD_pin.getText();

String Withdrawnday = DwithdrawalDate1.getSelectedItem().toString();

String Withdrawnmonth = DwithdrawalDate2.getSelectedItem().toString();

String Withdrawnyear = DwithdrawalDate3.getSelectedItem().toString();

String withdrawnDate = Withdrawnday + "/" + Withdrawnmonth + "/" +


Withdrawnyear;

int cardid = 0;

int PIN = 0;

int balance = 0;

if ((CardID.equals("")) || (PINnumber.equals("")) || (withdrawnAmt.equals("")))

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()) //

JOptionPane.showMessageDialog(DebitCard, "Card is not available");

else

for(BankCard list : bList)

if(list instanceof DebitCard)

44

Samir Timalsina
CS4001NI PROGRAMMING

DebitCard dca = (DebitCard)list;

if(dca.getCardId() == cardid)

if(dca.getHasWithdrawn() == true)

JOptionPane.showMessageDialog(DebitCard,"Card is already
used");

break;

else if(dca.getHasWithdrawn() == false)

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)

JOptionPane.showMessageDialog(DebitCard, "Enter valid


value","Warning", JOptionPane.WARNING_MESSAGE);

// Debit card event handeling for display button

else if(e.getSource()==debitdisplay)

for(BankCard list : bList)

if(list instanceof DebitCard)

DebitCard d = (DebitCard)list;

d.display();

JOptionPane.showMessageDialog(DebitCard, "Displayed in console");

// Debit card event handeling for clear button

46

Samir Timalsina
CS4001NI PROGRAMMING

else if(e.getSource() == debitclear)

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);

// Credit card event handeling for add button

else if(e.getSource()==addCredit_Card)

String ClientName = tfC_clientNAme.getText();

String issuerBank = tfcreditissuerbank.getText();

String bankAcc = tfCbankaccount.getText();

String CardID = tfCcardID.getText();

String CVC = tfC_CVC.getText();


47

Samir Timalsina
CS4001NI PROGRAMMING

String balanceAmt = tfCbalance.getText();

String interestRate = tfCinterestrate.getText();

String Expire_day = CexpiryDate1.getSelectedItem().toString();

String Expire_month = CexpiryDate2.getSelectedItem().toString();

String Expire_year = CexpiryDate3.getSelectedItem().toString();

String Expirydate = Expire_day + "/" + Expire_month + "/" + Expire_year;

int cardid = 0;

int Cvc = 0;

int balance = 0;

double Rate = 0;

boolean isadded= false;

if (ClientName.equals("") || (issuerBank.equals("")) || (bankAcc.equals("")) ||


(CardID.equals("")) || (CVC.equals("")) || (balanceAmt.equals("")) ||
(interestRate.equals("")))

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);

for(BankCard list : bList)

if(list.getCardId() == cardid)

isadded= true;

break;

if(isadded== true)

JOptionPane.showMessageDialog(Credit_Card,"Card already added");

else

CreditCard card= new


CreditCard(cardid,ClientName,issuerBank,bankAcc,balance,Cvc,Rate,Expirydate);

bList.add(card);

JOptionPane.showMessageDialog(Credit_Card,"Card added");

49

Samir Timalsina
CS4001NI PROGRAMMING

catch(NumberFormatException c)

JOptionPane.showMessageDialog(Credit_Card, "Enter valid value");

// Credit card event handeling for limit button

else if(e.getSource()== setCredit_Limit)

String CardID = tfCcardID1.getText();

String CardLimit = tfC_limit.getText();

String GracePeriod = tfCgraceperiod.getText();

int cardid = 0;

double Limit = 0;

int Period = 0;

if ((CardID.equals("")) || (CardLimit.equals("")) || (GracePeriod.equals("")))

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())

JOptionPane.showMessageDialog(Credit_Card, "The card is not found");

else

for(BankCard list : bList)

if(list instanceof CreditCard)

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;

else if(b.getIsGranted() == false)

b.setCreditLimit(Limit,Period);

JOptionPane.showMessageDialog(Credit_Card,"Card limit
set");

break;

else

JOptionPane.showMessageDialog(Credit_Card,"The card is not


available","Warning", JOptionPane.WARNING_MESSAGE);

catch(NumberFormatException c)

JOptionPane.showMessageDialog(Credit_Card, "Enter valid value


","Warning", JOptionPane.WARNING_MESSAGE);

52

Samir Timalsina
CS4001NI PROGRAMMING

// Credit card event handeling for cancel card button

else if(e.getSource() == cancelCredit_Card)

String CardID = tfCcardID1.getText();

int cardid = 0;

if(tfCcardID1.getText().isEmpty())

JOptionPane.showMessageDialog(Credit_Card, "Empty fields!!");

else

try

cardid = Integer.parseInt(CardID);

if(bList.isEmpty())

JOptionPane.showMessageDialog(Credit_Card,"The Card is not


available");

else

for(BankCard list : bList)

53

Samir Timalsina
CS4001NI PROGRAMMING

if(list instanceof CreditCard)

CreditCard cancel = (CreditCard)list;

if(cancel.getCardId()==(cardid))

if(cancel.getIsGranted() == true)

JOptionPane.showMessageDialog(Credit_Card, "The card is


canceled");

cancel.cancelCreditCard();

break;

else

JOptionPane.showMessageDialog(Credit_Card, "The card is not


available");

catch(NumberFormatException c)

54

Samir Timalsina
CS4001NI PROGRAMMING

JOptionPane.showMessageDialog(Credit_Card, "Enter valid value


","Warning", JOptionPane.WARNING_MESSAGE);

// Credit card event handeling for display button

else if(e.getSource()==creditdisplay)

for(BankCard list : bList)// iterating from an arraylist

if(list instanceof CreditCard)// testing the object as it is from instance class

CreditCard cd = (CreditCard)list;

cd.display();

JOptionPane.showMessageDialog(Credit_Card, "Displayed in
console");

// Event handeling for credit clear

else if(e.getSource() == creditclear)

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);

// calling main method

public static void main(String args[])

new BankGUI();

56

Samir Timalsina

You might also like