0% found this document useful (0 votes)
87 views27 pages

Chandan

Uploaded by

durlavregmi123
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)
87 views27 pages

Chandan

Uploaded by

durlavregmi123
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/ 27

CS4001NI Programming

Module Code & Module Title

CS4001NI Programming

Assessment Weightage & Type

30% Individual Coursework

2023 Spring

Student Name: Chandan Kumar Sharma

London Met ID: 23047353

College ID: NP01NT4A230047

Assignment Due Date:

Assignment Submission Date: May 10, 2024


Word Count: 2899

I confirm that I understand my coursework needs to be submitted online via Google Classroom under the relevant
module page before the deadline 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.
Chandan Kumar Sharma 23047353
Contents
1. Introduction......................................................................................................................................... 4
1.1 Introducing Project Content .......................................................................................................... 4
1.2 Tools Used ...................................................................................................................................... 4
1.2.1 BlueJ ....................................................................................................................................... 4
1.2.2 Draw.io ................................................................................................................................... 4
1.2.3 MS Word ................................................................................................................................. 5
1.2.4 Command prompt .................................................................................................................. 5
2. Class diagram: ..................................................................................................................................... 6
3. Pseudocode: ........................................................................................................................................ 7
4. Method Description: ......................................................................................................................... 17
5. Testing: ............................................................................................................................................... 19
Test1: Compiling & running using command prompt. ....................................................................... 19
Test 2: Adding objects of Tutor and Lecturer, grade assignments amount from lecturer, setting the
salary and removing the tutor. .......................................................................................................... 21
Test 3: Testing Appropriate Dialog boxes when unsuitable values entered. ..................................... 22
Error! Bookmark not defined.
6. Error detection: ................................................................................................................................. 23
6.1 Syntax error:................................................................................................................................. 23
23
6.2 Logical Error: ................................................................................................................................ 24
3.Semantic Error: ............................................................................................................................... 25
7. Conclusion ......................................................................................................................................... 26
Table of Figures:

Figure 1: Class Diagram including the old coursework ...............................................................6


Figure 2: Testing 1 .....................................................................................................................20
Figure 3: Test 1 ..........................................................................................................................20
Figure 4: Test 2 ..........................................................................................................................21
Figure 5: Test 3 ..........................................................................................................................22
Figure 7: Test 3 ............................................................................. Error! Bookmark not defined.
Figure 8: Syntax Error(Before) ...................................................................................................23
Figure 9: Syntax Error(After Correction) ...................................................................................23
Figure 10: Logical Error(Before) ................................................................................................24
Figure 11: Logical Error (After Correction) ................................................................................25
Figure 12: Semantic Error(Before) ............................................................................................25
Figure 13: Semantic Error (After Correction) ............................................................................26

Table of tables:

Table 1 Method Descriptions ....................................................................................................19


Table 2: Testing 1 .......................................................................................................................19
Table 3: Test 2 ............................................................................................................................21
Table 4: Test 3 ............................................................................................................................22
1. Introduction
This assignment is done using BlueJ which is an integrated development environment for Java
programming language in which we are told to design a graphical user interface that keeps
information about instructors and its details in an Array list. This software will assist a user to
conveniently manage the information about the tutors, lecturers, and professors at an
educational facility.

1.1 Introducing Project Content


This project has a parent class named ‘Teacher’ with 2 child classes inherited by the parent class
which are: Lecturer and Tutor where certain inputs have to be given for the data and they are
maintained by making objects and calling methods from the objects while manipulating data
according to situation.

1.2 Tools Used


These three tools have helped me to complete this coursework which are written below

with a short description about them:

1.2.1 BlueJ
BlueJ is a lightweight, beginner-friendly integrated development environment (IDE) mainly
used for beginning Java programming. Its sleek and easy interface makes it a popular
programmer. It offers numerous advantages including visible class representation, streamlined
project administration, and seamless integration of development tools. Its interactive nature
lets users to write, compile, and run Java programs with ease, enabling hands-on learning and
exploration. Overall, BlueJ serves as an important tool for building a better grasp of object-
oriented programming ideas in a friendly learning environment.

1.2.2 Draw.io
Draw.io is a website which is used to create diagrams for various operations. In this
coursework, I have used this website for making class diagrams of my programs.
1.2.3 MS Word
Microsoft Word is a word processing application developed by Microsoft. It allows users to
create, edit, format, and share documents with ease. It has a user-friendly interface and a wide
range of features, including spell-checking, grammar checking, templates, and formatting, to
writing letters and reports for creating resumes and reports. Microsoft Word is a great tool for
creating polished and professional-looking documents, and thus, in this report I have used this
software to prepare my report.

1.2.4 Command prompt


Command Prompt, often known as cmd, is a command-line interpreter tool accessible in
Windows operating system which provides users with a text-based interface to interact with the
operating system by running commands. Users may accomplish numerous operations, including
as browsing around directories, launching programs, managing files and directories, and
modifying system settings, all using text-based commands. It provides a robust and effective
method to control and administer a Windows machine. In this report, I have utilized cmd for
conducting various Java tasks.
2. Class diagram:

Figure 1: Class Diagram including the old


coursework
3. Pseudocode:

IMPORT JFrame from javax.swing package

IMPORT JPanel from javax.swing package

IMPORT JLabel from javax.swing package

IMPORT JTextField from javax.swing package

IMPORT JButton from javax.swing package

IMPORT JTextArea from javax.swing package

IMPORT JScrollPane from javax.swing package

IMPORT JOptionPane from javax.swing package

IMPORT ActionListener from java.awt.event package

IMPORT ActionEvent from java.awt.event package

IMPORT ArrayList from java.util package

DECLARE class Teacher

DECLARE protected attributes teacherId, teacherName, address, workingType,


employmentStatus

DECLARE constructor with parameters teacherId, teacherName, address, workingType,


employmentStatus
DECLARE method getTeacherId()

DECLARE method toString()

DECLARE class Lecturer extends Teacher

DECLARE private attributes yearsOfExperience, gradedScore

DECLARE constructor with parameters teacherId, teacherName, address, workingType,


employmentStatus, yearsOfExperience

DECLARE method setGradedScore() with parameter gradedScore

DECLARE method gradeAssignment() with parameters gradedScore, department

DECLARE method toString()

DECLARE class Tutor extends Teacher

DECLARE private attributes workingHours, salary, specialization, academicQualifications,


performanceIndex

DECLARE constructor with parameters teacherId, teacherName, address, workingType,


employmentStatus, workingHours, salary, specialization, academicQualifications,
performanceIndex
DECLARE method setSalaryWithAppraisal() with parameters newSalary,
newPerformanceIndex

DECLARE method toString()

DECLARE class TeacherGUI

DECLARE private attribute teachers of type ArrayList<Teacher>

DECLARE main method

CREATE TeacherGUI object

CALL createAndShowGUI method of TeacherGUI object

DECLARE method createAndShowGUI

CREATE JFrame object named frame with title "Teacher Management System"

SET size of frame to 800x600

SET default close operation to EXIT_ON_CLOSE

CREATE JPanel object named mainPanel

SET layout of mainPanel to null

CREATE JPanel object named labelPanel


SET layout of labelPanel to null

SET bounds of labelPanel to (20, 20, 350, 500)

SET background color of labelPanel to light gray

CREATE JPanel object named textFieldPanel

SET layout of textFieldPanel to null

SET bounds of textFieldPanel to (400, 20, 350, 500)

SET background color of textFieldPanel to light gray

DECLARE array of JLabel objects named labels

DECLARE array of JTextField objects named textFields

LOOP from i=0 to i < length of labels

CREATE JLabel object at index i

SET bounds of JLabel to (30, 20 + i * 40, 150, 20)

ADD JLabel to labelPanel

CREATE JTextField object at index i

SET bounds of JTextField to (20, 20 + i * 40, 200, 20)

ADD JTextField to textFieldPanel

ADD labelPanel and textFieldPanel to mainPanel


DECLARE JButton objects named addLecturerButton, addTutorButton,
gradeAssignmentsButton, setSalaryButton, removeTutorButton, displayButton, clearButton

SET bounds of addLecturerButton to (20, 540, 120, 30)

SET bounds of addTutorButton to (150, 540, 120, 30)

SET bounds of gradeAssignmentsButton to (280, 540, 160, 30)

SET bounds of setSalaryButton to (460, 540, 120, 30)

SET bounds of removeTutorButton to (590, 540, 120, 30)

SET bounds of displayButton to (250, 600, 120, 30)

SET bounds of clearButton to (400, 600, 120, 30)

ADD action listeners to buttons

ADD buttons to mainPanel

ADD mainPanel to frame

SET frame visible

END method createAndShowGUI


DECLARE ActionListener for addLecturerButton

DO

TRY

PARSE teacherId from textFields[0]

PARSE teacherName from textFields[1]

PARSE address from textFields[2]

PARSE workingType from textFields[3]

PARSE employmentStatus from textFields[4]

PARSE yearsOfExperience from textFields[7]

PARSE gradedScore from textFields[8]

CREATE Lecturer object with parsed values

ADD Lecturer object to teachers

DISPLAY "Lecturer added successfully"

CATCH (NumberFormatException ex)

DISPLAY "Please enter valid numeric values for Teacher ID, Years of Experience, and
Graded Score."

END CATCH

END DO

DECLARE ActionListener for addTutorButton

DO

TRY
PARSE teacherId from textFields[0]

PARSE teacherName from textFields[1]

PARSE address from textFields[2]

PARSE workingType from textFields[3]

PARSE employmentStatus from textFields[4]

PARSE workingHours from textFields[5]

PARSE salary from textFields[9]

PARSE specialization from textFields[10]

PARSE academicQualifications from textFields[11]

PARSE performanceIndex from textFields[12]

CREATE Tutor object with parsed values

ADD Tutor object to teachers

DISPLAY "Tutor added successfully"

CATCH (NumberFormatException ex)

DISPLAY "Please enter valid numeric values for Teacher ID, Working Hours, Salary, and
Performance Index."

END CATCH

END DO

DECLARE ActionListener for gradeAssignmentsButton

DO

TRY
PARSE teacherId from textFields[0]

LOOP through teachers

IF teacherId matches and teacher is instance of Lecturer

PARSE gradedScore from textFields[8]

PARSE department from textFields[6]

PARSE yearsOfExperience from textFields[7]

CALL gradeAssignment method of Lecturer

DISPLAY "Assignment graded successfully"

EXIT loop

END IF

END LOOP

DISPLAY "Lecturer with the specified Teacher ID not found"

CATCH (NumberFormatException ex)

DISPLAY "Please enter valid numeric values for Teacher ID, Years of Experience, and
Graded Score."

END CATCH

END DO

DECLARE ActionListener for setSalaryButton

DO

TRY

PARSE teacherId from textFields[0]


LOOP through teachers

IF teacherId matches and teacher is instance of Tutor

PARSE newSalary from textFields[9]

PARSE newPerformanceIndex from textFields[12]

CALL setSalaryWithAppraisal method of Tutor

DISPLAY "Salary set successfully"

EXIT loop

END IF

END LOOP

DISPLAY "Tutor with the specified Teacher ID not found"

CATCH (NumberFormatException ex)

DISPLAY "Please enter valid numeric values for Teacher ID, Salary, and Performance
Index."

END CATCH

END DO

DECLARE ActionListener for removeTutorButton

DO

TRY

PARSE teacherId from textFields[0]

LOOP through teachers

IF teacherId matches and teacher is instance of Tutor


REMOVE Tutor from teachers

DISPLAY "Tutor removed successfully"

EXIT loop

END IF

END LOOP

DISPLAY "Tutor with the specified Teacher ID not found"

CATCH (NumberFormatException ex)

DISPLAY "Please enter a valid numeric value for Teacher ID."

END CATCH

END DO

DECLARE ActionListener for displayButton

DO

CREATE JTextArea object named textArea with size 20x50

SET textArea editable to false

LOOP through teachers

APPEND teacher.toString() to textArea

END LOOP

CREATE JScrollPane object named scrollPane with textArea

DISPLAY scrollPane with title "Teacher Information"

END DO
DECLARE ActionListener for clearButton

DO

LOOP through textFields

SET text of textField to empty string

END LOOP

END DO

4. Method Description:
S.N. Methods Description

1. gradeAssignment(int It sets up the graphical user interface (GUI) for the


gradedScore, String Teacher Management System initializing GUI
department) components including JFrame, JPanels, JLabels,
JTextFields, JButtons, and adds action listeners to
handle user interactions.

2. Teacher(int teacherId, String This approach is responsible for grading


assignments for a professor.
teacherName, String address, When grading assignments for a lecturer, it is done
String workingType, String after clicking the "Grade Assignments" button. It
conducts grading logic based on the specified
employmentStatus) graded score and department and enables for
customized grading logic to be developed for
lecturers, offering a mechanism to handle their
distinct tasks inside the teacher management
system.
This strategy helps to adjust the compensation of an
instructor.
When creating a new pay for an instructor,
commonly prompted by selecting the "Set Salary"
button. It calculates the new compensation based on
the specified values and changes the tutor's income
appropriately. In real life, it would enable dynamic
modification of tutor compensation depending on
performance, allowing for fair and efficient salary
administration within the system.

3. setSalaryWithAppraisal(double This method helps to change the salary of a tutor.


newSalary,)
When setting a new salary for a tutor, usually
newPerformanceIndex)
triggered by clicking the "Set Salary" button. It
method
calculates the new salary based on the provided
values and updates the tutor's salary accordingly.
In real life, it would enable dynamic adjustment of
tutor salaries based on performance, allowing for
fair and efficient salary management within the
system.

4. createAndShowGUI() Each button in the GUI has a corresponding


ActionListener, and inside each actionPerformed
method in this program, particular duties are carried
out dependent on the button pressed.
When Adding a lecturer or tutor, it gets data from
text fields, generates a new Lecturer or a Tutor
object then adds it to the list of instructors and then
shows a success message.
While grading assignments, this method discovers
the lecturer with the supplied ID, collects grading
information from text fields, and runs the
gradeAssignment method for that professor.
For setting salary it identifies the tutor with the
supplied ID, pulls updated salary and performance
index information from text fields, and runs the
setSalaryWithAppraisal method for that instructor.
During removal of a tutor it discovers the tutor with
the supplied ID and removes it from the list of
instructors.
To show information it builds a JTextArea
containing information about all instructors and
presents it in a dialog box. In this application,
actionPerformed handles numerous user activities,
simplifying the administration of instructors and
their information using the GUI interface.

5. setSalaryWithAppraisal(double In this program, it adjusts the salary of a Tutor. It’s


newSalary, int called when the salary of a tutor needs to be
newPerformanceIndex) adjusted or changed by the user.

Table 1 Method Descriptions

5. Testing:
Test1: Compiling & running using command prompt.

For the test, command prompt has to be opened at the place the program has been stored in. Then
the parent class ‘Teacher’ and its child classes need to be compiled. Also, the GUI containing
class has to be constructed which as well implements ActionListener and eventually executes the
class containing ActionListener. The test is demonstrated below with screenshots.
S.N. Titles Results

1. Objectives To test that the program can be compiled in the command prompt.

2. Action 1. Command prompt was opened in the location of the


package containing all the Java files.
2. All the Java files were compiled including the parent, child,
and the GUI ones.
3. Inspection of the GUI containing class, ‘TeacherGUI’ was
done

3. Expected result The GUI file needs be opened in command prompt.

4. Actual result TeachGUI successfully opened in cmd.

5. Conclusion The test was successful.

Table 2: Testing 1
Figure 2: Testing 1

Figure 3: Test 1
Test 2: Adding objects of Tutor and Lecturer, grade assignments amount from lecturer,
setting the salary and removing the tutor.

S.N. Titles Results

1. Objectives To add the objects of Tutor and Lecturer then grade assignments
from lecturer, set the salary and remove the tutor.

2. Action 1. The GUI file ‘TeacherGUI’ was run.


2. The blanks were filled with correct inputs.
3. The buttons were then tested one by one if they function
correctly.

3. Expected result All the buttons would operate correctly as programmed.

4. Actual result All the buttons did operate correctly as programmed.

5. Conclusion The test was successful.

Table 3: Test 2

Figure 4: Test 2
3: Testing Appropriate Dialog boxes when unsuitable values entered.

S.N. Titles Results

1. Objectives To intentionally add wrong values to check if the appropriate set


dialogue boxes appear.

2. Action 1. The GUI file ‘TeacherGUI’ was run.


2. Wrong values for Teacher ID, Years of Experience, and
Graded Score were intentionally entered in the input areas.
3. The inputs were often changed to see how the program
would react to wrong inputs when other buttons were
pressed.

3. Expected result A dialogue should appear to alert user of the wrong input.

4. Actual result Users were alerted of the wrong format of input.

5. Conclusion The test was successful.

Table 4: Test 3

Figure 5: Test 3
6. Error detection:
While coding, I often faced errors in my programs. Even though some were simple errors, others
would cause a major error in my programs and were harder to solve. Some of them have been
listen below:

6.1 Syntax error:

Figure 6: Syntax Error(Before)

Figure 7: Syntax Error(After Correction)


While coding, I had missed a parenthesis, and I couldn’t compile the program. But it wasn’t hard
to identify the error since it had been pointed out by BlueJ by showing a red error indicator
beside the line and the error was easily fixed.

6.2 Logical Error:

A logical error was causing the fields to conflict and not to be in the position I had wanted.
Despite the code would compile and run of the error present, the consequence of setting the
vertical position of both labels and text fields to 20 resulted in a GUI layout where all
components were stacked directly on top of each other vertically.

Figure 8: Logical Error(Before)


Figure 9: Logical Error (After Correction)

After tying to fix the position by inputting certain values, at last it was fixed, when I could input
the correct logic for the program to run properly.

3.Semantic Error:

During my coursework , I encountered certain semantic errors when coding where I had entered
wrong variable types. For e.g: In the figure below, I mistakenly assigned an integer value to a

String value which caused an error during compilation.

Figure 10: Semantic Error(Before)


I could fix it easily as it was marked by the interface, by changing the data type from integer to
String.

Figure 11: Semantic Error (After Correction)

7. Conclusion
In conclusion, this coursework provided a comprehensive opportunity to apply Java
programming concepts in building a graphical user interface (GUI) for managing teacher details
using object-oriented programming principles. Through the development of the TeacherGUI
class and integration with existing Teacher, Lecturer, and Tutor classes, I gained practical
experience in utilizing ArrayLists, handling user input, and implementing event-driven
programming with Swing components.

Throughout this coursework, I furthered my understanding of class inheritance and


polymorphism by casting Teacher objects to their respective subclasses, such as Lecturer and
Tutor, to perform specific actions like grading assignments or setting salaries. Moreover,
incorporating exception handling with try and catch blocks enhanced the robustness of the
application by gracefully handling potential errors, such as invalid input formats.

Overall, this project reinforced my knowledge of Java fundamentals while emphasizing the
importance of designing user-friendly interfaces and writing clean, maintainable code.
Additionally, it highlighted the significance of thorough testing to ensure the reliability and
functionality of the application. Through this coursework, I've not only enhanced my Java
programming skills but also gained valuable insights into software development methodologies
and best practices.

You might also like