0% found this document useful (0 votes)
80 views63 pages

Swopnil Dahal PDF

The document outlines the CS400NI Programming coursework for the Autumn 2023 semester, focusing on the creation of three classes: Teacher, Lecturer, and Tutor. It includes details on class diagrams, pseudocode, method descriptions, and testing procedures, emphasizing the object-oriented nature of Java programming. The assignment is due on January 26, 2024, and late submissions will not be accepted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views63 pages

Swopnil Dahal PDF

The document outlines the CS400NI Programming coursework for the Autumn 2023 semester, focusing on the creation of three classes: Teacher, Lecturer, and Tutor. It includes details on class diagrams, pseudocode, method descriptions, and testing procedures, emphasizing the object-oriented nature of Java programming. The assignment is due on January 26, 2024, and late submissions will not be accepted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

CS400NI Programming

30% Individual Coursework

2023 Autumn

Student Name: Swopnil Dahal

London Met ID: 23049070

College ID: NP01CP4A230431

Assignment Due Date: 26th January 2024

Assignment Submission Date: 26th January 2024

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

Figure 1 Class Diagram................................................................................................... 5


Figure 2 Teacher Class Diagram ..................................................................................... 6
Figure 3 Lecture Class Diagram ...................................................................................... 7
Figure 4 Tutor Class Diagram ......................................................................................... 8
Figure 5 Final Class Diagram .......................................................................................... 9
Figure 6 Creating new Object. ....................................................................................... 23
Figure 7 Entering Values ............................................................................................... 23
Figure 8 Values Entered ................................................................................................ 24
Figure 9 Inspection of Lecture Class ............................................................................. 25
Figure 10 Display Method Of Lecture Class .................................................................. 26
Figure 11 Calling GradeAssignment Method ................................................................. 27
Figure 12 Grading Assignment ...................................................................................... 28
Figure 13 Inspecting Lecture Class after grading .......................................................... 29
Figure 14 Calling Display method of Lecture Class to show Grade .............................. 30
Figure 15 Calling newTutor method .............................................................................. 32
Figure 16 Entering Values to create object .................................................................... 32
Figure 17 Inspecting Tutor Class ................................................................................... 33
Figure 18 Calling setSalary Method .............................................................................. 34
Figure 19 Setting new Salary and Performance Index .................................................. 35
Figure 20 Salary Approved Message ............................................................................ 35
Figure 21 Reinspecting Tutor Class .............................................................................. 36
Figure 22 Creating Instance .......................................................................................... 38
Figure 23 Inspecting Tutor Class ................................................................................... 39
Figure 24 Calling Remove Tutor Method ....................................................................... 40
Figure 25 Message Showing Tutor Removed Successfully ........................................... 41
Figure 26 Reinspection of Removed Tutor Class .......................................................... 42
Figure 27 Calling the void display() method of Lecture class ........................................ 44
Figure 28 Displaying Lecture Class ............................................................................... 45
Figure 29 Calling void display() method of Tutor Class ................................................. 46
Figure 30 Displaying Tutor Class .................................................................................. 47
Figure 31 Syntax Error Detection .................................................................................. 48
Figure 32 Syntax Error Correction ................................................................................. 49
Figure 33 Semantic Error Detection .............................................................................. 50
Figure 34 Semantic Error Correction ............................................................................. 51
Figure 35 Logical Error Detection .................................................................................. 52
Figure 36 Logical Error Correction ................................................................................ 53

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

A class diagram is a visual representation of the structure and relationships within a


system using the Unified Modeling Language (UML). It shows the classes that make up
a system as well as its relationships, methods, and characteristics. Every class is shown
as a box with a list of its properties and methods inside. Connecting lines are used to
depict relationships between classes, which can involve relationships, aggregations, and
generalizations. (Rouse, 2013)

Figure 1 Class Diagram

5
SWOPNIL DAHAL
CS400NI PROGRAMMING

2.1 Class Diagram of Teacher Class

Figure 2 Teacher Class Diagram

6
SWOPNIL DAHAL
CS400NI PROGRAMMING

2.2 Class Diagram of Lecturer Class

Figure 3 Lecture Class Diagram

7
SWOPNIL DAHAL
CS400NI PROGRAMMING

2.3 Class Diagram of Tutor Class

Figure 4 Tutor Class Diagram

8
SWOPNIL DAHAL
CS400NI PROGRAMMING

2.4 Final Class Diagram

Figure 5 Final Class Diagram

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

CREATE Teacher(int teacherId, String teacherName, String address, String


workingType, String employmentStatus, int workingHours)
ASSIGN this.teacherId TO teacherId
ASSIGN this.teacherName TO teacherName
ASSIGN this.address TO address
ASSIGN this.workingType TO workingType
ASSIGN this.employmentStatus TO employmentStatus
ASSIGN this.workingHours TO workingHours
ENDDO

CREATE int getTeacherId()


RETURN this.teacherId
ENDDO

CREATE String getTeacherName()


RETURN this.teacherName
ENDDO

CREATE String getAddress()


RETURN this.address
ENDDO

CREATE String getWorkingType()


RETURN this.workingType
ENDDO

10
SWOPNIL DAHAL
CS400NI PROGRAMMING

CREATE String getEmploymentStatus()


RETURN this.employmentStatus
ENDDO

CREATE int getWorkingHours()


RETURN this.workingHours
ENDDO

CREATE void setWorkingHours(int workingHours)


ASSIGN this.workingHours TO workingHours
ENDDO

CREATE void setAddress(String address)


ASSIGN this.address TO address
ENDDO

CREATE void display()


DECLARE
String workingHoursInfo
ENDDO

ASSIGN workingHoursInfo TO (workingHours > 0) ? "Working Hours: " + workingHours


: "Working Hours: Not assigned"

Print "Teacher ID: " + teacherId


Print "Teacher Name: " + teacherName
Print "Address: " + address
Print "Working Type: " + workingType
Print "Employment Status: " + employmentStatus
Print workingHoursInfo
ENDDO
END

11
SWOPNIL DAHAL
CS400NI PROGRAMMING

3.2 Pseudocode of Lecturer Class

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

CREATE boolean getHasGraded()


RETURN this.hasGraded
ENDDO
CREATE void setGradedScore(int gradedScore)
ASSIGN this.gradedScore TO gradedScore
ENDDO
CREATE void gradeAssignment(int gradedScore, String department, int
yearsOfExperience)
IF NOT this.hasGraded
IF this.yearsOfExperience >= 5 AND this.department EQUALS department
IF gradedScore >= 70
ASSIGN this.gradedScore TO gradedScore
ELSE IF gradedScore >= 60
ASSIGN this.gradedScore TO 60
ELSE IF gradedScore >= 50
ASSIGN this.gradedScore TO 50
ELSE IF gradedScore >= 40
ASSIGN this.gradedScore TO 40
ELSE
ASSIGN this.gradedScore TO 0
ENDIF
ASSIGN this.hasGraded TO true
ELSE
PRINT "Lecturer does not meet the criteria for grading."
ENDIF
ELSE
PRINT "Lecturer has already graded."
ENDIF
13
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

3.3 Pseudocode of Tutor Class

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

CREATE String getAcademicQualifications()


RETURN this.academicQualifications
ENDDO
CREATE int getPerformanceIndex()
RETURN this.performanceIndex
ENDDO
CREATE boolean getIsCertified()
RETURN this.isCertified
ENDDO
CREATE void setSalary(double newSalary, int newPerformanceIndex)
IF NOT this.isCertified
IF newPerformanceIndex >= 5 AND CALL super.getWorkingHours() >= 20
DECLARE
double appraisalPercentage
ENDDO
IF newPerformanceIndex >= 8 AND newPerformanceIndex <= 9
ASSIGN appraisalPercentage TO 0.10
ELSE IF newPerformanceIndex EQUALS 10
ASSIGN appraisalPercentage TO 0.20
ELSE
ASSIGN appraisalPercentage TO 0.05
ENDIF
ASSIGN this.salary TO this.salary + (appraisalPercentage * this.salary)
ASSIGN this.performanceIndex TO newPerformanceIndex
ASSIGN this.isCertified TO true
PRINT "Salary approved for certified tutor."
ELSE
PRINT "Salary cannot be approved. Tutor has not met the criteria."

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

• Constructor Method (Teacher):


Creates a new Teacher object with specified attributes like ID, name, address, working
type, employment status, and working hours.
• Getter Method (getTeacherId):
It is an accessor method that Retrieves and returns the teacher's ID.
• Getter Method (getTeacherName):
It is an accessor method that Retrieves and returns the teacher's name.
• Getter Method (getAddress):
It is an accessor method that Retrieves and returns the teacher's address.
• Getter Method (getWorkingType):
It is an accessor method that Retrieves and returns the teacher's working type.
• Getter Method (getEmploymentStatus):
It is an accessor method that Retrieves and returns the teacher's employment status.
• Getter Method (getWorkingHours):
It is an accessor method that Retrieves and returns the teacher's assigned working
hours.
• Setter Method (setWorkingHours):
It is an accessor method that Updates the teacher's working hours to a new specified
value.
• Setter Method (setAddress):
It is an accessor method that Updates the teacher's address to a new specified value.
• Display Method (display):
Displays information about the teacher, including ID, name, address, working type,
employment status, and working hours.

18
SWOPNIL DAHAL
CS400NI PROGRAMMING

4.2 Method Description of Lecturer Class

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

• Getter Method (getDepartment):

It is an accessor method that retrieves and returns the department of the lecturer.

• Getter Method (getYearsOfExperience):

It is an accessor method that retrieves and returns the years of experience of the lecturer.

• Getter Method (getGradedScore):

It is an accessor method that retrieves and returns the graded score of the lecturer.

• Getter Method (getHasGraded):

It is an accessor method that retrieves and returns whether the lecturer has graded
assignments.

• Setter Method (setGradedScore):

It is an accessor method that sets the graded score of the lecturer to a specified value.

• Method (gradeAssignment):

19
SWOPNIL DAHAL
CS400NI PROGRAMMING

This method grades assignments based on specified criteria (years of experience,


department) and updates the lecturer's graded score and grading status.

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

4.3 Method Description of Tutor Class

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

• Getter Method (getSalary):

It is an accessor method that retrieves and returns the salary of the tutor.

• Getter Method (getSpecialization):

It is an accessor method that retrieves and returns the specialization of the tutor.

• Getter Method (getAcademicQualifications):

It is an accessor method that retrieves and returns the academic qualifications of the
tutor.

20
SWOPNIL DAHAL
CS400NI PROGRAMMING

• Getter Method (getPerformanceIndex):

It is an accessor method that retrieves and returns the performance index of the tutor.

• Getter Method (getIsCertified):

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

➢ Inspection Of Lecture Class

void gradeAssignment(int gradedScore, String department,


int yearsOfExperience)

GradedScore:50
Department”IT”
YearsofExpierence:5

➢ Reinspection of Lecture Class

Expected Results Grade Should be shown according to the marks

Actual Result Grade is shown according to the marks entered


Conclusion The test is successful

22
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 6 Creating new Object.

Figure 7 Entering Values

23
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 8 Values Entered

24
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 9 Inspection of Lecture Class

25
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 10 Display Method Of Lecture Class

26
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 11 Calling GradeAssignment Method

27
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 12 Grading Assignment

28
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 13 Inspecting Lecture Class after grading

29
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 14 Calling Display method of Lecture Class to show Grade

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

➢ Inspection Of Tutor Class

void setSalary(double newSalary, int newPerformanceIndex)

New Salary: 55000


New PerformanceIndex: 5

➢ Reinspection of Tutor Class

Expected Results Salary should be updated according to the new performance


index, and the Tutor's details should be displayed
Actual Result The salary is updated based on the new performance index,
and the Tutor's details are displayed correctly.
Conclusion The test is successful

31
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 15 Calling newTutor method

Figure 16 Entering Values to create object

32
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 17 Inspecting Tutor Class

33
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 18 Calling setSalary Method

34
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 19 Setting new Salary and Performance Index

Figure 20 Salary Approved Message

35
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 21 Reinspecting Tutor Class

36
SWOPNIL DAHAL
CS400NI PROGRAMMING

5.3 Test 3

Test No 3

Objective To inspect the Tutor class after removing a tutor.

Action ➢ Create an instance of the Tutor class with the following


details:

TeacherID: 3
TeacherName: "Sushant"
Address: "Kalopul"
WorkingType: "Part-Time"
WorkingHours: 10
EmploymentStatus: "Active"
Salary: 45000
Specialization: "Python"
AcademicQualifications: "Bachelors Degree"
PerformanceIndex: 5

➢ Inspection Of Tutor Class

➢ Display the details of the tutor before removal.

➢ Display the details of the tutor after removal.

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

Figure 22 Creating Instance

38
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 23 Inspecting Tutor Class

39
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 24 Calling Remove Tutor Method

40
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 25 Message Showing Tutor Removed Successfully

41
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 26 Reinspection of Removed Tutor Class

42
SWOPNIL DAHAL
CS400NI PROGRAMMING

5.4 Test 4

Test No 4

Objective To Display the details of Lecturer and Tutor classes.

Action
➢ Call the void display() method of the lecturer class

➢ Call the void display() method of the Tutor class

➢ Display the details of the lecturer.

➢ Display the details of the tutor.

Expected Results ➢ For the Lecturer:


Details of the lecturer, including department, years of experience,
graded score, and grade, should be displayed.

➢ For the Tutor:


Details of the tutor, including salary, specialization, academic
qualifications, performance index, and certification status, should
be displayed.

Actual Result The details of the lecturer and tutor are displayed correctly with
all relevant information.

Conclusion The test is successful

43
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 27 Calling the void display() method of Lecture class

44
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 28 Displaying Lecture Class

45
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 29 Calling void display() method of Tutor Class

46
SWOPNIL DAHAL
CS400NI PROGRAMMING

Figure 30 Displaying Tutor Class

47
SWOPNIL DAHAL
CS400NI PROGRAMMING

6. ERROR DETECTION AND CORRECTION

6.1 Syntax Error

Error Detection

Figure 31 Syntax Error Detection

48
SWOPNIL DAHAL
CS400NI PROGRAMMING

Error Correction

Figure 32 Syntax 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

6.2 Sematic Error

Error Detection

Figure 33 Semantic Error Detection

50
SWOPNIL DAHAL
CS400NI PROGRAMMING

Error Correction

Figure 34 Semantic Error Correction


This is a Semantic error which was caused due to improper use of program statements.
This error was solved by replacing the wrong data type(String) with correct data
type(double) in getter method for getSalary.

51
SWOPNIL DAHAL
CS400NI PROGRAMMING

6.3 Logical Error

Error Detection

Figure 35 Logical Error Detection

52
SWOPNIL DAHAL
CS400NI PROGRAMMING

Error Correction

Figure 36 Logical 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

In conclusion completing the Java coursework has been a rewarding educational


experience. In this coursework, the Teacher class serves as the parent class and the
Lecturer and Tutor classes serve as subclasses, illustrating the concept of inheritance in
object-oriented programming. In conclusion, I would state that. Thanks to this project, my
understanding of methods, constructors, attributes, and objects, all essential concepts in
object-oriented programming has improved. I was able to gain experience creating
classes with the appropriate properties, comprehending inheritance concepts, and
creating and utilizing methods to complete tasks by putting these classes into practice.
Additionally, by providing experience in developing and using objects, the program
promoted a practical grasp of encapsulation and code organization. The process for
Creating and applying instances of these classes enhanced my problem-solving and
coding skills. All things considered, this course has been extremely beneficial in solidifying
my foundational knowledge of Java programming and laying the groundwork for future
research and software development projects.

8. BIBLIOGRAPHY

Arun, R., 2023. What is Java: A Beginners Guide To Java. [Online]


Available at: https://www.simplilearn.com/tutorials/java-tutorial/what-is-java
Rouse, M., 2013. Class Diagram. [Online]
Available at: https://www.techopedia.com/definition/16466/class-diagram

54
SWOPNIL DAHAL
CS400NI PROGRAMMING

9. APPENDIX

Code Of Teacher Class


public class Teacher {
private int teacherId;
private String teacherName;
private String address;
private String workingType;
private String employmentStatus;
private int workingHours;

public Teacher(int teacherId, String teacherName, String address, String


workingType, String employmentStatus, int workingHours) {
this.teacherId = teacherId;
this.teacherName = teacherName;
this.address = address;
this.workingType = workingType;
this.employmentStatus = employmentStatus;
this.workingHours = workingHours;
}

public int getTeacherId() {


return this.teacherId;
}

public String getTeacherName() {


return this.teacherName;
}

55
SWOPNIL DAHAL
CS400NI PROGRAMMING

public String getAddress() {


return this.address;
}

public String getWorkingType() {


return this.workingType;
}

public String getEmploymentStatus() {


return this.employmentStatus;
}

public int getWorkingHours() {


return this.workingHours;
}

public void setWorkingHours(int workingHours) {


this.workingHours = workingHours;
}

public void setAddress(String address) {


this.address = address;
}

public void display() {


String workingHoursInfo = (workingHours > 0) ? "Working Hours: " + workingHours :
"Working Hours: Not assigned";

System.out.println("Teacher ID: " + teacherId);


56
SWOPNIL DAHAL
CS400NI PROGRAMMING

System.out.println("Teacher Name: " + teacherName);


System.out.println("Address: " + address);
System.out.println("Working Type: " + workingType);
System.out.println("Employment Status: " + employmentStatus);
System.out.println(workingHoursInfo);
}

}
Code Of Lecturer Class
public class Lecturer extends Teacher {
private String department;
private int yearsOfExperience;
private int gradedScore;
private boolean hasGraded;

public Lecturer(int teacherId, String teacherName, String address, String


workingType, int workingHours, String employmentStatus,
String department, int yearsOfExperience) {
super(teacherId, teacherName, address, workingType,
employmentStatus,workingHours);
super.setWorkingHours(workingHours);
this.department = department;
this.yearsOfExperience = yearsOfExperience;
this.hasGraded = false;
this.gradedScore = 0;
}

public String getDepartment() {

57
SWOPNIL DAHAL
CS400NI PROGRAMMING

return this.department;
}

public int getYearsOfExperience() {


return this.yearsOfExperience;
}

public int getGradedScore() {


return this.gradedScore;
}

public boolean getHasGraded() {


return this.hasGraded;
}

public void setGradedScore(int gradedScore) {


this.gradedScore = gradedScore;
}

public void gradeAssignment(int gradedScore, String department, int


yearsOfExperience) {
if (!hasGraded) {
if (yearsOfExperience >= 5 && this.department.equals(department)) {
if (gradedScore >= 70) {
this.gradedScore = gradedScore;
} else if (gradedScore >= 60) {
this.gradedScore = 60;
} else if (gradedScore >= 50) {
this.gradedScore = 50;
58
SWOPNIL DAHAL
CS400NI PROGRAMMING

} else if (gradedScore >= 40) {


this.gradedScore = 40;
} else {
this.gradedScore = 0;
}

this.hasGraded = true;
} else {
System.out.println("Lecturer does not meet the criteria for grading.");
}
} else {
System.out.println("Lecturer has already graded.");
}
}

public void display() {


super.display();

System.out.println("Department: " + department);


System.out.println("Years of Experience: " + yearsOfExperience);

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';
}

System.out.println("Graded Score: " + gradedScore);


System.out.println("Grade: " + grade);
} else {
System.out.println("Score has not been graded yet.");
}
}
}
Code of Tutor Class
public class Tutor extends Teacher {
private double salary;
private String specialization;
private String academicQualifications;
private int performanceIndex;
private boolean isCertified;

public Tutor(int teacherId, String teacherName, String address, String workingType,


String employmentStatus,
int workingHours, double salary, String specialization, String
academicQualifications, int performanceIndex) {
super(teacherId, teacherName, address, workingType,
employmentStatus,workingHours);
this.salary = salary;

60
SWOPNIL DAHAL
CS400NI PROGRAMMING

this.specialization = specialization;
this.academicQualifications = academicQualifications;
this.performanceIndex = performanceIndex;
this.isCertified = false;
}

public double getSalary() {


return this.salary;
}

public String getSpecialization() {


return this.specialization;
}

public String getAcademicQualifications() {


return this.academicQualifications;
}

public int getPerformanceIndex() {


return this.performanceIndex;
}

public boolean getIsCertified() {


return this.isCertified;
}

public void setSalary(double newSalary, int newPerformanceIndex) {


if (!isCertified) {

61
SWOPNIL DAHAL
CS400NI PROGRAMMING

if (newPerformanceIndex >= 5 && super.getWorkingHours() >= 20) {


double appraisalPercentage;
if (newPerformanceIndex >= 8 && newPerformanceIndex <= 9) {
appraisalPercentage = 0.10;
} else if (newPerformanceIndex == 10) {
appraisalPercentage = 0.20;
} else {
appraisalPercentage = 0.05;
}

this.salary = this.salary + (appraisalPercentage * this.salary);


this.performanceIndex = newPerformanceIndex;
isCertified = true;
System.out.println("Salary approved for certified tutor.");
} else {
System.out.println("Salary cannot be approved. Tutor has not met the
criteria.");
}
} else {
System.out.println("Salary cannot be changed. Tutor has already been
certified.");
}
}

public void removeTutor() {


if (!isCertified) {
this.salary = 0;
this.specialization = "";
this.academicQualifications = "";

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.");
}
}

public void display() {


super.display(); // Call the display method of the superclass

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

You might also like