Swopnil Dahal PDF
Swopnil Dahal PDF
2023 Autumn
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 mark of zero will be awarded.
CS400NI PROGRAMMING
TABLE OF CONTENTS
1. INTRODUCTION ................................................................................................................ 4
2. CLASS DIAGRAM .............................................................................................................. 5
2.1 Class Diagram of Teacher Class ................................................................................. 6
2.2 Class Diagram of Lecturer Class ................................................................................ 7
2.3 Class Diagram of Tutor Class ..................................................................................... 8
2.4 Final Class Diagram ................................................................................................... 9
3. PSEUDOCODE .................................................................................................................10
3.1 Pseudocode of Teacher Class ..................................................................................10
3.2 Pseudocode of Lecturer Class ...................................................................................12
3.3 Pseudocode of Tutor Class ........................................................................................15
4. METHOD DESCRIPTION .................................................................................................18
4.1 Method Description of Teacher Class.........................................................................18
4.2 Method Description of Lecturer Class ........................................................................19
4.3 Method Description of Tutor Class .............................................................................20
5. TESTING ..........................................................................................................................22
5.1 Test 1.........................................................................................................................22
5.2 Test 2.........................................................................................................................31
5.3 Test 3.........................................................................................................................37
5.4 Test 4.........................................................................................................................43
6. ERROR DETECTION AND CORRECTION .......................................................................48
6.1 Syntax Error ..............................................................................................................48
6.2 Sematic Error.............................................................................................................50
6.3 Logical Error ..............................................................................................................52
7. CONCLUSION ..................................................................................................................54
8. BIBLIOGRAPHY ...............................................................................................................54
9. APPENDIX ........................................................................................................................55
2
SWOPNIL DAHAL
CS400NI PROGRAMMING
LIST OF FIGURES
3
SWOPNIL DAHAL
CS400NI PROGRAMMING
1. INTRODUCTION
Java, which was first released by Sun Microsystems in 1995, is notable for being an
object-oriented and flexible programming language. Java stands out due to its platform
independence, which is made possible by the Java Virtual Machine (JVM), which enables
Java programs to execute on a variety of devices. One defining characteristic has been
the "Write Once, Run Anywhere" (WORA) approach, which emphasizes platform
portability. Java supports many different application areas and has a large ecosystem of
libraries and frameworks in addition to a strong standard library. Because of its C++-
influenced syntax, which prioritizes readability and maintainability, it is easily understood
by developers. By compiling Java programs into bytecode, cross-platform compatibility
and security are enhanced. (Arun, 2023)
In our Coursework we are required to create 3 Classes Teacher, Lecturer, and Tutor
classes. The Teacher class serves as the Parent class, with Lecturer and Tutor as
subclasses, inheriting attributes and behaviors from Teacher.
The Teacher class Stores information such as teacher ID, name, address, working type,
employment status, and working hours. Lecturer and Tutor classes extend the Teacher
class, incorporating additional attributes and methods specific to their roles.
The Lecturer class introduces features like department, years of experience, graded
score, and grading functionality. It extends the Teacher class. The Tutor class extends the
Teacher class to include salary, specialization, academic qualifications, performance
index, and certification-related methods, catering to the specifics of a tutoring role.
The goal is to implement methods, constructors, and objects based on the provided
specifications.
4
SWOPNIL DAHAL
CS400NI PROGRAMMING
2. CLASS DIAGRAM
5
SWOPNIL DAHAL
CS400NI PROGRAMMING
6
SWOPNIL DAHAL
CS400NI PROGRAMMING
7
SWOPNIL DAHAL
CS400NI PROGRAMMING
8
SWOPNIL DAHAL
CS400NI PROGRAMMING
9
SWOPNIL DAHAL
CS400NI PROGRAMMING
3. PSEUDOCODE
3.1 Pseudocode of Teacher Class
START
CREATE Class Teacher
DECLARE
int teacherId
String teacherName
String address
String workingType
String employmentStatus
int workingHours
ENDDO
10
SWOPNIL DAHAL
CS400NI PROGRAMMING
11
SWOPNIL DAHAL
CS400NI PROGRAMMING
START
CREATE Class Lecturer INHERITS Teacher
DECLARE
String department
int yearsOfExperience
int gradedScore
boolean hasGraded
ENDDO
CREATE Lecturer(int teacherId, String teacherName, String address, String
workingType, int workingHours, String employmentStatus,
String department, int yearsOfExperience)
CALL super(teacherId, teacherName, address, workingType, employmentStatus,
workingHours)
ASSIGN this.department TO department
ASSIGN this.yearsOfExperience TO yearsOfExperience
ASSIGN this.hasGraded TO false
ASSIGN this.gradedScore TO 0
ENDDO
CREATE String getDepartment()
RETURN this.department
ENDDO
CREATE int getYearsOfExperience()
RETURN this.yearsOfExperience
ENDDO
CREATE int getGradedScore()
RETURN this.gradedScore
ENDDO
12
SWOPNIL DAHAL
CS400NI PROGRAMMING
ENDDO
CREATE void display()
CALL super.display()
Print "Department: " + this.department
Print "Years of Experience: " + this.yearsOfExperience
IF this.hasGraded
DECLARE
char grade
ENDDO
IF this.gradedScore >= 70
ASSIGN grade TO 'A'
ELSE IF this.gradedScore >= 60
ASSIGN grade TO 'B'
ELSE IF this.gradedScore >= 50
ASSIGN grade TO 'C'
ELSE IF this.gradedScore >= 40
ASSIGN grade TO 'D'
ELSE
ASSIGN grade TO 'E'
ENDIF
Print "Graded Score: " + this.gradedScore
Print "Grade: " + grade
ELSE
Print "Score has not been graded yet."
ENDIF
ENDDO
END
14
SWOPNIL DAHAL
CS400NI PROGRAMMING
START
CREATE Class Tutor INHERITS Teacher
DECLARE
double salary
String specialization
String academicQualifications
int performanceIndex
boolean isCertified
ENDDO
CREATE Tutor(int teacherId, String teacherName, String address, String workingType,
String employmentStatus,
int workingHours, double salary, String specialization, String academicQualifications, int
performanceIndex)
CALL super(teacherId, teacherName, address, workingType, employmentStatus,
workingHours)
ASSIGN this.salary TO salary
ASSIGN this.specialization TO specialization
ASSIGN this.academicQualifications TO academicQualifications
ASSIGN this.performanceIndex TO performanceIndex
ASSIGN this.isCertified TO false
ENDDO
CREATE double getSalary()
RETURN this.salary
ENDDO
CREATE String getSpecialization()
RETURN this.specialization
ENDDO
15
SWOPNIL DAHAL
CS400NI PROGRAMMING
16
SWOPNIL DAHAL
CS400NI PROGRAMMING
ENDIF
ELSE
PRINT "Salary cannot be changed. Tutor has already been certified."
ENDIF
ENDDO
CREATE void removeTutor()
IF NOT this.isCertified
ASSIGN this.salary TO 0
ASSIGN this.specialization TO ""
ASSIGN this.academicQualifications TO ""
ASSIGN this.performanceIndex TO 0
ASSIGN this.isCertified TO false
PRINT "Tutor removed successfully."
ELSE
PRINT "Certified tutor cannot be removed."
ENDIF
ENDDO
CREATE void display()
CALL super.display()
IF this.isCertified
PRINT "Salary: $" + this.salary
PRINT "Specialization: " + this.specialization
PRINT "Academic Qualifications: " + this.academicQualifications
PRINT "Performance Index: " + this.performanceIndex
PRINT "Certified: Yes"
ENDIF
ENDDO
END
17
SWOPNIL DAHAL
CS400NI PROGRAMMING
4. METHOD DESCRIPTION
4.1 Method Description of Teacher Class
18
SWOPNIL DAHAL
CS400NI PROGRAMMING
• Constructor (Lecturer):
This method creates a new Lecturer object by extending the Teacher class, with additional
attributes such as department, years of experience, graded score, and grading status.
It is an accessor method that retrieves and returns the department of the lecturer.
It is an accessor method that retrieves and returns the years of experience of the lecturer.
It is an accessor method that retrieves and returns the graded score of the lecturer.
It is an accessor method that retrieves and returns whether the lecturer has graded
assignments.
It is an accessor method that sets the graded score of the lecturer to a specified value.
• Method (gradeAssignment):
19
SWOPNIL DAHAL
CS400NI PROGRAMMING
• Method (display):
Displays information about the lecturer, including details from the superclass (Teacher),
such as ID, name, address, working type, employment status, and working hours.
Additionally, it displays the department, years of experience, and graded score of the
lecturer.
• Constructor (Tutor):
This method creates a new Tutor object by extending the Teacher class, with additional
attributes such as salary, specialization, academic qualifications, performance index,
and certification status.
It is an accessor method that retrieves and returns the salary of the tutor.
It is an accessor method that retrieves and returns the specialization of the tutor.
It is an accessor method that retrieves and returns the academic qualifications of the
tutor.
20
SWOPNIL DAHAL
CS400NI PROGRAMMING
It is an accessor method that retrieves and returns the performance index of the tutor.
It is an accessor method that retrieves and returns whether the tutor is certified.
• Method (setSalary):
This method sets the salary of the tutor based on specified criteria, considering the
performance index, and working hours.
• Method (removeTutor):
It is an accessor method that removes the tutor by resetting attributes if the tutor is not
certified. A certified tutor cannot be removed.
• Method (display):
This method displays information about the tutor, including details from the superclass
(Teacher), such as ID, name, address, working type, employment status, and working
hours. If the tutor is certified, it also displays salary, specialization, academic
qualifications, performance index, and certification status.
21
SWOPNIL DAHAL
CS400NI PROGRAMMING
5. TESTING
5.1 Test 1
Test No 1
Objectives To Inspect the Lecturer class, grade the assignment, and re-
inspect the Lecturer Class
Action ➢ The Lecture is called with the following arguments
TeacherID: 1
TeacherName:”Swopnil”
Address:”Dhapakhel”
WorkingType:”Part-Time”
WorkingHours:6
EmploymentStatus:”Active”
Department:”IT”
YearsOfexpierence:5
GradedScore:50
Department”IT”
YearsofExpierence:5
22
SWOPNIL DAHAL
CS400NI PROGRAMMING
23
SWOPNIL DAHAL
CS400NI PROGRAMMING
24
SWOPNIL DAHAL
CS400NI PROGRAMMING
25
SWOPNIL DAHAL
CS400NI PROGRAMMING
26
SWOPNIL DAHAL
CS400NI PROGRAMMING
27
SWOPNIL DAHAL
CS400NI PROGRAMMING
28
SWOPNIL DAHAL
CS400NI PROGRAMMING
29
SWOPNIL DAHAL
CS400NI PROGRAMMING
30
SWOPNIL DAHAL
CS400NI PROGRAMMING
5.2 Test 2
Test No 2
Objectives To Inspect the Tutor class, set the salary, and re-inspect the
Tutor Class
Action ➢ The Tutor is called with the following arguments:
TeacherID: 2
TeacherName: "Pratisha"
Address: "Koteshwor"
WorkingType: "Part-Time"
WorkingHours: 21
EmploymentStatus: "Active"
Salary: 50000
Specialization: "Java"
AcademicQualifications: "Master Degree"
PerformanceIndex: 10
31
SWOPNIL DAHAL
CS400NI PROGRAMMING
32
SWOPNIL DAHAL
CS400NI PROGRAMMING
33
SWOPNIL DAHAL
CS400NI PROGRAMMING
34
SWOPNIL DAHAL
CS400NI PROGRAMMING
35
SWOPNIL DAHAL
CS400NI PROGRAMMING
36
SWOPNIL DAHAL
CS400NI PROGRAMMING
5.3 Test 3
Test No 3
TeacherID: 3
TeacherName: "Sushant"
Address: "Kalopul"
WorkingType: "Part-Time"
WorkingHours: 10
EmploymentStatus: "Active"
Salary: 45000
Specialization: "Python"
AcademicQualifications: "Bachelors Degree"
PerformanceIndex: 5
Expected Results The details of the tutor should be reset to default values (zero or
empty) as the tutor has been removed. The "Certified: No"
message should be displayed.
Actual Result The Tutor is removed
Conclusion The test is successful
37
SWOPNIL DAHAL
CS400NI PROGRAMMING
38
SWOPNIL DAHAL
CS400NI PROGRAMMING
39
SWOPNIL DAHAL
CS400NI PROGRAMMING
40
SWOPNIL DAHAL
CS400NI PROGRAMMING
41
SWOPNIL DAHAL
CS400NI PROGRAMMING
42
SWOPNIL DAHAL
CS400NI PROGRAMMING
5.4 Test 4
Test No 4
Action
➢ Call the void display() method of the lecturer class
Actual Result The details of the lecturer and tutor are displayed correctly with
all relevant information.
43
SWOPNIL DAHAL
CS400NI PROGRAMMING
44
SWOPNIL DAHAL
CS400NI PROGRAMMING
45
SWOPNIL DAHAL
CS400NI PROGRAMMING
46
SWOPNIL DAHAL
CS400NI PROGRAMMING
47
SWOPNIL DAHAL
CS400NI PROGRAMMING
Error Detection
48
SWOPNIL DAHAL
CS400NI PROGRAMMING
Error Correction
In the given Java code, a syntax error was intentionally introduced in the display method
by adding an extra closing parenthesis. The error was identified and corrected by
removing the unnecessary parenthesis, ensuring proper syntax. This correction allows
the code to be compiled without issues.
49
SWOPNIL DAHAL
CS400NI PROGRAMMING
Error Detection
50
SWOPNIL DAHAL
CS400NI PROGRAMMING
Error Correction
51
SWOPNIL DAHAL
CS400NI PROGRAMMING
Error Detection
52
SWOPNIL DAHAL
CS400NI PROGRAMMING
Error Correction
In this code there is no syntax or sematic error the code is going to function correctly, but
we will not get the logical output we expected, in this case if graded score is more or equal
to 10 the grade is to be A but logically this is not correct.
53
SWOPNIL DAHAL
CS400NI PROGRAMMING
7. CONCLUSION
8. BIBLIOGRAPHY
54
SWOPNIL DAHAL
CS400NI PROGRAMMING
9. APPENDIX
55
SWOPNIL DAHAL
CS400NI PROGRAMMING
}
Code Of Lecturer Class
public class Lecturer extends Teacher {
private String department;
private int yearsOfExperience;
private int gradedScore;
private boolean hasGraded;
57
SWOPNIL DAHAL
CS400NI PROGRAMMING
return this.department;
}
this.hasGraded = true;
} else {
System.out.println("Lecturer does not meet the criteria for grading.");
}
} else {
System.out.println("Lecturer has already graded.");
}
}
if (hasGraded) {
char grade;
if (gradedScore >= 70) {
grade = 'A';
} else if (gradedScore >= 60) {
grade = 'B';
} else if (gradedScore >= 50) {
59
SWOPNIL DAHAL
CS400NI PROGRAMMING
grade = 'C';
} else if (gradedScore >= 40) {
grade = 'D';
} else {
grade = 'E';
}
60
SWOPNIL DAHAL
CS400NI PROGRAMMING
this.specialization = specialization;
this.academicQualifications = academicQualifications;
this.performanceIndex = performanceIndex;
this.isCertified = false;
}
61
SWOPNIL DAHAL
CS400NI PROGRAMMING
62
SWOPNIL DAHAL
CS400NI PROGRAMMING
this.performanceIndex = 0;
isCertified = false;
System.out.println("Tutor removed successfully.");
} else {
System.out.println("Certified tutor cannot be removed.");
}
}
if (isCertified) {
System.out.println("Salary: $" + salary);
System.out.println("Specialization: " + specialization);
System.out.println("Academic Qualifications: " + academicQualifications);
System.out.println("Performance Index: " + performanceIndex);
System.out.println("Certified: Yes");
}
}
}
63
SWOPNIL DAHAL