0% found this document useful (0 votes)
309 views101 pages

2017-18 A CS4001NI A2 CW Coursework NP01CP4A170082

This document describes a Java programming coursework that creates a GUI to store details of IT training courses. It includes an introduction describing programming concepts. The coursework adds a TrainingInstitute class that declares an event handler class and implements an ActionListener interface. The class contains a main method that executes a sample() method, which contains code to create buttons, text fields and labels to add and manage professional courses and certifications. The document also includes class diagrams, pseudocode, method descriptions, testing procedures and error handling techniques.

Uploaded by

hazel
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)
309 views101 pages

2017-18 A CS4001NI A2 CW Coursework NP01CP4A170082

This document describes a Java programming coursework that creates a GUI to store details of IT training courses. It includes an introduction describing programming concepts. The coursework adds a TrainingInstitute class that declares an event handler class and implements an ActionListener interface. The class contains a main method that executes a sample() method, which contains code to create buttons, text fields and labels to add and manage professional courses and certifications. The document also includes class diagrams, pseudocode, method descriptions, testing procedures and error handling techniques.

Uploaded by

hazel
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/ 101

Islington College

Programming
CS4001NI
Coursework 2

Submitted By: Submitted To:


Dibya Shrestha Mr.Bhim Bahadur Sunar
17031100 Lecturer, IT
L1C8 Programming
Date: 22 Apr, 2018
Word Count:-7086 Semester:Spring
Contents
1) Introduction.................................................................................................................1
2) Class Diagram............................................................................................................3
3) Pseudocode................................................................................................................5
4) Method Description...................................................................................................23
5) Testing......................................................................................................................25
5.1) Test No.1: Compiling program and running through command prompt...............25
5.2) Test showing the functions of buttons..................................................................27
5.2.1) Test No.2: Adding courses to Professional Course List................................30
5.2.2) Test No.3: Adding courses to Certification list...............................................31
5.2.3) Test No.4: Enrolling student to Professional Class.......................................33
5.2.4) Test No.5: Complete the Course...................................................................34
5.2.5) Test No.6: Enrolling for Certification..............................................................35
5.3) Test No.8: Test to display the message box when unsuitable values are entered
for the Course number.................................................................................................36
6) Error Detection and Correction.................................................................................43
6.1) Compiled Error......................................................................................................43
6.2) Syntax Error..........................................................................................................45
6.3) Syntax error.......................................................................................................46
7) Conclusion................................................................................................................48
8) Appendix 1................................................................................................................49
8.1) Code for Class (Course).......................................................................................49
8.2) Code for class(Professional).................................................................................50
8.3) Code for class(Certification).................................................................................55
8.4) Code for class(TrainingInstitute)...........................................................................58
9) Appendix 2................................................................................................................81
9.1) Class Diagram......................................................................................................81
9.1.1) Course (Parent Class)....................................................................................81
9.1.2) Professional....................................................................................................82
9.1.3) Certification....................................................................................................83
9.2) Pseudocode..........................................................................................................84
9.2.1) Class(Course)................................................................................................84
9.2.2) For Professional Subclass.............................................................................85
9.2.3) For Certification sub class..............................................................................88
9.3) Method Description...............................................................................................92
Bibliography.....................................................................................................................95
TABLE OF FIGURES

Figure 1: Design of the program........................................................................................2


Figure 2: Running the program through command prompt.............................................26
Figure 3: Adding course to Professional.........................................................................30
Figure 4: Adding course to Professional.........................................................................30
Figure 5: Displaying after adding courses to professional..............................................31
Figure 6: Adding course to certification...........................................................................31
Figure 7: Adding course to certification...........................................................................32
Figure 8: Displaying after adding course to certification.................................................32
Figure 9: Enrolling student to professional class.............................................................33
Figure 10: Displaying after enrolling to professional.......................................................33
Figure 11: Completing the course...................................................................................34
Figure 12: Enrolling student to certification class............................................................35
Figure 13: Displaying after enrolling student to certification class..................................35
Figure 14: Adding course to professional........................................................................39
Figure 15: Adding course to certification.........................................................................39
Figure 16: Displaying the message box when course number is greater than the list size
.........................................................................................................................................40
Figure 17: Displaying the message box when the course number entered is less than 0
.........................................................................................................................................40
Figure 18: Displaying the message box when course number entered is not available
professional......................................................................................................................41
Figure 19: Displaying the message box when course number entered is greater than the
list size.............................................................................................................................41
Figure 20: Displaying the message box when course number entered is not available for
certification.......................................................................................................................42
Figure 21: Error that occurs when package is not import to create array list..................43
Figure 22: Correction for error 6.1 figure 21....................................................................44
Figure 23: Error that occurs when try is used without catch...........................................45
Figure 24: Correction for error 6.2 figure 23....................................................................45
Figure 25: Error showing the problem when this keyword is not used............................46
Figure 26: Correction for error 6.3 figure 25....................................................................47
TABLE OF TABLES

Table 1: Class Diagram of class Training Institute............................................................4


Table 2: Method Diagram of class Training Institute.......................................................24
Table 3: Black box for compiling program through command prompt............................25
Table 4: Blackbox to show the functions of buttons........................................................29
Table 5: Blackbox to display the message when unsuitable values are entered for
professional......................................................................................................................38
CS4001N1 PROGRAMMING

1) Introduction

“A program is a set of instructions targeted to solve a particular problem that can be


unambiguously understood by the computer.” (Bart Baesens, Aimee Backiel, Seppe
vanden Broucke, 2015) Java is an object-oriented programming. Programming is an
activity of coding a program which is translated into machine level language that is
understood by the computer at the end by using complier or interpreter. Programming
are written step-wise as analysis, program design, program coding and translation to
machine language, testing, debugging, development and maintenance. (Bart Baesens,
Aimee Backiel, Seppe vanden Broucke, 2015)

The main aim and objectives of this coursework is to add the class
“TrainingInstitute” that declares an event handler class and specifies that the class
implements an ActionListener interface in which the GUI (Graphic User Interface) for
the first coursework is created that stores the details of IT courses in your IT training
courses. The class contains a main method that executes the method sample() that
contains code to create GUI and thus the GUI is appeared on the screen. the others
method is created to write code that implements the methods in listener interface for
various buttons of Professional and Certification class. The input object are stored in
the array named “list”. The GUI consists add, enroll, complete button to add objects,
enroll students and set the course completion status as complete for Professional class,
add, enroll button to add objects, enroll students for Certification class and display all
and clear button to display the detailed information and clear the objects. After the
completion of the coursework, it displays all the detailed information related with the
admission and certification of the students.

There was no special hardware required to make the following application but BLUE
J was used as a basic software. The coursework is divided into development part that
contains a new BlueJ project containing three classes (Course, Professional,
Certification and TrainingInstitute) and report writing part that was written in MS-Word.

1
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Figure 1: Design of the program

2
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

2) Class Diagram

TrainingInstitute
- professional : JLabel
- separator : JLabel
- courseName : JLabel
- instructorName : JLabel
- totalHours : JLabel
- courseNumber : JLabel
- studentName : JLabel
- enrolDate : JLabel
- courseFee : JLabel
- downPayment : JLabel
- roomNumber : JLabel
- dailyHour : JLabel
- certification : JLabel
- lblSeperator : JLabel
- lblCourseName : JLabel
- lblInstructorName : JLabel
- lblTotalHours : JLabel
- lblCourseNumber : JLabel
- lblCourseFee : JLabel
- lblStudentName : JLabel
- startDate : JLabel
- examDate : JLabel
- examCenter : JLabel
- txtCourseName :JTextField
- txtInstructorName :JTextField
- txtTotalHours :JTextField
- txtCourseNumber :JTextField
- txtStudentName :JTextField
- txtEnrolDate :JTextField
- txtCourseFee :JTextField
- txtDownPayment :JTextField
- txtRoomNumber :JTextField
- txtDailyHour :JTextField
- fieldCourseName :JTextField
- fieldInstructorName :JTextField
- fieldTotalHours :JTextField
- fieldCourseNumber :JTextField
- fieldCourseFee :JTextField
- fieldStudentName :JTextField
- txtStartDate :JTextField
- txtExamDate :JTextField

3
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

- txtExamCenter :JTextField
- btnAdd : JButton
- btnComplete : JButton
- btnEnrolStudent : JButton
- add : JButton
- enroll : JButton
- display : JButton
- clear : JButton
- f : JFrame
+ sample ( ) : void
+ actionPerformed (actionEvent e ) : void
+ addToProfessional ( ) : void
+ addToCertification ( ) : void
+ courseCompletion ( ) : void
+ EnrollToProfessional ( ) : void
+ enrolToCertification ( ) : void
+ display ( ) : void
+ clear ( ) : void
+ main (String[ ] args ) : void

Table 1: Class Diagram of class Training Institute

4
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

3) Pseudocode
Pseudocode is an informal program description that does not contain any syntax,
code or underlying technology considerations.

CALL sample ( ) {

DO

f=CREATE_FRAME();

f.setLayout(null);

professional= CREATE_LABEL ("Professional Course");

professional.setBounds(5,5,150,30);

f.add(professional);

seperator=CREATE_LABEL("-----------------------------------------------------------------------------
----------------------------------------------");

seperator.setBounds(5,3,500,50);

f.add(seperator);

courseName= CREATE_LABEL ("Course Name");

courseName.setBounds(6,35,100,30);

f.add(courseName);

txtCourseName=CREATE_TEXT FIELD(" ");

txtCourseName.setBounds(100,35,400,25);

f.add(txtCourseName);

instructorName= CREATE_LABEL ("Instructor Name");

5
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

instructorName.setBounds(6,65,100,30);

f.add(instructorName);

txtInstructorName= CREATE_TEXT FIELD ("");

txtInstructorName.setBounds(100,65,400,25);

f.add(txtInstructorName);

totalHours= CREATE_LABEL ("Total Hours");

totalHours.setBounds(6,95,100,25);

f.add(totalHours);

txtTotalHours= CREATE_TEXT FIELD ("");

txtTotalHours.setBounds(100,95,145,25);

f.add(txtTotalHours);

btnAdd= CREATE_BUTTON ("Add");

btnAdd.setBounds(380,125,116,30);

f.add(btnAdd);

courseNumber= CREATE_LABEL ("Course Number");

courseNumber.setBounds(6,160,100,30);

f.add(courseNumber);

txtCourseNumber= CREATE_TEXT FIELD ("");

txtCourseNumber.setBounds(100,160,145,25);

f.add(txtCourseNumber);

studentName= CREATE_LABEL ("Student Name");

6
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

studentName.setBounds(6,190,100,30);

f.add(studentName);

txtStudentName= CREATE_TEXT FIELD ("");

txtStudentName.setBounds(100,190,145,25);

f.add(txtStudentName);

enrolDate= CREATE_LABEL ("Enrol Date");

enrolDate.setBounds(250,190,100,30);

f.add(enrolDate);

txtEnrolDate= CREATE_TEXT FIELD ("");

txtEnrolDate.setBounds(335,190,165,25);

f.add(txtEnrolDate);

dailyHour= CREATE_LABEL ("Daily Hour");

dailyHour.setBounds(6,125,100,30);

f.add(dailyHour);

txtDailyHour= CREATE_TEXT FIELD ("");

txtDailyHour.setBounds(100,125,145,25);

f.add(txtDailyHour);

courseFee= CREATE_LABEL ("Course Fee");

courseFee.setBounds(250,95,100,30);

f.add(courseFee);

txtCourseFee= CREATE_TEXT FIELD ("");

7
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

txtCourseFee.setBounds(335,95,165,25);

f.add(txtCourseFee);

downPayment= CREATE_LABEL ("Down Payment");

downPayment.setBounds(6,220,100,30);

f.add(downPayment);

txtDownPayment= CREATE_TEXT FIELD ("");

txtDownPayment.setBounds(100,220,145,25);

f.add(txtDownPayment);

roomNumber= CREATE_LABEL ("Room Number");

roomNumber.setBounds(250,220,100,30);

f.add(roomNumber);

txtRoomNumber= CREATE_TEXT FIELD ("");

txtRoomNumber.setBounds(335,220,165,25);

f.add(txtRoomNumber);

btnComplete= CREATE_BUTTON ("Complete");

btnComplete.setBounds(250,255,100,30);

f.add(btnComplete);

btnEnrolStudent= CREATE_BUTTON ("Enrol Student");

btnEnrolStudent.setBounds(380,255,120,30);

f.add(btnEnrolStudent);

certification= CREATE_LABEL ("Certification Course");

8
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

certification.setBounds(5,300,150,30);

f.add(certification);

lblSeperator= CREATE_LABEL
("------------------------------------------------------------------------------------------------------------------
---------");

lblSeperator.setBounds(5,302,500,50);

f.add(lblSeperator);

lblCourseName= CREATE_LABEL ("Course Name");

lblCourseName.setBounds(6,335,100,30);

f.add(lblCourseName);

fieldCourseName= CREATE_TEXT FIELD ("");

fieldCourseName.setBounds(100,335,400,25);

f.add(fieldCourseName);

lblInstructorName= CREATE_LABEL ("Instructor Name");

lblInstructorName.setBounds(6,365,100,30);

f.add(lblInstructorName);

fieldInstructorName= CREATE_TEXT FIELD ("");

fieldInstructorName.setBounds(100,365,400,25);

f.add(fieldInstructorName);

lblTotalHours= CREATE_LABEL ("Total Hours");

lblTotalHours.setBounds(6,395,100,30);

f.add(lblTotalHours);

9
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

fieldTotalHours= CREATE_TEXT FIELD ("");

fieldTotalHours.setBounds(100,395,145,25);

f.add(fieldTotalHours);

add=new JButton("Add");

add.setBounds(380,485,116,30);

f.add(add);

lblCourseNumber= CREATE_LABEL ("Course Number");

lblCourseNumber.setBounds(6,520,100,30);

f.add(lblCourseNumber);

fieldCourseNumber= CREATE_TEXT FIELD ("");

fieldCourseNumber.setBounds(100,520,400,25);

f.add(fieldCourseNumber);

lblStudentName= CREATE_LABEL ("Student Name");

lblStudentName.setBounds(6,550,100,30);

f.add(lblStudentName);

fieldStudentName= CREATE_TEXT FIELD ("");

fieldStudentName.setBounds(100,550,400,25);

f.add(fieldStudentName);

lblCourseFee= CREATE_LABEL ("Course Fee");

lblCourseFee.setBounds(250,395,100,30);

f.add(lblCourseFee);

10
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

fieldCourseFee= CREATE_TEXT FIELD ("");

fieldCourseFee.setBounds(335,395,165,25);

f.add(fieldCourseFee);

startDate= CREATE_LABEL ("Start Date");

startDate.setBounds(6,580,100,30);

f.add(startDate);

txtStartDate= CREATE_TEXT FIELD ("");

txtStartDate.setBounds(100,580,145,25);

f.add(txtStartDate);

examDate= CREATE_LABEL ("Exam Date");

examDate.setBounds(250,580,100,30);

f.add(examDate);

txtExamDate= CREATE_TEXT FIELD ("");

txtExamDate.setBounds(335,580,165,25);

f.add(txtExamDate);

examCenter= CREATE_LABEL ("Exam Center");

examCenter.setBounds(6,610,100,30);

f.add(examCenter);

txtExamCenter= CREATE_TEXT FIELD ("");

txtExamCenter.setBounds(100,610,400,25);

f.add(txtExamCenter);

11
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

certificate= CREATE_LABEL ("Awarded By");

certificate.setBounds(6,425,100,30);

f.add(certificate);

txtCertificate= CREATE_TEXT FIELD ("");

txtCertificate.setBounds(100,425,400,25);

f.add(txtCertificate);

validity= CREATE_LABEL ("Validity");

validity.setBounds(6,455,100,30);

f.add(validity);

txtValidity= CREATE_TEXT FIELD ("");

txtValidity.setBounds(100,455,400,25);

f.add(txtValidity);

enrol= CREATE_BUTTON ("Enrol Student");

enrol.setBounds(380,640,120,30);

f.add(enrol);

display= CREATE_BUTTON ("Display All");

display.setBounds(250,700,100,30);

f.add(display);

clear=CREATE_BUTTON("Clear");

clear.setBounds(380,700,120,30);

f.add(clear);

12
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

btnAdd.addActionListener(this);

add.addActionListener(this);

display.addActionListener(this);

btnEnrolStudent.addActionListener(this);

enrol.addActionListener(this);

clear.addActionListener(this);

btnComplete.addActionListener(this);

f.setVisible(true);

f.setSize(600,900);

f.setLocationRelativeTo(null);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

END DO

CALL actionPerformed (ActionEvent e)

DO

If (e.getSource()=btnAdd)

DO

CALL addToProfessional()

END DO

if (e.getSource()=add)

DO

CALL addToCertification()

13
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

END DO

if (e.getSource()=btnComplete)

DO

CALL courseCompletion()

END DO

if (e.getSource()=btnEnrolStudent)

DO

CALL EnrolToProfessional()

END DO

if (e.getSource()=enrol)

DO

CALL enrolToCertification()

END DO

if (e.getSource()==display){

DO

CALL display()

END DO

if (e.getSource()=clear)

DO

CALL clear()

END DO

14
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

END DO

CALL addToProfessional()

DO

Try

DO

String courseName=txtCourseName.getText();

String instructorName=txtInstructorName.getText();

int courseFee=Integer.parseInt(txtCourseFee.getText());

int totalHours=Integer.parseInt(txtTotalHours.getText());

int dailyHour=Integer.parseInt(txtDailyHour.getText());

Professional pobj=new
Professional(courseName,instructorName,courseFee,totalHours,dailyHour

list.add(pobj)

displays add to professional message

END DO

catch(NullPointerException nu)

DO

Display an error message

END DO

catch(Exception exc)

DO

15
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Display an error message

END DO

END DO

CALL addToCertification()

DO

Try

DO

String courseName=fieldCourseName.getText();

String instructorName=fieldInstructorName.getText();

int totalHours=Integer.parseInt(fieldTotalHours.getText());

int courseFee=Integer.parseInt(fieldCourseFee.getText());

String cerificateAwardedBy=txtCertificate.getText();

String validity=txtValidity.getText();

Certification cobj=new
Certification(courseName,instructorName,totalHours,courseFee,cerificate
AwardedBy,validity);

list.add(cobj);

display add to certification message

END DO

catch(NullPointerException po)

DO

Display an error message

16
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

END DO

catch(Exception ex)

DO

Display an error message

END DO

END DO

CALLcourseCompletion()

DO

Try

DO

int courseNum=Integer.parseInt(txtCourseNumber.getText());

Professional pro=(Professional)list.get(courseNum);

if(pro.getCourseStarted()==true)

DO

if(pro instanceof Professional)

DO

pro.courseCompletion();

display course completion message

END DO

Else

DO

Display course not available message

END DO

17
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

END DO

Else

DO

Display course hasnot started message

END DO

END DO

catch(NullPointerException po)

DO

Display error message

END DO

catch(Exception ex)

DO

Display error message

END DO

END DO

CALL EnrolToProfessional()

DO

Try

DO

int pcourseNumber=Integer.parseInt(txtCourseNumber.getText());

if (pcourseNumber < list.size() && pcourseNumber>=0)

DO

Course c=(Course)list.get(pcourseNumber);

if(c instanceof Professional)

DO

18
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

String studentName=txtStudentName.getText();

String enrolDate=txtEnrolDate.getText();

int downPayment=Integer.parseInt(txtDownPayment.getText());

String roomNumber=txtRoomNumber.getText();

Professional pr=((Professional)c);

pr.enrollment(studentName,enrolDate,downPayment,roomNumber);

display enrolled message

END DO

Else

DO

Display course not available for professional message

END DO

Else

DO

Display entered course not available message

END DO

END DO

catch(NullPointerException n)

DO

Display error message

END DO

catch(Exception exce)

DO

Display error message

END DO

19
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

END DO

CALL enrolToCertification()

DO

Try

DO

int ccourseNumber=Integer.parseInt(fieldCourseNumber.getText());

if (ccourseNumber < list.size() && ccourseNumber >= 0)

DO

Course c=list.get(ccourseNumber);

if(c instanceof Certification)

DO

String studentName=fieldStudentName.getText();

String startDate=txtStartDate.getText();

String examDate=txtExamDate.getText();

String examCenter=txtExamCenter.getText();

Certification cer=((Certification)c);

cer.enrollingForCertificationCourse(studentName,startDate,exa
mDate,examCenter);

display error message

END DO

Else

DO

Display course not available message

END DO

Else

20
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

DO

Display course not available message

END DO

END DO

catch(NullPointerException n)

DO

Display error message

END DO catch(Exception ne)

DO

Display error message

END DO

CALL display()

DO

for(Course c:list)

if(c instanceof Professional)

DO

Professional p=(Professional) c;

p.display()

END DO

if(c instanceof Certification)

DO

Certification ce=(Certification) c;

ce.display(); }

END DO

END DO

21
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

CALL clear()

DO

txtCourseName.setText("");

txtInstructorName.setText("");

txtTotalHours.setText("");

txtCourseNumber.setText("");

txtStudentName.setText("");

txtEnrolDate.setText("");

txtCourseFee.setText("");

txtDownPayment.setText("");

txtRoomNumber.setText("");

txtDailyHour.setText("");

fieldCourseName.setText("");

fieldInstructorName.setText("");

fieldTotalHours.setText("");

fieldCourseNumber.setText("");

fieldCourseFee.setText("");

fieldStudentName.setText("");

txtStartDate.setText("");

txtExamDate.setText("");

txtExamCenter.setText("");

txtCertificate.setText("");

txtValidity.setText("");

END DO

CALL(String[] args)

22
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

DO

new TrainingInstitute().sample();

END DO

4) Method Description
A method in Java is a block of statements that has a name and can be
executed by calling it from some other place in your program.. Every program
must have at least one method to accomplish any work. (Veer, 2004)

TrainingInstitute
sample( )
This method is used to create a GUI for the first part of coursework that stores the details of IT courses
in your IT training courses.
actionPerformed (action event e )
This method is created to call the methods that implements the methods in listener interface for various
buttons for Professional and Certification class
addToProfessional ( )
This method is used to add the new objects to the professional class and displays the add message.

addToCertification ( )
This method is used to add new objects to the certification class and displays the add message

CourseCompletion ( )
This method is used to make the status of course complete and displaying the course completion
message.
EnrollToProfessional ( )
This method is used to enroll the new students to the class Professional

23
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

enrolToCertification ( )
This method is used to enroll the new students to the class Certification.

Display ( )
This method is used to displays all the information related to professional and certification class

Clear ( )
This method is used to clear all the text field to add new objects.

main (String [ ] args )


This is the main method of the class in which the sample( ) method is called to add new objects.

Table 2: Method Diagram of class Training Institute

24
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

5) Testing

5.1) Test No.1: Compiling program and running through command prompt

Objective Command prompt was opened and the path was set

Action Open command prompt

C:\Users\Dell>set path="C:\Program Files\Java\jdk\bin";

C:\Users\Dell>cd desktop

C:\Users\Dell\Desktop>cd System Code

C:\Users\Dell\Desktop\System Code>javac
TrainingInstitute.java

C:\Users\Dell\Desktop\System Code>java TrainingInstitute

Expected Result The program will be compiled and the GUI will be created
and will be displayed on the screen

Actual Result The program was compiled and the GUI was created and
was displayed on the screen

Conclusion Test was successful.

Table 3: Black box for compiling program through command prompt

25
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Figure 2: Running the program through command prompt

26
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

5.2) Test showing the functions of buttons


Objective Set the value for professional for adding course
Set the value for professional for adding course
Set the value for Certification for adding course
Set the value for Certification for adding course
Set the value for Professional for enrolling students
Check the completion of course
Set the value for Certification for enrolling students
Set the value for Certification for enrolling students

Action 5.2.1) addToProfessional was called;


courseName=”computing”
instructorName=”jackson”
courseFee=1000000
totalHours=100
dailyHour=1
Add Button was clicked

5.2.2) addToProfessional was called;


courseName=”networking”
instructorName=”daniel”
courseFee=900000
totalHours=50
dailyHour=3
Add Button was clicked

5.2.3) addToCertification was called;


courseName=”logic”
instructorName=”mark”
totalHours=48
courseFee=800000
certificateAwardedBy=”LMU”
validTill=”2020/1/1”
Add Button was clicked

27
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

5.2.4) addToCertification was called;


courseName=”hardware”
instructorName=”ten”
totalHours=60
courseFee=500000
certificateAwardedBy=”T.U”
validTill=”2020/55”
Add Button was clicked

5.2.5) EnrolToProfessional was called;


Course Number = 0
Student Name =”lucas”
Down Payment =10000
Enroll Date =”2018/4/4”
Room Number =100

Enroll Student Button was clicked

5.2.6) Complete Button was clicked

5.2.7) enrolToCertification was called;


Course Number = 3
Student Name =”mark”
Start Date =”2018/44”
Exam Date =”2018/9/9”
Exam Center =”james College”

Enroll Student Button was clicked

Expected Result 1) Object will be created and value will be assign and a dialog box is
appeared with message “Congratulations!!! computing is added
professional. Press Ok to add"
2) Object will be created and value will be assign and a dialog box is
appeared with message “Congratulations!!! networking is added
professional. Press Ok to add"

3) Object will be created and value will be assign and a dialog box is
appeared with message “Congratulations!!! logic is added

28
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

certification. Press Ok to add"

4) Object will be created and value will be assign and a dialog box is
appeared with message “Congratulations!!! hardware is added
certification. Press Ok to add"
5) Course completion process will be done and a dialog box is
appeared with message “the course has been completed”
6) Object will be created and value will be assign and a dialog box is
appeared with message “Congratulations!!! lucas has been
enrolled to professional!!!"
7) Object will be created and value will be assign and a dialog box is
appeared with message “Congratulations!!! mark has been
enrolled to certification!!!"

Actual Result 1) Object was created and value was assigned and a dialog box was
appeared with message “Congratulations!!! computing is added
professional. Press Ok to add"
2) Object was created and value was assigned and a dialog box was
appeared with message “Congratulations!!! networking is added
professional. Press Ok to add"
3) Object was created and value was assigned and a dialog box was
appeared with message “Congratulations!!! logic is added
certification. Press Ok to add"
4) Object was created and value was assigned and a dialog box was
appeared with message “Congratulations!!! hardware is added
certification. Press Ok to add"
5) Course completion process is done and a dialog box is appeared
with message “the course has been completed”
6) Object was created and value was assigned and a dialog box was
appeared with message “Congratulations!!! lucas has been
enrolled to professional!!!"
7) Object was created and value was assigned and a dialog box was
appeared with message “Congratulations!!! mark has been
enrolled to certification!!!"

Conclusion Test was successful.

Table 4: Blackbox to show the functions of buttons

29
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

5.2.1) Test No.2: Adding courses to Professional Course List

Figure 3: Adding course to Professional

Figure 4: Adding course to Professional

30
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Figure 5: Displaying after adding courses to professional


5.2.2) Test No.3: Adding courses to Certification list

Figure 6: Adding course to certification

31
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Figure 7: Adding course to certification

Figure 8: Displaying after adding course to certification

32
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

5.2.3) Test No.4: Enrolling student to Professional Class

Figure 9: Enrolling student to professional class

Figure 10: Displaying after enrolling to professional

33
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

5.2.4) Test No.5: Complete the Course

Figure 11: Completing the course

34
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

5.2.5) Test No.6: Enrolling for Certification

Figure 12: Enrolling student to certification class

Figure 13: Displaying after enrolling student to certification class

35
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

5.3) Test No.8: Test to display the message box when unsuitable values are
entered for the Course number

Objective Set the value for professional for adding course


Set the value for Certification for adding course
Set the value for Professional for enrolling student
Set the value for Professional for enrolling student
Set the value for Professional for enrolling student
Set the value for certification for enrolling student
Set the value for certification for enrolling student

Action 1) addToProfessional was called;

Course Name=”multimedia”
Instructor Name=”hobi”
Course Fee=800000
Total Hours=200
Daily Hour=1
Add Button of Professional was clicked

2) addToCertification was called;


course Name=”logic”
instructor Name=”TOP”
total Hours=150
course Fee=157890
certificate Awarded By=”LMU”
valid Till=”2020/5/6”
Add Button of certification was clicked

3) EnrolToProfessional was called;


Course Number = 3
Student Name =”taehyung”
Down Payment =50000
Enroll Date =”2018/2/2”
Room Number =102
Enroll Student Button of Professional was clicked

36
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

4) EnrolToProfessional was called;


Course Number = -1
Student Name =”lucas”
Down Payment =10000
Enroll Date =”2018/3/3”
Room Number =103
Enroll Student Button of Professional was clicked

5) EnrolToProfessional was called;


Course Number = 1
Student Name =”winwin”
Down Payment =100000
Enroll Date =”2018/3/5”
Room Number =110
Complete Button of Professional was clicked

6) enrolToCertification was called;


Course Number = 4
Student Name =”Jinyoung”
Start Date =”2017/2/1”
Exam Date =”2017/9/9”
Exam Center =”British college”
Enroll Student Button of certification was clicked

7) enrolToCertification was called;


Course Number = 0
Student Name =”mark”
Start Date =”2016/2/1”
Exam Date =”2017/3/3”
Exam Center =”islington”
Enroll Student Button of certification was clicked

Expected 1) Object will be created and value will be assign and a dialog box will
Result appeared with message “Congratulations!!! Multimedia is added
professional. Press Ok to add"
2) Object will be created and value will be assign and a dialog box will
appeared with message “Congratulations!!! logic is added certification. Press

37
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Ok to add"
3) Object cannot be created since the value of course number is greater than
the available course number. Thus dialog box “Sorry!! The entered course is
not available ” will be displayed
4) Object cannot be created since the value of course number is lesser than
the available course number. Thus dialog box “Sorry!! The entered course is
not available ” will be displayed
5) Since the input course number is not available for professional a dialog box
with message “Sorry!!! This course is not available for professional” will be
displayed
6) Object cannot be created since the value of course number is greater than
the available course number. Thus dialog box “Sorry!!!The entered course is
not available” will be displayed
7) Since the input course number is not available for certification a dialog box
with message “Sorry!!! This course is not available for certification “will be
displayed

Actual 1) Object was created and value was assigned and a dialog box was appeared
Result with message “Congratulations!!! Multimedia is added professional. Press
Ok to add"
2) Object was created and value was assigned and a dialog box was appeared
with message “Congratulations!!! logic is added certification. Press Ok to
add
3) Object was not created since the value of course number was greater than
the available course number. Thus dialog box “Sorry!! The entered course is
not available” was displayed
4) Object was not created since the value of course number was lesser than
the available course number. Thus dialog box “Sorry!! The entered course is
not available” was displayed
5) Since the input course number was not available for certification a dialog box
with message “Sorry!!! This course is not available for professional” was
displayed
6) Object was not created since the value of course number was greater than
the available course number. Thus dialog box “Sorry!!!The entered course is
not available” was displayed
7) Since the input course number was not available for certification a dialog box
with message “Sorry!!! This course is not available for certification is
displayed”

Conclusion Test was successful.

38
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Table 5: Blackbox to display the message when unsuitable values are entered for
professional
STEP: 1

Figure 14: Adding course to professional


STEP 2

Figure 15: Adding course to certification

39
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

STEP 3

Figure 16: Displaying the message box when course number is greater than the list size
STEP 4

Figure 17: Displaying the message box when the course number entered is less than 0

40
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

STEP 5

Figure 18: Displaying the message box when course number entered is not available
professional
STEP 6

41
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Figure 19: Displaying the message box when course number entered is greater than the
list size

STEP 7

42
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Figure 20: Displaying the message box when course number entered is not available for
certification

6) Error Detection and Correction

43
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

6.1) Compiled Error

Figure 21: Error that occurs when package is not import to create array list

The above figure shows the compiled error during compiling the program. To
declare array list, we need to import the array list from the java.util.ArrayList
packages. Since the package is not import the program cannot be compiled.

44
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Figure 22: Correction for error 6.1 figure 21

The error was corrected after importing java.util.ArrayList package

45
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

6.2) Syntax Error

Figure 23: Error that occurs when try is used without catch
Above figure shows the error detected when try was used without catch. Thus the
program cannot be compiled in this case.

Figure 24: Correction for error 6.2 figure 23


The program run clearly when catch was used.

46
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

6.3) Syntax error

Figure 25: Error showing the problem when this keyword is not used
As this keyword can be used to refer to any member of the current object from within
an instance Method or a constructor. The above figure shows error while compiling the
program when this keyword is not used

47
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Figure 26: Correction for error 6.3 figure 25


The error was corrected after adding this keyword

48
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

7) Conclusion
Completing the coursework in a short period of time was a challenging
task to do. It requires a lot of time and efforts to complete it. At first a lot of study
and research was done to pass through the steps like project formation,
pseudocode, method description, testing and error detection and correction.
Without that research the coursework would had been never completed. During
the testing and implementing a lot of errors was seen but it was debugged at last
with the help of respective teachers.
The coursework is not only helpful for securing marks but it can be also be
used in future projects. While working in this project, knowledge about the basic
terms of java was clearly obtained and the errors that is visible while running the
program. The program can be executed not only for the admission process but
by changing the code it can be used in other organizations such as in store for
billing system, keeping records of workers in offices any more.

49
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

8) Appendix 1

8.1) Code for Class (Course)

public class Course//declaring class named Course

//class attributes

String courseName;

String instructorName;

String studentName;

int totalHours;

//constructing constructor named Course with three parameter courseName,


instructorName and totalHours

public Course(String courseName,String instructorName,int totalHours){

this.courseName=courseName;

this.instructorName=instructorName;

this.totalHours=totalHours;

studentName="";

public String getCourseName(){//get method for studentName

return courseName;

public String getInstructorName(){//get method for instructorName

return instructorName;

public int getTotalHours(){//get method for totalHours

50
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

return totalHours;

public void setStudentName(String studentName){//set method for studentName

this.studentName=studentName;

public String getStudentName(){//get method for studentName

return studentName;

public void display(){//set method for displaying information

if(!studentName.equals(""))System.out.println("name of student= "+studentName);

System.out.println("name of course= "+courseName);

System.out.println("name of instructor= "+instructorName);

System.out.println("total hours= "+totalHours);

8.2) Code for class(Professional)

public class Professional extends Course//inherited class Professional from


superclass Course

//class attributes

private int courseFee;

private String enrollDate;

private String roomNo;

51
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

private int dailyHour;

private int downPayment;

private boolean courseStarted;

private boolean courseCompleted;

//constructing constructor named Professional with five parameter courseName,


instructorName,courseFee,totalHours and dailyHour

public Professional(String courseName,String instructorName,int courseFee,int


totalHours,int dailyHour){

super(courseName,instructorName,totalHours);//accessing super class


constructor

this.courseFee=courseFee;

this.dailyHour=dailyHour;

enrollDate="";

roomNo="";

downPayment=0;

courseStarted=false;

courseCompleted=false;

public void setCourseFee(int courseFee){//set method for courseFee

this.courseFee=courseFee;

public int getCourseFee(){//get method for courseFee

return courseFee;

public String getEnrollDate(){//get method for enrollDate

return enrollDate;

52
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

public String getRoomNo(){//get method for roomNo

return roomNo;

public void setDailyHour(int dailyHour){//set method for dailyHour

this.dailyHour=dailyHour;

public int getDailyHour(){//get method for dailyHour

return dailyHour;

public int getDownPayment(){//get method for downPayment

return downPayment;

public boolean getCourseStarted(){//get method for courseStarted

return courseStarted;

public boolean getCourseCompleted(){//get method for courseCompleted

return courseCompleted;

//set method for enrollment with 4 parameters studentName, enrollDate,


downPayment and roomNo

public void enrollment(String studentName,String enrollDate,int


downPayment,String roomNo){

if(courseStarted==true){

System.out.println("The class has already started "+" by


"+getInstructorName()+" in "+roomNo);

53
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

}else{

this.studentName=studentName;

this.enrollDate=enrollDate;

this.roomNo=roomNo;

this.downPayment=downPayment;

courseStarted=true;

courseCompleted=false;

public void courseCompletion(){//set method for courseCompletion

if(courseCompleted==true){

System.out.println("The course was already completed");

}else{

setStudentName("");

enrollDate="";

downPayment=0;

courseStarted=false;

courseCompleted=true;

public void courseDescription(){//set method for courseCompletion

System.out.println("course name="+getCourseName());

System.out.println("instructor's name= "+instructorName);

System.out.println("course fee= "+courseFee);

54
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

public void display(){//set method for displaying course completion,


enrollDate,courseFee,downPayment,dailyHour and roomNo

System.out.println("");

System.out.println("Professional course: ");

System.out.println("");

super.display();//accessing display object

System.out.println("course fee= "+courseFee);

System.out.println("daily hour= "+dailyHour);

if(courseStarted==true){

System.out.println("course completed= "+courseCompleted);

System.out.println("enroll date= "+enrollDate);

System.out.println("down payment= "+downPayment);

System.out.println("room number= "+roomNo);

55
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

8.3) Code for class(Certification)


public class Certification extends Course{//inherited class Certification from superclass
Course

private int courseFee;

private String startDate;

private String examDate;

private String examCenter;

private String certificateAwardedBy;

private String validTill;

private boolean courseStarted;

//constructing constructor named Certification


courseName,instructorName,totalHours,courseFee, certificateAwardedBy and validTill

public Certification(String courseName,String instructorName,int totalHours,int


courseFee,String certificateAwardedBy,String validTill){

super(courseName,instructorName,totalHours);//accessing super class constructor

this.courseFee=courseFee;

this.certificateAwardedBy=certificateAwardedBy;

this.validTill=validTill;

startDate="";

examDate="";

examCenter="";

courseStarted=false;

public void setCourseFee(int courseFee){//set method for courseFee

if(courseStarted==false){

this.courseFee=courseFee;

56
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

}else{

System.out.println("The course has already been started so it is impossible to


change the course fee");

public int getCourseFee(){//get method for courseFee

return courseFee;

public String getStartDate(){//get method for startDate

return startDate;

public String getExamDate(){//get method for examDate

return examDate;

public String getExamCenter(){//get method for examCenter

return examCenter;

public String getCertificateAwardedBy(){//get method for vertificateAwardedBy

return certificateAwardedBy;

public String getValidTill(){//get method for validTill

return validTill;

public boolean getCourseStarted(){//get method for courseStarted

return courseStarted;

57
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

//set method for enrolling students for certification with 4 parameters studentName,
startDate, examDate and examCenter

public void enrollingForCertificationCourse(String studentName,String


startDate,String examDate,String examCenter){

if(courseStarted==false){

this.setStudentName(studentName);

this.examDate=examDate;

this.examCenter=examCenter;

this.startDate=startDate;

courseStarted=true;

}else{

System.out.println("the course has started already from "+this.startDate);

public void display(){//set method for displaying startDate, examDate,examCenter,


certificateAwardedBy and validTill

System.out.println("");

System.out.println("Certification course: ");

System.out.println("");

super.display();

System.out.println("course fee="+courseFee);

System.out.println("certificate is awarded by= "+certificateAwardedBy);

System.out.println("certification validity= "+validTill);

if(courseStarted==true){

System.out.println("course starting date= "+startDate);

58
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

System.out.println("exam date= "+examDate);

System.out.println("exam center= "+examCenter);

8.4) Code for class(TrainingInstitute)

/**

* Description: TrainingInstitute is made to create a GUI for Professional and


Certification class that declare an event handler class and specify that the class
implements an ActionListener interface

* Author:Dibya Shrestha

* Coursework 2:Programming

* Section:L1C8

* Semester:Spring

* ID:NP01CP4A170082

*/

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.ArrayList;

import java.io.IOException;

59
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

public class TrainingInstitute implements ActionListener

{//Declaring an event handler class and specifying that the class implements an
ActionListener interface

private JLabel
professional,seperator,courseName,instructorName,totalHours,courseNumber,studentN
ame,enrolDate,courseFee,downPayment,roomNumber,dailyHour;

private JLabel
certification,lblSeperator,lblCourseName,lblInstructorName,lblTotalHours,lblCourseNum
ber,lblCourseFee,lblStudentName,startDate,examDate,examCenter

,certificate,validity;

private JTextField
txtCourseName,txtInstructorName,txtTotalHours,txtCourseNumber,txtStudentName,txtE
nrolDate,txtCourseFee,txtDownPayment,txtRoomNumber,txtDailyHour;

private JTextField
fieldCourseName,fieldInstructorName,fieldTotalHours,fieldCourseNumber,fieldCourseF
ee,fieldStudentName,txtStartDate,txtExamDate,txtExamCenter,

txtCertificate,txtValidity;

private JButton btnAdd,btnComplete,btnEnrolStudent;

private JButton add,enrol,display,clear;

private JFrame f;

ArrayList <Course> list=new ArrayList <Course>();//constructing an array list named


list for Course class

/**

* This method is used to create a GUI that contains different


JLabel,JTextField,JButton for Professional and Certification class

*/

public void sample(){//set method for creating GUI

60
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

f=new JFrame();

f.setLayout(null);

professional=new JLabel("Professional Course");

professional.setBounds(5,5,150,30);

f.add(professional);

seperator=new
JLabel("----------------------------------------------------------------------------------------------------------
-----------------");

seperator.setBounds(5,3,500,50);

f.add(seperator);

courseName=new JLabel("Course Name");

courseName.setBounds(6,35,100,30);

f.add(courseName);

txtCourseName=new JTextField("");

txtCourseName.setBounds(100,35,400,25);

f.add(txtCourseName);

instructorName=new JLabel("Instructor Name");

instructorName.setBounds(6,65,100,30);

f.add(instructorName);

txtInstructorName=new JTextField("");

61
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

txtInstructorName.setBounds(100,65,400,25);

f.add(txtInstructorName);

totalHours=new JLabel("Total Hours");

totalHours.setBounds(6,95,100,25);

f.add(totalHours);

txtTotalHours=new JTextField("");

txtTotalHours.setBounds(100,95,145,25);

f.add(txtTotalHours);

btnAdd=new JButton("Add");

btnAdd.setBounds(380,125,116,30);

f.add(btnAdd);

courseNumber=new JLabel("Course Number");

courseNumber.setBounds(6,160,100,30);

f.add(courseNumber);

txtCourseNumber=new JTextField("");

txtCourseNumber.setBounds(100,160,145,25);

f.add(txtCourseNumber);

studentName=new JLabel("Student Name");

studentName.setBounds(6,190,100,30);

62
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

f.add(studentName);

txtStudentName=new JTextField("");

txtStudentName.setBounds(100,190,145,25);

f.add(txtStudentName);

enrolDate=new JLabel("Enrol Date");

enrolDate.setBounds(250,190,100,30);

f.add(enrolDate);

txtEnrolDate=new JTextField("");

txtEnrolDate.setBounds(335,190,165,25);

f.add(txtEnrolDate);

dailyHour=new JLabel("Daily Hour");

dailyHour.setBounds(6,125,100,30);

f.add(dailyHour);

txtDailyHour=new JTextField("");

txtDailyHour.setBounds(100,125,145,25);

f.add(txtDailyHour);

courseFee=new JLabel("Course Fee");

courseFee.setBounds(250,95,100,30);

63
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

f.add(courseFee);

txtCourseFee=new JTextField("");

txtCourseFee.setBounds(335,95,165,25);

f.add(txtCourseFee);

downPayment=new JLabel("Down Payment");

downPayment.setBounds(6,220,100,30);

f.add(downPayment);

txtDownPayment=new JTextField("");

txtDownPayment.setBounds(100,220,145,25);

f.add(txtDownPayment);

roomNumber=new JLabel("Room Number");

roomNumber.setBounds(250,220,100,30);

f.add(roomNumber);

txtRoomNumber=new JTextField("");

txtRoomNumber.setBounds(335,220,165,25);

f.add(txtRoomNumber);

btnComplete=new JButton("Complete");

btnComplete.setBounds(250,255,100,30);

f.add(btnComplete);

64
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

btnEnrolStudent=new JButton("Enrol Student");

btnEnrolStudent.setBounds(380,255,120,30);

f.add(btnEnrolStudent);

certification=new JLabel("Certification Course");

certification.setBounds(5,300,150,30);

f.add(certification);

lblSeperator=new
JLabel("----------------------------------------------------------------------------------------------------------
-----------------");

lblSeperator.setBounds(5,302,500,50);

f.add(lblSeperator);

lblCourseName=new JLabel("Course Name");

lblCourseName.setBounds(6,335,100,30);

f.add(lblCourseName);

fieldCourseName=new JTextField("");

fieldCourseName.setBounds(100,335,400,25);

f.add(fieldCourseName);

lblInstructorName=new JLabel("Instructor Name");

lblInstructorName.setBounds(6,365,100,30);

65
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

f.add(lblInstructorName);

fieldInstructorName=new JTextField("");

fieldInstructorName.setBounds(100,365,400,25);

f.add(fieldInstructorName);

lblTotalHours=new JLabel("Total Hours");

lblTotalHours.setBounds(6,395,100,30);

f.add(lblTotalHours);

fieldTotalHours=new JTextField("");

fieldTotalHours.setBounds(100,395,145,25);

f.add(fieldTotalHours);

add=new JButton("Add");

add.setBounds(380,485,116,30);

f.add(add);

lblCourseNumber=new JLabel("Course Number");

lblCourseNumber.setBounds(6,520,100,30);

f.add(lblCourseNumber);

fieldCourseNumber=new JTextField("");

fieldCourseNumber.setBounds(100,520,400,25);

66
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

f.add(fieldCourseNumber);

lblStudentName=new JLabel("Student Name");

lblStudentName.setBounds(6,550,100,30);

f.add(lblStudentName);

fieldStudentName=new JTextField("");

fieldStudentName.setBounds(100,550,400,25);

f.add(fieldStudentName);

lblCourseFee=new JLabel("Course Fee");

lblCourseFee.setBounds(250,395,100,30);

f.add(lblCourseFee);

fieldCourseFee=new JTextField("");

fieldCourseFee.setBounds(335,395,165,25);

f.add(fieldCourseFee);

startDate=new JLabel("Start Date");

startDate.setBounds(6,580,100,30);

f.add(startDate);

txtStartDate=new JTextField("");

txtStartDate.setBounds(100,580,145,25);

67
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

f.add(txtStartDate);

examDate=new JLabel("Exam Date");

examDate.setBounds(250,580,100,30);

f.add(examDate);

txtExamDate=new JTextField("");

txtExamDate.setBounds(335,580,165,25);

f.add(txtExamDate);

examCenter=new JLabel("Exam Center");

examCenter.setBounds(6,610,100,30);

f.add(examCenter);

txtExamCenter=new JTextField("");

txtExamCenter.setBounds(100,610,400,25);

f.add(txtExamCenter);

certificate=new JLabel("Awarded By");

certificate.setBounds(6,425,100,30);

f.add(certificate);

txtCertificate=new JTextField("");

txtCertificate.setBounds(100,425,400,25);

f.add(txtCertificate);

68
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

validity=new JLabel("Validity");

validity.setBounds(6,455,100,30);

f.add(validity);

txtValidity=new JTextField("");

txtValidity.setBounds(100,455,400,25);

f.add(txtValidity);

enrol=new JButton("Enrol Student");

enrol.setBounds(380,640,120,30);

f.add(enrol);

display=new JButton("Display All");

display.setBounds(250,700,100,30);

f.add(display);

clear=new JButton("Clear");

clear.setBounds(380,700,120,30);

f.add(clear);

btnAdd.addActionListener(this);

add.addActionListener(this);

display.addActionListener(this);

69
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

btnEnrolStudent.addActionListener(this);

enrol.addActionListener(this);

clear.addActionListener(this);

btnComplete.addActionListener(this);

f.setVisible(true);

f.setSize(600,900);

f.setLocationRelativeTo(null);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/**

* This method is created to write code that implements the methods in listener
interface for various for Professional and Certificationclass

*/

public void actionPerformed(ActionEvent e){

/**

* /calling addToProfessional method

*/

if (e.getSource()==btnAdd){

addToProfessional();

70
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

/**

* /calling addToCertification method

*/

if (e.getSource()==add){

addToCertification();

/**

* /calling courseCompletion method

*/

if (e.getSource()==btnComplete){

courseCompletion();

/**

* /calling EnrolToProfessional method

*/

if (e.getSource()==btnEnrolStudent){

EnrolToProfessional();

/**

* /calling enrolToCertification method

71
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

*/

if (e.getSource()==enrol){

enrolToCertification();

/**

* /calling display method

*/

if (e.getSource()==display){

display();

/**

* /calling clear method

*/

if (e.getSource()==clear){

clear();

/**

* //method that includes codes for Add button for Professional class to add new
values

*/

public void addToProfessional(){

72
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

try{

String courseName=txtCourseName.getText();//return the value from


txtCourseName and stores in courseName as a string value

String instructorName=txtInstructorName.getText();

int courseFee=Integer.parseInt(txtCourseFee.getText());//return the value from


txtCourseFee and stores in courseFee as a integer value

int totalHours=Integer.parseInt(txtTotalHours.getText());

int dailyHour=Integer.parseInt(txtDailyHour.getText());

Professional pobj=new
Professional(courseName,instructorName,courseFee,totalHours,dailyHour);//creating
new object for Professional

list.add(pobj);//adding the object to the list

JOptionPane.showMessageDialog(f,"Congratulations!!! "+courseName+" is
added professional.Press Ok to add");//displays a message box

}catch(NullPointerException nu){

JOptionPane.showMessageDialog(f,nu.getMessage(),"Error !!! No
Input!",JOptionPane.ERROR_MESSAGE);

}catch(Exception exc){

JOptionPane.showMessageDialog(f,exc.getMessage(),"Error !!! Enter valid


input!",JOptionPane.ERROR_MESSAGE);

/**

73
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

* //method that includes codes for for Add button for Certification class to add new
values

*/

public void addToCertification(){

try{

String courseName=fieldCourseName.getText();

String instructorName=fieldInstructorName.getText();

int totalHours=Integer.parseInt(fieldTotalHours.getText());

int courseFee=Integer.parseInt(fieldCourseFee.getText());

String cerificateAwardedBy=txtCertificate.getText();

String validity=txtValidity.getText();

Certification cobj=new
Certification(courseName,instructorName,totalHours,courseFee,cerificateAwardedBy,va
lidity);

list.add(cobj);

JOptionPane.showMessageDialog(f,"Congratulations!!! "+courseName+" is
added to Certification.Press Ok to add");

}catch(NullPointerException po){

JOptionPane.showMessageDialog(f,po.getMessage(),"Error !!! No
Input!",JOptionPane.ERROR_MESSAGE);

}catch(Exception ex){

JOptionPane.showMessageDialog(f,ex.getMessage(),"Error !!! Enter valid


input!",JOptionPane.ERROR_MESSAGE);

74
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

/**

* method that includes codes for for complete button for Professional class

*/

public void courseCompletion(){

try{

int courseNum=Integer.parseInt(txtCourseNumber.getText());

Professional pro=(Professional)list.get(courseNum);

if(pro.getCourseStarted()==true){

if(pro instanceof Professional){

pro.courseCompletion();

JOptionPane.showMessageDialog(f,"The course has been completed");

}else{

JOptionPane.showMessageDialog(f,"The course is not available!");

}else{

JOptionPane.showMessageDialog(f,"The course has not started yet");

}catch(NullPointerException po){

75
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

JOptionPane.showMessageDialog(f,po.getMessage(),"Error !!! No
Input!",JOptionPane.ERROR_MESSAGE);

}catch(Exception ex){

JOptionPane.showMessageDialog(f,ex.getMessage(),"Error !!! Enter valid


input!",JOptionPane.ERROR_MESSAGE);

/**

* method that includes codes for for Enrol Student button for Professional class to
enrol students

*/

public void EnrolToProfessional(){

try{

int pcourseNumber=Integer.parseInt(txtCourseNumber.getText());

if (pcourseNumber < list.size() && pcourseNumber>=0){

Course c=(Course)list.get(pcourseNumber);

if(c instanceof Professional){

String studentName=txtStudentName.getText();

76
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

String enrolDate=txtEnrolDate.getText();

int downPayment=Integer.parseInt(txtDownPayment.getText());

String roomNumber=txtRoomNumber.getText();

Professional pr=((Professional)c);

pr.enrollment(studentName,enrolDate,downPayment,roomNumber);

JOptionPane.showMessageDialog(f,"Congratulations!!! "+studentName+"
has been enrolled to professional!!!");

}else{

JOptionPane.showMessageDialog(f,"Sorry!!! This course is not available


for professional");

}else{

JOptionPane.showMessageDialog(f,"Sorry!!! The entered course number is not


available ");

}catch(NullPointerException n){

JOptionPane.showMessageDialog(f,n.getMessage(),"Error !!! No
Input!",JOptionPane.ERROR_MESSAGE);

}catch(Exception exce){

JOptionPane.showMessageDialog(f,exce.getMessage(),"Error !!! Enter valid


input!",JOptionPane.ERROR_MESSAGE);

77
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

/**

* method that includes codes for for Enrol button for Certification class to enrol student

*/

public void enrolToCertification(){

try{

int ccourseNumber=Integer.parseInt(fieldCourseNumber.getText());

if (ccourseNumber < list.size() && ccourseNumber >= 0){

Course c=list.get(ccourseNumber);

if(c instanceof Certification){

String studentName=fieldStudentName.getText();

String startDate=txtStartDate.getText();

String examDate=txtExamDate.getText();

String examCenter=txtExamCenter.getText();

Certification cer=((Certification)c);

cer.enrollingForCertificationCourse(studentName,startDate,examDate,exam
Center);

JOptionPane.showMessageDialog(f,"Congratulations!!! "+studentName+"
has been enrolled for certification!!!");

}else{

JOptionPane.showMessageDialog(f,"Sorry!!! This course is not available for


certification");

78
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

}else{

JOptionPane.showMessageDialog(f,"Sorry!!! The entered course number is not


available ");

}catch(NullPointerException n){

JOptionPane.showMessageDialog(f,n.getMessage(),"Error !!! No
Input!",JOptionPane.ERROR_MESSAGE);

}catch(Exception ne){

JOptionPane.showMessageDialog(f,ne.getMessage(),"Error !!! Enter valid


input!",JOptionPane.ERROR_MESSAGE);

/**

* //method that includes codes for for Display button for both Professional and
Certification class to display the input values

*/

public void display(){

System.out.println("The complete details is given below:\n");

for(Course c:list){//for loop to store the value for Professional and Certification
class

79
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

if(c instanceof Professional){//checks if the input values is of profesional class or


not

Professional p=(Professional) c;

p.display();//displays the information for professional class

}if(c instanceof Certification){//checks if the input values is of certification class or


not

Certification ce=(Certification) c;

ce.display();//displays the information for certification class

/**

* //method that includes codes for for clear button for both Professional and
Certification class to clear all the values

*/

public void clear(){

txtCourseName.setText("");//set text to input new values for course name of


professional class

txtInstructorName.setText("");

txtTotalHours.setText("");

txtCourseNumber.setText("");

txtStudentName.setText("");

txtEnrolDate.setText("");

txtCourseFee.setText("");

txtDownPayment.setText("");

txtRoomNumber.setText("");

80
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

txtDailyHour.setText("");

fieldCourseName.setText("");//set text to input new values for course name of


certification class

fieldInstructorName.setText("");

fieldTotalHours.setText("");

fieldCourseNumber.setText("");

fieldCourseFee.setText("");

fieldStudentName.setText("");

txtStartDate.setText("");

txtExamDate.setText("");

txtExamCenter.setText("");

txtCertificate.setText("");

txtValidity.setText("");

/**

* It is the main method used to call the sample method

*/

public static void main(String[] args){

new TrainingInstitute().sample();

81
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

9) Appendix 2

9.1) Class Diagram


9.1.1) Course (Parent Class)

Course

+ courseName : Str
+ instructorName : String
+ studentName : String
+ totalHours : int

+ getCourseName( ) : String

+ getInstructorName( ) : String

+ getTotalHours ( ) : int

+ setStudentName(studentName : String) : void

+ getStudentName ( ) : String

82
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

9.1.2) Professional

Professional
- courseFee : int
- enrollDate : String
- roomNo : String
- dailyHour : int
- downPayment : int
- courseStarted : Boolean
- courseCompleted : Boolean
+ setCourseFee(courseFee : int) : void
+ getCourseFee ( ) : int
+ getEnrollDate ( ) : int
+ getRoomNo ( ) : int
+ setDailyHour(dailyHour:int) : void
+ getDailyHour ( ) : int
+ getDownPayment ( ) : int
+ getCourseStarted ( ) : boolean
+ getCourseCompleted ( ) : boolean
+ setEnrollment(studentName:String enrollDate:String downPayment:int
roomNo:String) : void
+ setCourseCompletion ( ) : void
+ setCourseDescription ( ) : void
+ setDisplay ( ) : void

83
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

9.1.3) Certification

Certification

- courseFee : int

- startDate : String

- examDate : String

- examCenter : String

- certificateAwardedBy : String

- validTill : String

- courseStarted : Boolean

+ setCourseFee(courseFee : int) : void

+ getCourseFee ( ) : int

+ getStartDate ( ) : String

+ getExamDate ( ) : String

+ getExamCenter ( ) : String

+ getCertificateAwardedBy ( ) : String

+ getValidTill ( ) : String

+ getCourseStarted ( ) : Boolean

+ setEnrollingForCertificationCourse(studentName:String startDate:String examDate:String


examCenter : String) :void

+ setDisplay ( ) : void

84
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

9.2) Pseudocode

9.2.1) Class(Course)
Define class (say Course)

Initialize course name, instructor name and student name as String and total
hours as int

Construct constructor (say Course) with course name, instructor name and total
hours as parameters

this.courseName = courseName;

this.instructorName=instructorName;

this.totalHours=totalHours;

Assign student name as empty string

return course name as string

return instructor name as string

return total hours as string

set the name of student as string

return the name of student as string

Call display(){

DO

IF(!studentName.equals(“ “)

DO

Display the course name,instucyor name and total hours

END DO

85
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

ENDIF

END DO

9.2.2) For Professional Subclass


Course class extend by sub class Professional

private int courseFee

private String enrollDate

private String roomNo

private int dailyHour

private int downPayment

private boolean courseStarted

private boolean courseCompleted

Construct a constructor Professional with parameter


courseName,instructorName, courseFee,totalHour and dailyHour

Super(courseName,instructorName,totalHours)

this.courseFee=courseFee

this.dailyHour=dailyHour

enrollDate=” “

roomNo=” “

downPayment=0

corurseStarted=false

courseCompleted=false

CALL setCourseFee(int courseFee)

this.courseFee=courseFee

CALL int getCourseFee()


86
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

return courseFee

CALL String getEnrollDate()

return enrollDate

CALL String getRoomNo()

return roomNo

CALL setDailyHour(int dailyHour)

this.dailyHour=dailyHour

CALL int getDailyHour()

return dailyHour

CALL int getDownPayment()

return downPayment

CALL boolean getCourseStarted()

return courseStarted

CALL boolean getCourseCompleted()

return courseCompleted

CALL enrollment(String studentName,String enrollDate, int downPayment,


int roomNo)

DO

IF(courseStarted==true)

DO

DISPLAYi( “the class has already started”)

END DO

ELSE

DO

this.studentName=studentName

87
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

this.enrollDate=enrollDate

this.roomNo=roomNo

this.downPayment=downPayment

courseStarted=true

courseCompleted=false

END DO

END IF

END DO

CALL courseCompletion( )

DO

IF(courseCompleted==true)

DO

DISPLAY(“The course has already completed”)

END DO

ELSE

DO

setStudentName(" ")

enrollDate=" "

downPayment=0

courseStarted=false

courseCompleted=true

END DO

END IF

END DO

CALL courseDescription( )

88
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

DISPLAY the name of course

DISPLAY the name of instructor

DISPLAY the integer value of course frr

CALL display( )

Super.display( )

DISPLAY the value of course fee

DISPLAY the value of daily hour

DO

IF(courseStarted==true)

DO

DISPLAY the boolean value of course


completed

DISPLAY the string value of enroll date

DISPLAY the value of down payment

DISPLAY the value of room number

END DO

END IF

END DO

9.2.3) For Certification sub class


Course class extend by sub class Certification

private int courseFee

private String startDate

private String examDate

private String examCenter

private String certificateAwardedBy

private String validTill

89
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

private boolean courseStarted

Construct a constructor named Certification with parameter String courseName,


String instructorName, int totalHours, String courseFee, String
certificateAwardedBy and String validTill

super(courseName,instructorName,totalHours)

this.courseFee=courseFee

this.certificateAwardedBy=certificateAwardedBy

this.validTill=validTill

startDate=" "

examDate=" “

examCenter=" "

courseStarted=false

CALL setCourseFee(int courseFee)

DO

IF(courseStarted==false)

DO

this.courseFee=courseFee

END DO

ELSE

DO

DISPLAY (“the course has already started”)

END DO

END IF

CALL int getCourseFee( )

return courseFee

90
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

CALL String getStartDate( )

return startDate

CALL String getExamDate( )

return examDate

CALL String getExamCenter( )

return examCenter

CALL String getCertificateAwardedBy ()

return certificateAwardedBy

CALL String getValidTill( )

return validTill

CALL boolean getCourseStarted( )

return courseStarted

CALL enrollingForCertificateCourse(String studentName, String examDate,


String examCenter)

DO

IF(courseStarted==false)

DO

this.setStudentName(studentName)

this.examDate=examDate

this.examCenter=examCenter

this.startDate=startDate

courseStarted=true

END DO

ELSE

DO

91
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

DISPLAY ( “ the course has started already”)

END DO

END IF

CALL display( )

Super.display( )

DISPLAY the certification awarding body

DISPLAY the certification validity date

DISPLAY the course fee

DO

IF( courseStarted==true)

DO

DISPLAY the course starting date

DISPLAY the exam date

DISPLAY the exam center

END DO

END IF

END DO

92
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

9.3) Method Description


Course

getCourseName : This method is used to return the string course name input by the user.

getInstructorName : This method is used to return the string name of instructor input by the
user

getTotalHours : This method the used to return the integer value total hours input by the
user.

setStudentName : This method is used to set the name of the student as a string.

Display : This method is used to print the name of the student, course name, instructor’s
name and total hours.

93
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Professional

setCourseFee : This method is used to set the course fee as a integer.

getCourseFee : This method is used to return the integer value of course fee input by
the user.
getEnrollDate : This method is used to return the string value of enrollment date input
by the user.
getRoomNo : This method is used to return the string value of room number input by
the user.

setDailyHour : This method is used to set the integer value of daily hour .

getDailyHour : This method is used to return the integer value of daily hour.

getDownPayment : This method is used to return the integer value of down payment
input by the user.

getCourseStarted : This method is used to return the Boolean value of course


started.

getCourseCompleted : This method is used to return the Boolean value of course


completion.

enrollment : This method is used to check the Boolean value of courseStarted and
displays “the course had been already started” if the Boolean value is true otherwise it
stores the value of studentName, enrollDate, roomNo, downPayment input by the
user the value of courseStarted is assigned as true and courseCompleted as false.
courseCompletition : This method is used to check the Boolean value of
courseCompletition and displays “the course had been already completed” if the
Boolean value of courseCompleted is true otherwise it set the name of student,
enrollDate is assigned empty string and downPayment, courseStarted and
courseCompleted is assigned as 0, false and true.
courseDescription : This method is used to displays the name of course, instructor
name and course fee.

display : This method is used to displays the course completed, enrollment date and
downpayment.

94
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Certification

setCourseFee : This method is used to check the Boolean value of courseStarted. If it is


false the value of courseFee is stored otherwise it displays “the course had been already
started”
getCourseFee : This method is used to return the integer value of course fee.

getStartDate : This method is used to return the starting date of course.

getExamDate : This method is used to return the date of exam as a string value.

getExamCenter : This method is used to return the value of exam center as a string.

getCertificateAwardedBy : This method is used to return the value of the organization


that award the certificate.

getValidTill : This method is used to return the value of validity date as a string.

getCourseStarted : This method is used to return the Boolean value of courseStarted.

enrollingForCertification : This method is used to enroll students for certification

display : This method is used to display course starting date, name of student, exam
date, exam center and certification validity if the value of courseStarted is true.

95
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING

Bibliography
Bart Baesens, Aimee Backiel, Seppe vanden Broucke, 2015. Beginning Java
Programming: The Object-Oriented Approach. illustrated, reprint ed. s.l.:John Wiley &
Sons.

Bart Baesens, Aimee Backiel, Seppe vanden Broucke, 2015. Beginning Java
Programming: The Object-Oriented Approach. illustrated,reprint ed. s.l.:John Wiley &
Sons.

Veer, E. A. V., 2004. JavaScript For Dummies. 4 ed. s.l.:John Wiley & Sons.

96
Dibya Shrestha(L1C8)

You might also like