Module Code & Module Title
CC4001NI Programming
Assessment Weightage & Type
30% Individual Coursework
Year and Semester
2021 Spring
Student Name: Ashma Maharjan
Group: C2
London Met ID: 20048835
College ID: np01cp4s210041@[Link]
Assignment Due Date: 23rd May, 2021
Assignment Submission Date: 17th May, 2021
I confirm that I understand my coursework needs to be submitted online via Google Classroom under the
relevant module page before the deadline in order for my assignment to be accepted and marked. I am
fully aware that late submissions will be treated as non-submission and a marks of zero will be awarded.
Table of Contents
List of Figures: ................................................................................................................. 3
List of Tables: .................................................................................................................. 3
Introduction: .................................................................................................................... 1
Class diagram: ................................................................................................................ 3
Pseudocode: ................................................................................................................... 8
Method Description: ...................................................................................................... 18
Testing: ......................................................................................................................... 22
Error Detection and Correction: ..................................................................................... 34
Conclusion: ................................................................................................................... 40
Bibliography: ................................................................................................................. 41
Appendix: ...................................................................................................................... 43
List of Figures:
Figure 1: Class diagram of the classes in BlueJ .............................................................. 3
Figure 2: Class diagram .................................................................................................. 4
Figure 3: Class diagram of Course class......................................................................... 5
Figure 4: Class diagram of AcademicCourse class ......................................................... 6
Figure 5: Class diagram of NonAcademicCourse class .................................................. 7
Figure 6: Assigning values in AcademicCourse class ................................................... 23
Figure 7: Inspection of AcademicCourse class ............................................................. 24
Figure 8: Assigning values in the method void register () .............................................. 24
Figure 9: Re-inspection of AcademicCourse class ........................................................ 25
Figure 10: Assigning values in NonAcademicCourse class ........................................... 27
Figure 11: Assigning values in method void register () .................................................. 28
Figure 12: Inspection of NonAcademicCourse class ..................................................... 28
Figure 13: Re-inspection of NonAcademicCourse class ............................................... 29
Figure 14: Inspection of NonAcademicCourse class ..................................................... 30
Figure 15: Removing non-academic course .................................................................. 31
Figure 16: Re-inspection of NonAcademicCourse class ............................................... 31
Figure 17: Displaying the details of AcademicCourse class .......................................... 32
Figure 18: Displaying the details of NonAcademicCourse class ................................... 33
Figure 19: Error-1 due to missing of semicolon ............................................................. 34
Figure 20: Error-1 Solved .............................................................................................. 34
Figure 21: Error-2 due to missing parentheses ............................................................. 35
Figure 22: Error-2 solved............................................................................................... 35
Figure 23: Error-3 due to incompatible types ................................................................ 36
Figure 24: Error-3 solved............................................................................................... 37
Figure 25: Error-4 due to fault in logic ........................................................................... 38
Figure 26: Output due to logical error ............................................................................ 38
Figure 27: Solving error-4.............................................................................................. 39
Figure 28: Output after solving error-4 .......................................................................... 39
List of Tables:
Table 1: Test 1- Inspect AcademicCourse class, register an academic course, and re-
inspect the AcademicCourse Class........................................................................ 22
Table 2: Test 2- Inspect NonAcademicCourse class, register a non-academic course, and
re-inspect the NonAcademicCourse Class ............................................................. 26
Table 3: Test 3-Inspect NonAcademicCourse class, change the status of isRemoved to
true and re-inspect the NonAcademicCourse class ............................................... 30
Table 4: Test 4- Display the detail of AcademicCourse and NonAcademicCourse classes.
............................................................................................................................... 32
CC4001NI PROGRAMMING
Introduction:
For the 1st course work of the module “Programming (Computing Faculty)” we are
expected to use “BlueJ” platform for completing our task related to coding. The main aim
of this assignment is to implement a real-world problem scenario using Object-oriented
concept of java by creating a class called Course which consist of two sub classes
Academic Course and Non-Academic Course.
Here, the program consists of three classes: Course, Academic Course and Non-
Academic Course. The Course class is the parent class which takes the information about
course like course ID, course name, name of the course leader and the duration of the
course. The course ID, course name and duration are initialized in the constructor and
course leader is initialized with empty string. The accessor method has been used to
return the values of each attributes. Then, new name of the course leader will be set. The
information about the course ID, course name and course duration will be displayed. If
the course leader is not an empty string, then the name of course leader will also be
displayed.
Similarly, Academic Course class is created which is the sub class of the Course class.
It takes information about lecturer name, level, credit, starting date, completion date,
number of assessments and registered status. The course ID, course name and duration
are called from the parent class constructor. Then, the attributes are initialized in the
constructor as per the instruction. The accessor and mutator methods are used to return
and set the values respectively and register method is created. And finally, information
about course ID, course name, duration and course leader are displayed by calling the
method from the parent class. If the academic course is already registered then lecturer
name, level, credit, starting date, completion date and number of assessments will also
be displayed.
Likewise, Non-Academic Course class is created which is also the sub class of the Course
class. It takes information about instructor name, start date, completion date, exam date
1
Ashma Maharjan
CC4001NI PROGRAMMING
prerequisite and status of registration and remove. Here also, constructor, accessor and
mutator methods and other methods like register and remove are created as per
instruction. Then method of parent class is called to display course ID, course name, and
duration. Also, instructor name, starting date, completion date and exam date are also
displayed, if the non-academic course is already registered.
2
Ashma Maharjan
CC4001NI PROGRAMMING
Class diagram:
Class diagram is the static diagram which represents the static view of an application.
They are the main building block in object-oriented modelling ([Link], 2021).
It describes the structure of a system by showing the system's classes, their attributes,
operations (or methods), and the relationships among objects ([Link],
2020). The class diagram consists of three rows in rectangular format where first row
consists the name of class, second row consists the attributes of the class and last or
third row consists the constructors and methods used in the class. Moreover, in the class
diagram, access modifiers such as public, private, protected and default are denoted by
+, -, #, and ~ signs respectively.
Figure 1: Class diagram of the classes in BlueJ
3
Ashma Maharjan
CC4001NI PROGRAMMING
Course
~ courseID: String
~ courseName: String
~ courseLeader: String
~ duration: int
~ Course (courseID: String, courseName: String, duration: int)
~ getCourseID (): String
~ getCourseName (): String
~ getCourseLeader (): String
~ getDuration (): int
~ setCourseLeader (courseLeader: String): void
~ display (): void
AcademicCourse NonAcademicCourse
~ lecturerName: String ~ instructorName: String
~ level: String ~ startDateNA: String
~ credit: String ~ completeDateNA: String
~ startDate: String ~ examDate: String
~ completeDate: String ~ preRequisite: String
~ assessment: int ~ registeredNA: boolean
~ registered: boolean ~ removed: boolean
~ AcademicCourse (courseID: String, courseName: String, duration: int, ~ NonAcademicCourse (courseID: String, courseName: String, duration:
level: String, credit: String, assessment: int) int, preRequisite: String)
~ getLevel (): String ~ getInstructorName (): String
~ getLecturerName (): String ~ getStartDateNA (): String
~ getCredit (): String ~ getCompleteDateNA (): String
~ getStartDate (): String ~ getExamDate (): String
~ getCompleteDate (): String ~ getPreRequisite (): String
~ getAssessment (): int ~ isRegisteredNA (): boolean
~ isRegistered (): boolean ~ isRemoved (): boolean
~ setLecturerName (lecturerName: String): void ~ setInstructorName (instructorName: String): void
~ setAssessment (assessment: String): void ~ register (courseLeader: String, instructorName: String, startDateNA:
~ register (courseLeader: String, lecturerName: String, startDate: String, String, completeDateNA: String, examDate: String): void
completeDate: String): void ~ remove (): void
~ display (): void ~ display (): void
Figure 2: Class diagram
4
Ashma Maharjan
CC4001NI PROGRAMMING
The class diagram for each class is given below:
Course class:
Course
~ courseID: String
~ courseName: String
~ courseLeader: String
~ duration: int
~ Course (courseID: String, courseName: String, duration: int)
~ getCourseID (): String
~ getCourseName (): String
~ getCourseLeader (): String
~ getDuration (): int
~ setCourseLeader (courseLeader: String): void
~ display (): void
Figure 3: Class diagram of Course class
5
Ashma Maharjan
CC4001NI PROGRAMMING
AcademicCourse class:
AcademicCourse
~ lecturerName: String
~ level: String
~ credit: String
~ startDate: String
~ completeDate: String
~ assessment: int
~ registered: boolean
~ AcademicCourse (courseID: String, courseName: String, duration: int,
level: String, credit: String, assessment: int)
~ getLevel (): String
~ getLecturerName (): String
~ getCredit (): String
~ getStartDate (): String
~ getCompleteDate (): String
~ getAssessment (): int
~ isRegistered (): boolean
~ setLecturerName (lecturerName: String): void
~ setAssessment (assessment: String): void
~ register (courseLeader: String, lecturerName: String, startDate: String,
completeDate: String): void
~ display (): void
Figure 4: Class diagram of AcademicCourse class
6
Ashma Maharjan
CC4001NI PROGRAMMING
NonAcademicCourse class:
NonAcademicCourse
~ instructorName: String
~ startDateNA: String
~ completeDateNA: String
~ examDate: String
~ preRequisite: String
~ registeredNA: boolean
~ removed: boolean
~ NonAcademicCourse (courseID: String, courseName: String, duration:
int, preRequisite: String)
~ getInstructorName (): String
~ getStartDateNA (): String
~ getCompleteDateNA (): String
~ getExamDate (): String
~ getPreRequisite (): String
~ isRegisteredNA (): boolean
~ isRemoved (): boolean
~ setInstructorName (instructorName: String): void
~ register (courseLeader: String, instructorName: String, startDateNA:
String, completeDateNA: String, examDate: String): void
~ remove (): void
~ display (): void
Figure 5: Class diagram of NonAcademicCourse class
7
Ashma Maharjan
CC4001NI PROGRAMMING
Pseudocode:
Pseudocode is a false code or representation of code in such a way that it is
understandable even by the person having basic knowledge on the programming. It is
written in the form of annotations and informational text that is written in plain English
only. It doesn’t have any syntax therefore cannot be compiled or interpreted by compiler.
Pseudocode focuses on explaining the working on each line of the program. It makes the
codes readable and makes it easier for the developer to understand the program easily.
Pseudocode acts as a bridge, in between the program and the algorithm ([Link],
2012).
The pseudocode for each class is given below:
Course class:
CREATE class Course
DECLARE instance variable courseID with String type
DECLARE instance variable courseName with String type
DECLARE instance variable courseLeader with String type
DECLARE instance variable duration with int type
CREATE constructor Course (PASS parameters courseID of String type,
courseName of String type, duration of int type)
DO
ASSIGN parameter courseID to instance variable courseID
ASSIGN parameter courseName to instance variable courseName
ASSIGN parameter duration to instance variable duration
ASSIGN empty value to courseLeader
ENDDO
8
Ashma Maharjan
CC4001NI PROGRAMMING
CREATE method getCourseID () with return type String
DO
RETURN courseID
ENDDO
CREATE method getCourseName () with return type String
DO
RETURN courseName
ENDDO
CREATE method getCourseLeader () with return type String
DO
RETURN courseLeader
ENDDO
CREATE method getDuration () with return type int
DO
RETURN duration
ENDDO
CREATE method setCourseLeader with no return type (PASS parameter
courseLeader of String type)
DO
ASSIGN parameter courseLeader to instance variable courseLeader
ENDDO
CREATE method display () with no return type
DO
PRINT courseID
PRINT courseName
PRINT duration
9
Ashma Maharjan
CC4001NI PROGRAMMING
IF (getCourseLeader () != “”)
PRINT courseLeader
ENDIF
ENDDO
AcademicCourse class:
CREATE class AcademicCourse which EXTENDS Course class
DECLARE instance variable lecturerName with String type
DECLARE instance variable level with String type
DECLARE instance variable credit with String type
DECLARE instance variable startDate with String type
DECLARE instance variable completeDate with String type
DECLARE instance variable assessment with int type
DECLARE instance variable registered with boolean type
CREATE constructor AcademicCourse (PASS parameters courseID of String
type, courseName of String type, duration of int type, level of String type, credit of
String type, assessment of int type)
DO
CALL super class’s constructor
ASSIGN parameter level to instance variable level
ASSIGN parameter credit to instance variable credit
ASSIGN parameter assessment to instance variable assessment
ASSIGN empty value to lecturerName
ASSIGN empty value to startDate
ASSIGN empty value to completeDate
INITIALIZE registered status to false
ENDDO
10
Ashma Maharjan
CC4001NI PROGRAMMING
CREATE method getLevel () with return type String
DO
RETURN level
ENDDO
CREATE method getLecturerName () with return type String
DO
RETURN lecturerName
ENDDO
CREATE method getCredit () with return type String
DO
RETURN credit
ENDDO
CREATE method getStartDate () with return type String
DO
RETURN startDate
ENDDO
CREATE method getCompleteDate () with return type String
DO
RETURN completeDate
ENDDO
CREATE method getAssessment () with return type int
DO
RETURN assessment
ENDDO
11
Ashma Maharjan
CC4001NI PROGRAMMING
CREATE method isRegistered () with return type boolean
DO
RETURN registered
ENDDO
CREATE method setLecturerName with no return type (PASS parameter
lecturerName of String type)
DO
ASSIGN parameter lecturerName to instance variable lecturerName
ENDDO
CREATE method setAssessment with no return type (PASS parameter
assessment of int type)
DO
ASSIGN parameter assessment to instance variable assessment
ENDDO
CREATE method register with no return type (PASS parameters courseLeader of
String type, lecturerName of String type, startDate of String type, completeDate of
String type)
DO
IF (isRegistered () == true)
PRINT lecturerName
PRINT startDate
PRINT completeDate
ELSE
CALL setCourseLeader (PASS parameter courseLeader of String
type)
ASSIGN parameter lecturerName to instance variable lecturerName
ASSIGN parameter startDate to instance variable startDate
12
Ashma Maharjan
CC4001NI PROGRAMMING
ASSIGN parameter completeDate to instance variable
completeDate
CHANGE registered status to true
ENDIF
ENDDO
CREATE method display () with no return type
DO
CALL display () method of super class
IF (isRegistered () == true)
PRINT lecturerName
PRINT level
PRINT credit
PRINT startDate
PRINT completeDate
PRINT assessment
ENDIF
ENDDO
13
Ashma Maharjan
CC4001NI PROGRAMMING
NonAcademicCourse class:
CREATE class NonAcademicCourse which EXTENDS Course class
DECLARE instance variable instructorName with String type
DECLARE instance variable startDateNA with String type
DECLARE instance variable completeDateNA with String type
DECLARE instance variable examDate with String type
DECLARE instance variable preRequisite with String type
DECLARE instance variable registeredNA with booleam type
DECLARE instance variable removed with boolean type
CREATE constructor NonAcademicCourse (PASS parameters courseID of String
type, courseName of String type, duration of int type, preRequisite of String
type)
DO
CALL super class’s constructor
ASSIGN parameter preRequisite to instance variable preRequisite
ASSIGN empty value to startDateNA
ASSIGN empty value to completeDateNA
ASSIGN empty value to examDate
INITIALIZE registeredNA status to false
INITIALIZE removed status to false
ENDDO
CREATE method getInstructorName () with return type String
DO
RETURN instructorName
ENDDO
CREATE method getStartDateNA () with return type String
DO
14
Ashma Maharjan
CC4001NI PROGRAMMING
RETURN startDateNA
ENDDO
CREATE method getCompleteDateNA () with return type String
DO
RETURN completeDateNA
ENDDO
CREATE method getExamDate () with return type String
DO
RETURN examDate
ENDDO
CREATE method getPreRequisite () with return type String
DO
RETURN preRequisite
ENDDO
CREATE method isRegisteredNA () with return type boolean
DO
RETURN registeredNA
ENDDO
CREATE method isRemoved () with return type boolean
DO
RETURN removed
ENDDO
15
Ashma Maharjan
CC4001NI PROGRAMMING
CREATE method seInstructorName with no return type (PASS parameter
instructorName of String type)
DO
IF (isRegisteredNA () == false)
ASSIGN parameter instructorName to instance variable
instructorName
ELSE
PRINT a message that non-academic course is already registered
therefore it is not possible to change the instructor’s name
ENDIF
ENDDO
CREATE method register with no return type (PASS parameters courseLeader of
String type, instructorName of String type, startDateNA of String type,
completeDateNA of String type, examDate of String type)
DO
IF (isRegisteredNA () == true)
CALL method setInstructorName (PASS parameter instructorName
of String type)
INTIALIZE registeredNA status to true
CALL super class’s method setCourseLeader (PASS parameter
courseLeader of String type)
ASSIGN parameter startDateNA to instance variable startDateNA
ASSIGN parameter completeDateNA to instance variable
completeDateNA
ASSIGN parameter examDate to instance variable examDate
ELSE
PRINT a message that non-academic course is already registered
ENDIF
ENDDO
16
Ashma Maharjan
CC4001NI PROGRAMMING
CREATE method remove () with no return type
DO
IF (isRemoved () == true)
PRINT a message that non-academic course is already removed
ELSE
CALL super class’s method setCourseLeader (PASS parameter with
empty value)
ASSIGN empty value to instructorName
ASSIGN empty value to startDateNA
ASSIGN empty value to completeDateNA
ASSIGN empty value to examDate
SET status of registeredNA to false
SET status of removed to true
ENDIF
ENDDO
CREATE method display () with no return type
DO
CALL display () method of super class
IF (isRegisteredNA () == true)
PRINT instructorName
PRINT startDateNA
PRINT completeDateNA
PRINT examDate
ENDIF
ENDDO
17
Ashma Maharjan
CC4001NI PROGRAMMING
Method Description:
Method is a block of code where data, known as parameters are passed and performs
certain actions when called ([Link], n.d.). In this program, we have three classes
and different methods are used in these classes. The brief description of each method in
each class is given below:
Course class:
Different methods used in Course class are:
• getCourseID ():
It is an accessor method with String return type which returns courseID.
• getCourseName ():
It is an accessor method with String return type which returns courseName.
• getCourseLeader ():
It is an accessor method with String return type which returns courseLeader.
• getDuration ():
It is an accessor method with int return type which returns duration.
• setCourseLeader (String courseLeader):
It is a mutator method with no return type which sets new name to the
courseLeader.
• display ():
It doesn’t have return type and displays the details of course such as
courseID, coursename, and duration and, if the courseLeader is not an
empty string, the name of the courseLeader will also be displayed.
AcademicCourse class:
Different methods used in AcademicCourse class are:
• getLevel ():
It is an accessor method with String return type which returns level.
18
Ashma Maharjan
CC4001NI PROGRAMMING
• getLecturerName ():
It is an accessor method with String return type which returns
LecturerName.
• getCredit ():
It is an accessor method with String return type which returns credit.
• getStartDate ():
It is an accessor method with String return type which returns startDate.
• getCompleteDate ():
It is an accessor method with String return type which returns
completeDate.
• getAssessment ():
It is an accessor method with int return type which returns assessment.
• isRegistered ():
It is an accessor method with boolean return type which returns registered
status.
• setLecturerName (String lecturerName):
It is a mutator method with no return type which assigns the new value to
the lecturer’s name.
• setAssessment (int assessment):
It is a mutator method with no return type which accepts assigns the new
value to the number of assessments attribute.
• register (String courseLeader, String lecturerName, String startDate, String
completeDate):
It is a method with no return type which accepts four parameters. If the
academic course is already registered, an appropriate message is
displayed. If not, respective values are passed to the parameters.
• display ():
It is a method with no return type which calls the display method from the
parent class and displays the details of academic course if the academic
course is already registered.
19
Ashma Maharjan
CC4001NI PROGRAMMING
NonAcademicCourse class:
Different methods used in NonAcademicCourse class are:
• getInstructorName ():
It is an accessor method with String return type which returns
instructorName.
• getStartDateNA ():
It is an accessor method with String return type which returns startDateNA.
• getCompleteDateNA ():
It is an accessor method with String return type which returns
completeDateNA.
• getStartDate ():
It is an accessor method with String return type which returns the startDate.
• getCompleteDate ():
It is an accessor method with String return type which returns the
completeDate.
• getExamDate ():
It is an accessor method with String return type which returns examDate.
• getPreRequisite ():
It is an accessor method with String return type which returns preRequisite.
• isRegisteredNA ():
It is an accessor method with boolean return type which returns the
registeredNA status.
• isRemoved ():
It is an accessor method with boolean return type which returns the
removed status.
• setInstructorName (String instructorName):
It is a mutator method with no return type. If the non-academic course is not
registered yet, then new value is assigned to the instructor’s name
otherwise suitable message is displayed.
20
Ashma Maharjan
CC4001NI PROGRAMMING
• register (String courseLeader, String instructorName, String startDateNA, String
completeDateNA, String examDate):
It is a method with no return type which accepts five parameters. If the non-
academic course is not registered, then respective values will be assigned
to the parameters otherwise suitable message is displayed.
• remove ():
It is a method with no return type. If the course is already removed then
suitable message will be displayed. Otherwise, the parameters will be
assigned with the respective values.
• display ():
It is a method with no return type which calls the display method from the
parent class and displays the details of non-academic course if it is already
registered.
21
Ashma Maharjan
CC4001NI PROGRAMMING
Testing:
Testing means evaluating something with the intent to find whether it satisfies the
specified objectives or not. It helps to identify any gaps, errors, or missing requirements
in contrary to the actual requirements ([Link], 2021).
Test 1: Inspect AcademicCourse class, register an academic course, and re-inspect the
AcademicCourse Class
Test No: 1
Objective: To inspect AcademicCourse class, register an academic course
and re-inspect the AcademicCourse class
Action: → The AcademicCourse is called with following arguments:
courseID = “101”
courseName = “Java”
duration = 1
level = “Level 4”
credit = “45”
assessment = 2
→ Inspection of AcademicCourse class.
→ Method void register () is called with following arguments:
courseLeader = “John Andrew”
lecturerName = “Michale Joe”
startDate = “2021 July 2”
completeDate = “2022 July 2”
→ Re-inspection of AcademicCourse class.
Expected Result: The Academic Course will be registered.
Actual Result: The Academic Course was registered.
Conclusion: The test is successful.
Table 1: Test 1- Inspect AcademicCourse class, register an academic course, and re-inspect the
AcademicCourse Class
22
Ashma Maharjan
CC4001NI PROGRAMMING
Output Results:
Figure 6: Assigning values in AcademicCourse class
23
Ashma Maharjan
CC4001NI PROGRAMMING
Figure 7: Inspection of AcademicCourse class
Figure 8: Assigning values in the method void register ()
24
Ashma Maharjan
CC4001NI PROGRAMMING
Figure 9: Re-inspection of AcademicCourse class
25
Ashma Maharjan
CC4001NI PROGRAMMING
Test 2: Inspect NonAcademicCourse class, register a non-academic course and re-
inspect the NonAcademicCourse Class
Test No: 2
Objective: To inspect NonAcademicCourse class, register a non-academic
course and re-inspect the NonAcademicCourse class
Action: → The NonAcademicCourse is called with following arguments:
courseID = “201”
courseName = “Machine Learning”
duration = 2
preRequisite = “Java Programming”
→ Inspection of NonAcademicCourse class.
→ Method void register () is called with following arguments:
courseLeader = “Jessica Mason”
instructorName = “Jack William”
startDateNA = “2021 August 10”
completeDateNA = “2023 August 10”
examDate = “2023 April 25”
→ Re-inspection of NonAcademicCourse class.
Expected Result: The Non-Academic Course will be registered.
Actual Result: The Non-Academic Course was registered.
Conclusion: The test is successful.
Table 2: Test 2- Inspect NonAcademicCourse class, register a non-academic course, and re-inspect the
NonAcademicCourse Class
26
Ashma Maharjan
CC4001NI PROGRAMMING
Output Results:
Figure 10: Assigning values in NonAcademicCourse class
27
Ashma Maharjan
CC4001NI PROGRAMMING
Figure 12: Inspection of NonAcademicCourse class
Figure 11: Assigning values in method void register ()
28
Ashma Maharjan
CC4001NI PROGRAMMING
Figure 13: Re-inspection of NonAcademicCourse class
29
Ashma Maharjan
CC4001NI PROGRAMMING
Test 3: Inspect NonAcademicCourse class again, change the status of isRemoved to true
and re-inspect the NonAcademicCourse class
Test No: 3
Objective: To inspect NonAcademicCourse class, change the status of
isRemoved to true and re-inspect the NonAcademicCourse class
Action: → Inspection of NonAcademicCourse class.
→ Method void remove () is called.
→ Re-inspection of NonAcademicCourse class.
Expected Result: The Non-Academic Course will be removed and registration status
of non-academic course will be false.
Actual Result: The Non-Academic Course was removed registration status of
non-academic course became false.
Conclusion: The test is successful.
Table 3: Test 3-Inspect NonAcademicCourse class, change the status of isRemoved to true and re-inspect
the NonAcademicCourse class
Output Results:
Figure 14: Inspection of NonAcademicCourse class
30
Ashma Maharjan
CC4001NI PROGRAMMING
Figure 15: Removing non-academic course
Figure 16: Re-inspection of NonAcademicCourse class
31
Ashma Maharjan
CC4001NI PROGRAMMING
Test 4: Display the detail of AcademicCourse and NonAcademicCourse classes.
Test No: 3
Objective: To display the detail of AcademicCourse and NonAcademicCourse
classes.
Action: → Method void display () of AcadmeicCourse class is called.
→ Method void display () of NonAcademicCourse class is called.
Expected Result: The details of Academic and Non-Academic course will be
displayed.
Actual Result: The details of Academic and Non-Academic course was displayed.
Conclusion: The test is successful.
Table 4: Test 4- Display the detail of AcademicCourse and NonAcademicCourse classes.
Output Results:
Figure 17: Displaying the details of AcademicCourse class
32
Ashma Maharjan
CC4001NI PROGRAMMING
Figure 18: Displaying the details of NonAcademicCourse class
33
Ashma Maharjan
CC4001NI PROGRAMMING
Error Detection and Correction:
While doing the coursework different types of errors were encountered in the program
and they were solved with proper observation.
Syntax error:
A syntax error is an error in the source code of a program. Such type of error occurs if
any aspects of the code do not conform with the syntactical rule of the programming
language. They are compile time error which are indicated by the compiler during the
compile time ([Link], 2021).
Some syntax errors were found in the program which are displayed below:
Figure 19: Error-1 due to missing of semicolon
This error was encountered due the missing semicolon at the end of statement and was
solved by putting the semicolon at the end of the statement.
Figure 20: Error-1 Solved
34
Ashma Maharjan
CC4001NI PROGRAMMING
Figure 21: Error-2 due to missing parentheses
When the display method was called, parentheses was not included after the method
name which led to the error. This error was solved by including the parentheses after the
method name.
Figure 22: Error-2 solved
35
Ashma Maharjan
CC4001NI PROGRAMMING
Semantic error:
A semantic error is such kind of error which occurs due to improper use of program
statements. Semantic error can be compile time or run time error. Using a variable which
was not initialized in the program creates semantic error. Similarly, type incompatibility,
for example giving string value to the variable of integer type also leads to semantic error.
Some semantic error was found in the program which are displayed below:
Figure 23: Error-3 due to incompatible types
36
Ashma Maharjan
CC4001NI PROGRAMMING
In the above case, courseID is of String data type but while passing the input value integer
type of value was passed which cause the error. This error was solved by passing String
value instead of integer value to courseID.
Figure 24: Error-3 solved
37
Ashma Maharjan
CC4001NI PROGRAMMING
Logical error:
Logical error is a run time error that cannot be detected by the compiler and is
encountered during runtime. Such type of error occurs due to fault in the logic or structure
of the program. They cause the program to behave unexpectedly i.e., the program will
produce different result than expected. These types of error are difficult to be detected
([Link], 2021).
Some logical error was found in the program which are displayed below:
Figure 25: Error-4 due to fault in logic
Figure 26: Output due to logical error
This error was encountered due to fault in the logic while writing the program. As per the
instruction details of course leader was to be displayed only if the course leader was not
empty. But the output result was not expected due to the logical error.
38
Ashma Maharjan
CC4001NI PROGRAMMING
To solve the error, changes was made to the logical structure of the program by using the
correct statement.
Figure 27: Solving error-4
Figure 28: Output after solving error-4
39
Ashma Maharjan
CC4001NI PROGRAMMING
Conclusion:
In conclusion, three classes were created in this coursework using BlueJ. They were:
Course class, AcademicCourse class and NonAcademicCourse class. The Course class
was the parent class of both AcademicCourse and NonAcademicCourse classes. That is
there were two sub classes in the program, AcademicCourse and NonAcademicCourse
class. Different data types were used for different attributes in each class. As well as
various constructors and methods were used in each class with the aim of performing
specified action. Similarly, class diagram was made for each class. After then, rough view
of the code was presented through the pseudocode. Then, each method of each class
was described in brief and the test inspection was done for each class. Finally, different
errors detected throughout the program was presented along with their solution.
So, this program helped me to build concept on inheritance, use of various data types,
constructors and methods. Also, thought the coursework I came to learn about the class
diagram and the pseudocode as well and the process to build them up. Similarly, I came
to know how the classes can be tested without the need of creating the object for the
validity purpose. And, finally, I was able to learn about different types of error which may
encounter while writing the program and the methods to detect and solve them.
This coursework helped me to gain a lot of knowledge but, however, I had to face
difficulties in some part of the coursework, especially in the coding part. The first difficulty
I encountered was in understanding the requirements of the coursework. Since, I was
new to programming I had to face a lot of difficulties in understanding many terms in the
coursework. But regular interaction with the teachers and friends, researches in the
internet, proper go-through to the lecture content and YouTube videos related to the java
programming helped me a lot to overcome all those difficulties.
Finally, keeping on side all those challenges and difficulties, this coursework was fun and
knowledgeful in overall. I came to learn about many new topics related to java
programming throughout this project and with all efforts and hard work this coursework
was submitted on the time.
40
Ashma Maharjan
CC4001NI PROGRAMMING
Bibliography:
[Link], 2021. Writing error-free code. [Online]
Available at: [Link]
[Accessed 17 05 2021].
[Link], 2012. Pseudocode Java. [Online]
Available at: [Link]
java#:~:text=In%20Java%2C%20a%20term%20used,the%20implementation%20of%20
an%20algorithm.&text=Pseudocode%20is%20the%20false%20code,level%20program
ming%20knowledge%20can%20understand.
[Accessed 14 05 2021].
[Link], 2021. Syntax Error. [Online]
Available at: [Link]
[Accessed 17 05 2021].
[Link], 2021. Software Testing - Quick Guide. [Online]
Available at:
[Link]
[Accessed 15 05 2021].
[Link], 2021. UML - Class Diagram. [Online]
Available at: [Link]
[Accessed 14 05 2021].
[Link], 2020. What is Class Diagram?. [Online]
Available at: [Link]
language/what-is-class-diagram/
[Accessed 14 05 2021].
41
Ashma Maharjan
CC4001NI PROGRAMMING
[Link], n.d. Java Methods. [Online]
Available at:
[Link]
20block,are%20also%20known%20as%20functions.
[Accessed 15 05 2021].
42
Ashma Maharjan
CC4001NI PROGRAMMING
Appendix:
Course class:
/**
* Write a description of class Course here.
*
* @Ashma Maharjan
* @17/05/2021
*/
public class Course
{
/*
Course class has four attributes, which correspond to the courseID, course
name, course leader and duration.
The courseID and coursename are each represented as a string of text and
duration as a number.
*/
String courseID, courseName, courseLeader;
int duration;
/*
Creating constructor where courseID, coursename and duration are initialized in
the constructor by being assigned the value of the constructor's parameters.
The courseLeader is initialized with empty string (“”) in the constructor.
*/
43
Ashma Maharjan
CC4001NI PROGRAMMING
Course(String courseID, String courseName, int duration)
{
[Link] = courseID;
[Link] = courseName;
[Link] = duration;
courseLeader = "";
}
// Creating accessor (getter) method for each attribute.
String getCourseID()
{
return courseID;
}
String getCourseName()
{
return courseName;
}
String getCourseLeader()
{
return courseLeader;
}
int getDuration()
{
return duration;
}
44
Ashma Maharjan
CC4001NI PROGRAMMING
// Creating mutator (setter) method for courseLeader.
void setCourseLeader(String courseLeader)
{
[Link] = courseLeader;
}
/*
Creating display method which displays courseID, coursename, and duration and,
if the courseLeader is not an empty string, the name of the courseLeader also
should be displayed.
*/
void display()
{
[Link]("The details of course are displayed below: ");
[Link]("Course ID: " +getCourseID());
[Link]("Course Name: " +getCourseName());
[Link]("Course Duration(in years): " +getDuration());
if(getCourseLeader() != "") {
[Link]("Course Leader: " +getCourseLeader());
}
}
}
45
Ashma Maharjan
CC4001NI PROGRAMMING
AcademicCourse class:
/**
* Write a description of class Course here.
*
* @Ashma Maharjan
* @17/05/2021
*/
public class AcademicCourse extends Course
{
/*
AcademicCourse class is a subclass of the Course class and has seven attributes:
Lecturer name - a string of characters
Level - a string of characters
Credit - a string of characters
Starting Date - a string of characters
Completion Date - a string of characters
Number of Assessments- a whole number
isRegistered - either true or false (boolean)
*/
String lecturerName, level, credit, startDate, completeDate;
int assessment;
boolean registered;
/*
Creating constructor which accepts six parameters, which are the courseID,
coursename, duration, level, credit, and number of assessments.
46
Ashma Maharjan
CC4001NI PROGRAMMING
A call is made to the superclass constructor with three parameters, the courseID,
coursename, and duration.
Additionally, in the constructor, assign instructor name, starting date and
completion date as an empty ("") string, isRegistered status is initialized to false.
*/
AcademicCourse(String courseID, String courseName, int duration, String level, String
credit, int assessment)
{
super(courseID, courseName, duration);
[Link] = level;
[Link] = credit;
[Link] = assessment;
lecturerName = "";
startDate = "";
completeDate = "";
registered = false;
}
// Creating accessor (getter) method for each attribute.
String getLevel()
{
return level;
}
String getLecturerName()
{
return lecturerName;
}
47
Ashma Maharjan
CC4001NI PROGRAMMING
String getCredit()
{
return credit;
}
String getStartDate()
{
return startDate;
}
String getCompleteDate()
{
return completeDate;
}
int getAssessment()
{
return assessment;
}
boolean isRegistered()
{
return registered;
}
//Creating mutator (setter) method for lecturer name and number of assessments.
void setLecturerName(String lecturerName)
{
[Link] = lecturerName;
}
48
Ashma Maharjan
CC4001NI PROGRAMMING
void setAssessment(int assessment)
{
[Link] = assessment;
}
/*
Creating register method which accepts four parameters that includes a course
leader name, lecturer name, starting date, and completion date.
If the academic course is already registered, an appropriate message including the
instructor’s name, starting date and completion date is displayed.
*/
void register(String courseLeader, String lecturerName, String startDate, String
completeDate)
{
if(isRegistered() == true) {
[Link]("The academic course is already registered. The details of
academic course are displayed below:");
[Link]("Lecturer name: " +getLecturerName());
[Link]("Starting date: " +getStartDate());
[Link]("Completion date: " +getCompleteDate());
}
else {
[Link](courseLeader);
[Link] = lecturerName;
[Link] = startDate;
[Link] = completeDate;
registered = true;
49
Ashma Maharjan
CC4001NI PROGRAMMING
}
}
/*
Creating display method to display details of the Course from the parent class.
If the academic course is already registered then lecturer name, level, credit,
starting date, completion date and number of assessments must also be displayed.
*/
void display()
{
[Link]();
if(isRegistered() == true) {
[Link]("The academic course already is registered. The details of
academic course are displayed below: ");
[Link]("Lecturer name: " +getLecturerName());
[Link]("Level: " +getLevel());
[Link]("Credit hours: " +getCredit());
[Link]("Starting date: " +getStartDate());
[Link]("Completion date: " +getCompleteDate());
[Link]("Number of assessments: " +getAssessment());
}
}
}
50
Ashma Maharjan
CC4001NI PROGRAMMING
NonAcademicCourse class:
/**
* Write a description of class Course here.
*
* @Ashma Maharjan
* @17/05/2021
*/
public class NonAcademicCourse extends Course //Non-academic course class is also
the child class of Course (parent) class.
{
/*
NonAcademicCourse class is also a subclass of the Course class and it has seven
attributes:
Instructor name - a string of character
Duration - a whole number
Start date - a string of character
Completion date - a string of character
Exam date - a string of character
prerequisite - a string of character
isRegistered - either true or false (boolean)
isRemoved - either true or false (boolean)
*/
String instructorName, startDateNA, completeDateNA, examDate, preRequisite;
// Here, NA represents attributes for Non Academic Course.
boolean registeredNA, removed;
51
Ashma Maharjan
CC4001NI PROGRAMMING
/*
Creating constructor which accepts four parameters which are the courseID,
course name, duration and prerequisite.
A call is made to the superclass constructor with three parameters, the courseID,
course name and duration.
The attribute prerequisite is given the corresponding parameter value.
Additionally, the constructor initializes starting date, completion date and exam
date to empty ("") string, and isRegistered and isRemoved status to false.
*/
NonAcademicCourse(String courseID, String courseName, int duration, String
preRequisite)
{
super(courseID, courseName, duration);
[Link] = preRequisite;
startDateNA = "";
completeDateNA = "";
examDate = "";
registeredNA = false;
removed = false;
}
// Creating accessor (getter) method for each attributes.
String getInstructorName()
{
return instructorName;
}
52
Ashma Maharjan
CC4001NI PROGRAMMING
String getStartDateNA()
{
return startDateNA;
}
String getCompleteDateNA()
{
return completeDateNA;
}
String getExamDate()
{
return examDate;
}
String getPreRequisite()
{
return preRequisite;
}
boolean isRegisteredNA()
{
return registeredNA;
}
boolean isRemoved()
{
return removed;
}
53
Ashma Maharjan
CC4001NI PROGRAMMING
/*
Creating mutator (setter) method for instructor name.
If the non-academic course has not registered yet, the new value is assigned to
the instructor name attribute.
If the non-academic course is already registered, then a suitable message is output
to the user indicating that it is therefore not possible to change the instructor’s
name.
*/
void setInstructorName(String instructorName)
{
if(isRegisteredNA() == false) {
[Link] = instructorName;
}
else {
[Link]("The non-academic course is already registered. Therefore, it
is not possible to change the instructor name.");
}
}
/*
Creating register method for registering the non-academic course.
The method has five parameters, the course leader name, instructor name, starting
date, completion date, and exam date.
If the non-academic course has not registered yet, the method to set the instructor
name is called with the instructor’s name as a parameter and isRegistered status
54
Ashma Maharjan
CC4001NI PROGRAMMING
is set to true, otherwise a suitable message is displayed to the user indicating that
the course is already registered.
*/
void register(String courseLeader, String instructorName, String startDateNA, String
completeDateNA, String examDate)
{
if(isRegisteredNA() == false) {
setInstructorName(instructorName);
registeredNA = true;
[Link](courseLeader);
[Link] = startDateNA;
[Link] = completeDateNA;
[Link] = examDate;
}
else {
[Link]("The non-academic course is already registered.");
}
}
/*
Creating remove method.
If the non-academic course is already removed a suitable message is output.
If the course is not removed yet, the method to set the course leader name (method
to set course leader name in parent class) is called with "" as a parameter, the
instructor’s name, the starting date, completion date and exam date are set to "",
the status of isRegistered is set to false and the isRemoved status is set to true.
55
Ashma Maharjan
CC4001NI PROGRAMMING
*/
void remove()
{
if(isRemoved() == true) {
[Link]("The non-academic course is already removed.");
}
else {
[Link]("");
instructorName = "";
startDateNA = "";
completeDateNA = "";
examDate = "";
registeredNA = false;
removed = true;
}
}
/*
Creating display method to display details of Course from parent class.
If the non-academic course is already registered then instructor name, starting
date, completion date and exam date must also be displayed.
*/
void display()
{
[Link]();
if(isRegisteredNA() == true) {
56
Ashma Maharjan
CC4001NI PROGRAMMING
[Link]("The non-academic course is already registered. The details
of non-academic course are displayed below: ");
[Link]("Instructor name: " +getInstructorName());
[Link]("Starting date: " +getStartDateNA());
[Link]("Completion date: " +getCompleteDateNA());
[Link]("Exam date: " +getExamDate());
}
}
}
57
Ashma Maharjan