2017-18 A CS4001NI A2 CW Coursework NP01CP4A170082
2017-18 A CS4001NI A2 CW Coursework NP01CP4A170082
Programming
CS4001NI
Coursework 2
1) Introduction
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
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
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.setBounds(5,5,150,30);
f.add(professional);
seperator=CREATE_LABEL("-----------------------------------------------------------------------------
----------------------------------------------");
seperator.setBounds(5,3,500,50);
f.add(seperator);
courseName.setBounds(6,35,100,30);
f.add(courseName);
txtCourseName.setBounds(100,35,400,25);
f.add(txtCourseName);
5
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
instructorName.setBounds(6,65,100,30);
f.add(instructorName);
txtInstructorName.setBounds(100,65,400,25);
f.add(txtInstructorName);
totalHours.setBounds(6,95,100,25);
f.add(totalHours);
txtTotalHours.setBounds(100,95,145,25);
f.add(txtTotalHours);
btnAdd.setBounds(380,125,116,30);
f.add(btnAdd);
courseNumber.setBounds(6,160,100,30);
f.add(courseNumber);
txtCourseNumber.setBounds(100,160,145,25);
f.add(txtCourseNumber);
6
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
studentName.setBounds(6,190,100,30);
f.add(studentName);
txtStudentName.setBounds(100,190,145,25);
f.add(txtStudentName);
enrolDate.setBounds(250,190,100,30);
f.add(enrolDate);
txtEnrolDate.setBounds(335,190,165,25);
f.add(txtEnrolDate);
dailyHour.setBounds(6,125,100,30);
f.add(dailyHour);
txtDailyHour.setBounds(100,125,145,25);
f.add(txtDailyHour);
courseFee.setBounds(250,95,100,30);
f.add(courseFee);
7
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
txtCourseFee.setBounds(335,95,165,25);
f.add(txtCourseFee);
downPayment.setBounds(6,220,100,30);
f.add(downPayment);
txtDownPayment.setBounds(100,220,145,25);
f.add(txtDownPayment);
roomNumber.setBounds(250,220,100,30);
f.add(roomNumber);
txtRoomNumber.setBounds(335,220,165,25);
f.add(txtRoomNumber);
btnComplete.setBounds(250,255,100,30);
f.add(btnComplete);
btnEnrolStudent.setBounds(380,255,120,30);
f.add(btnEnrolStudent);
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.setBounds(6,335,100,30);
f.add(lblCourseName);
fieldCourseName.setBounds(100,335,400,25);
f.add(fieldCourseName);
lblInstructorName.setBounds(6,365,100,30);
f.add(lblInstructorName);
fieldInstructorName.setBounds(100,365,400,25);
f.add(fieldInstructorName);
lblTotalHours.setBounds(6,395,100,30);
f.add(lblTotalHours);
9
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
fieldTotalHours.setBounds(100,395,145,25);
f.add(fieldTotalHours);
add=new JButton("Add");
add.setBounds(380,485,116,30);
f.add(add);
lblCourseNumber.setBounds(6,520,100,30);
f.add(lblCourseNumber);
fieldCourseNumber.setBounds(100,520,400,25);
f.add(fieldCourseNumber);
lblStudentName.setBounds(6,550,100,30);
f.add(lblStudentName);
fieldStudentName.setBounds(100,550,400,25);
f.add(fieldStudentName);
lblCourseFee.setBounds(250,395,100,30);
f.add(lblCourseFee);
10
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
fieldCourseFee.setBounds(335,395,165,25);
f.add(fieldCourseFee);
startDate.setBounds(6,580,100,30);
f.add(startDate);
txtStartDate.setBounds(100,580,145,25);
f.add(txtStartDate);
examDate.setBounds(250,580,100,30);
f.add(examDate);
txtExamDate.setBounds(335,580,165,25);
f.add(txtExamDate);
examCenter.setBounds(6,610,100,30);
f.add(examCenter);
txtExamCenter.setBounds(100,610,400,25);
f.add(txtExamCenter);
11
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
certificate.setBounds(6,425,100,30);
f.add(certificate);
txtCertificate.setBounds(100,425,400,25);
f.add(txtCertificate);
validity.setBounds(6,455,100,30);
f.add(validity);
txtValidity.setBounds(100,455,400,25);
f.add(txtValidity);
enrol.setBounds(380,640,120,30);
f.add(enrol);
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
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)
END DO
catch(NullPointerException nu)
DO
END DO
catch(Exception exc)
DO
15
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
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);
END DO
catch(NullPointerException po)
DO
16
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
END DO
catch(Exception ex)
DO
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
DO
pro.courseCompletion();
END DO
Else
DO
END DO
17
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
END DO
Else
DO
END DO
END DO
catch(NullPointerException po)
DO
END DO
catch(Exception ex)
DO
END DO
END DO
CALL EnrolToProfessional()
DO
Try
DO
int pcourseNumber=Integer.parseInt(txtCourseNumber.getText());
DO
Course c=(Course)list.get(pcourseNumber);
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);
END DO
Else
DO
END DO
Else
DO
END DO
END DO
catch(NullPointerException n)
DO
END DO
catch(Exception exce)
DO
END DO
19
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
END DO
CALL enrolToCertification()
DO
Try
DO
int ccourseNumber=Integer.parseInt(fieldCourseNumber.getText());
DO
Course c=list.get(ccourseNumber);
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);
END DO
Else
DO
END DO
Else
20
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
DO
END DO
END DO
catch(NullPointerException n)
DO
DO
END DO
CALL display()
DO
for(Course c:list)
DO
Professional p=(Professional) c;
p.display()
END DO
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.
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
C:\Users\Dell>cd desktop
C:\Users\Dell\Desktop\System Code>javac
TrainingInstitute.java
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
25
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
26
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
27
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
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
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!!!"
29
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
30
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
31
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
32
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
33
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
34
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
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
Course Name=”multimedia”
Instructor Name=”hobi”
Course Fee=800000
Total Hours=200
Daily Hour=1
Add Button of Professional was clicked
36
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
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”
38
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
Table 5: Blackbox to display the message when unsuitable values are entered for
professional
STEP: 1
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
43
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
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
45
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
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.
46
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
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
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
//class attributes
String courseName;
String instructorName;
String studentName;
int totalHours;
this.courseName=courseName;
this.instructorName=instructorName;
this.totalHours=totalHours;
studentName="";
return courseName;
return instructorName;
50
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
return totalHours;
this.studentName=studentName;
return studentName;
//class attributes
51
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
this.courseFee=courseFee;
this.dailyHour=dailyHour;
enrollDate="";
roomNo="";
downPayment=0;
courseStarted=false;
courseCompleted=false;
this.courseFee=courseFee;
return courseFee;
return enrollDate;
52
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
return roomNo;
this.dailyHour=dailyHour;
return dailyHour;
return downPayment;
return courseStarted;
return courseCompleted;
if(courseStarted==true){
53
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
}else{
this.studentName=studentName;
this.enrollDate=enrollDate;
this.roomNo=roomNo;
this.downPayment=downPayment;
courseStarted=true;
courseCompleted=false;
if(courseCompleted==true){
}else{
setStudentName("");
enrollDate="";
downPayment=0;
courseStarted=false;
courseCompleted=true;
System.out.println("course name="+getCourseName());
54
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
System.out.println("");
System.out.println("");
if(courseStarted==true){
55
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
this.courseFee=courseFee;
this.certificateAwardedBy=certificateAwardedBy;
this.validTill=validTill;
startDate="";
examDate="";
examCenter="";
courseStarted=false;
if(courseStarted==false){
this.courseFee=courseFee;
56
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
}else{
return courseFee;
return startDate;
return examDate;
return examCenter;
return certificateAwardedBy;
return validTill;
return courseStarted;
57
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
//set method for enrolling students for certification with 4 parameters studentName,
startDate, examDate and examCenter
if(courseStarted==false){
this.setStudentName(studentName);
this.examDate=examDate;
this.examCenter=examCenter;
this.startDate=startDate;
courseStarted=true;
}else{
System.out.println("");
System.out.println("");
super.display();
System.out.println("course fee="+courseFee);
if(courseStarted==true){
58
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
/**
* 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
{//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 JFrame f;
/**
*/
60
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
f=new JFrame();
f.setLayout(null);
professional.setBounds(5,5,150,30);
f.add(professional);
seperator=new
JLabel("----------------------------------------------------------------------------------------------------------
-----------------");
seperator.setBounds(5,3,500,50);
f.add(seperator);
courseName.setBounds(6,35,100,30);
f.add(courseName);
txtCourseName=new JTextField("");
txtCourseName.setBounds(100,35,400,25);
f.add(txtCourseName);
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.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.setBounds(6,160,100,30);
f.add(courseNumber);
txtCourseNumber=new JTextField("");
txtCourseNumber.setBounds(100,160,145,25);
f.add(txtCourseNumber);
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.setBounds(250,190,100,30);
f.add(enrolDate);
txtEnrolDate=new JTextField("");
txtEnrolDate.setBounds(335,190,165,25);
f.add(txtEnrolDate);
dailyHour.setBounds(6,125,100,30);
f.add(dailyHour);
txtDailyHour=new JTextField("");
txtDailyHour.setBounds(100,125,145,25);
f.add(txtDailyHour);
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.setBounds(6,220,100,30);
f.add(downPayment);
txtDownPayment=new JTextField("");
txtDownPayment.setBounds(100,220,145,25);
f.add(txtDownPayment);
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.setBounds(380,255,120,30);
f.add(btnEnrolStudent);
certification.setBounds(5,300,150,30);
f.add(certification);
lblSeperator=new
JLabel("----------------------------------------------------------------------------------------------------------
-----------------");
lblSeperator.setBounds(5,302,500,50);
f.add(lblSeperator);
lblCourseName.setBounds(6,335,100,30);
f.add(lblCourseName);
fieldCourseName=new JTextField("");
fieldCourseName.setBounds(100,335,400,25);
f.add(fieldCourseName);
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.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.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.setBounds(6,550,100,30);
f.add(lblStudentName);
fieldStudentName=new JTextField("");
fieldStudentName.setBounds(100,550,400,25);
f.add(fieldStudentName);
lblCourseFee.setBounds(250,395,100,30);
f.add(lblCourseFee);
fieldCourseFee=new JTextField("");
fieldCourseFee.setBounds(335,395,165,25);
f.add(fieldCourseFee);
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.setBounds(250,580,100,30);
f.add(examDate);
txtExamDate=new JTextField("");
txtExamDate.setBounds(335,580,165,25);
f.add(txtExamDate);
examCenter.setBounds(6,610,100,30);
f.add(examCenter);
txtExamCenter=new JTextField("");
txtExamCenter.setBounds(100,610,400,25);
f.add(txtExamCenter);
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.setBounds(380,640,120,30);
f.add(enrol);
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
*/
/**
*/
if (e.getSource()==btnAdd){
addToProfessional();
70
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
/**
*/
if (e.getSource()==add){
addToCertification();
/**
*/
if (e.getSource()==btnComplete){
courseCompletion();
/**
*/
if (e.getSource()==btnEnrolStudent){
EnrolToProfessional();
/**
71
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
*/
if (e.getSource()==enrol){
enrolToCertification();
/**
*/
if (e.getSource()==display){
display();
/**
*/
if (e.getSource()==clear){
clear();
/**
* //method that includes codes for Add button for Professional class to add new
values
*/
72
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
try{
String instructorName=txtInstructorName.getText();
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
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){
/**
73
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
* //method that includes codes for for Add button for Certification class to add new
values
*/
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){
74
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
/**
* method that includes codes for for complete button for Professional class
*/
try{
int courseNum=Integer.parseInt(txtCourseNumber.getText());
Professional pro=(Professional)list.get(courseNum);
if(pro.getCourseStarted()==true){
pro.courseCompletion();
}else{
}else{
}catch(NullPointerException po){
75
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
JOptionPane.showMessageDialog(f,po.getMessage(),"Error !!! No
Input!",JOptionPane.ERROR_MESSAGE);
}catch(Exception ex){
/**
* method that includes codes for for Enrol Student button for Professional class to
enrol students
*/
try{
int pcourseNumber=Integer.parseInt(txtCourseNumber.getText());
Course c=(Course)list.get(pcourseNumber);
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{
}else{
}catch(NullPointerException n){
JOptionPane.showMessageDialog(f,n.getMessage(),"Error !!! No
Input!",JOptionPane.ERROR_MESSAGE);
}catch(Exception exce){
77
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
/**
* method that includes codes for for Enrol button for Certification class to enrol student
*/
try{
int ccourseNumber=Integer.parseInt(fieldCourseNumber.getText());
Course c=list.get(ccourseNumber);
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{
78
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
}else{
}catch(NullPointerException n){
JOptionPane.showMessageDialog(f,n.getMessage(),"Error !!! No
Input!",JOptionPane.ERROR_MESSAGE);
}catch(Exception ne){
/**
* //method that includes codes for for Display button for both Professional and
Certification class to display the input values
*/
for(Course c:list){//for loop to store the value for Professional and Certification
class
79
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
Professional p=(Professional) c;
Certification ce=(Certification) c;
/**
* //method that includes codes for for clear button for both Professional and
Certification class to clear all the values
*/
txtInstructorName.setText("");
txtTotalHours.setText("");
txtCourseNumber.setText("");
txtStudentName.setText("");
txtEnrolDate.setText("");
txtCourseFee.setText("");
txtDownPayment.setText("");
txtRoomNumber.setText("");
80
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
txtDailyHour.setText("");
fieldInstructorName.setText("");
fieldTotalHours.setText("");
fieldCourseNumber.setText("");
fieldCourseFee.setText("");
fieldStudentName.setText("");
txtStartDate.setText("");
txtExamDate.setText("");
txtExamCenter.setText("");
txtCertificate.setText("");
txtValidity.setText("");
/**
*/
new TrainingInstitute().sample();
81
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
9) Appendix 2
Course
+ courseName : Str
+ instructorName : String
+ studentName : String
+ totalHours : int
+ getCourseName( ) : String
+ getInstructorName( ) : String
+ getTotalHours ( ) : int
+ 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
+ getCourseFee ( ) : int
+ getStartDate ( ) : String
+ getExamDate ( ) : String
+ getExamCenter ( ) : String
+ getCertificateAwardedBy ( ) : String
+ getValidTill ( ) : String
+ getCourseStarted ( ) : Boolean
+ 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;
Call display(){
DO
IF(!studentName.equals(“ “)
DO
END DO
85
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
ENDIF
END DO
Super(courseName,instructorName,totalHours)
this.courseFee=courseFee
this.dailyHour=dailyHour
enrollDate=” “
roomNo=” “
downPayment=0
corurseStarted=false
courseCompleted=false
this.courseFee=courseFee
return courseFee
return enrollDate
return roomNo
this.dailyHour=dailyHour
return dailyHour
return downPayment
return courseStarted
return courseCompleted
DO
IF(courseStarted==true)
DO
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
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
CALL display( )
Super.display( )
DO
IF(courseStarted==true)
DO
END DO
END IF
END DO
89
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
super(courseName,instructorName,totalHours)
this.courseFee=courseFee
this.certificateAwardedBy=certificateAwardedBy
this.validTill=validTill
startDate=" "
examDate=" “
examCenter=" "
courseStarted=false
DO
IF(courseStarted==false)
DO
this.courseFee=courseFee
END DO
ELSE
DO
END DO
END IF
return courseFee
90
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
return startDate
return examDate
return examCenter
return certificateAwardedBy
return validTill
return courseStarted
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
END DO
END IF
CALL display( )
Super.display( )
DO
IF( courseStarted==true)
DO
END DO
END IF
END DO
92
Dibya Shrestha(L1C8)
CS4001N1 PROGRAMMING
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
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.
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
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.
getValidTill : This method is used to return the value of validity date as a string.
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)