Question
Question
Question
Overview
This laboratory exercise consists of several parts. You will have to develop a simple grade
reporting system using the structure analysis and design approach that you have learnt in your
previous study. Then you will be asked to develop the same system with the modern object-
oriented approach. You will be asked to record the time required to develop the system in
each stage and the problems that you encountered. Then you will be asked to compare the
structure approach and the object-oriented approach.
Please follow the instructions given by the laboratory sheets. You must complete all work in
one stage before proceeding to the next stage.
You are asked to develop a simple GRS in Java with the following functions:
The user can display the average mark of a module by giving the module code.
The user can display the median mark of a module by giving the module code.
The median mark of a module is the middle value of all marks of the module
sorted in order.
The user can display all students who have the best performance among the
students taking a module. For example, if the maximum mark of module ITD2322
is 75, all students who have obtained 75 marks in ITD2322 will be displayed.
The student ID and module code are of String type. The mark of a student for a module is of
integer type.
java Main <option> <module code> where Main is the name of the Java class.
The followings are some sample commands and the corresponding meanings :-
Command Meaning
java Main average ITD2322 Display the average mark of module
ITD2322.
java Main median ICT2669 Display the median mark of the module
ICT2669
java Main beststudent ITD2321 Display the students who have the best
performance in module ITD2321
If not both “option” and “module code” are provided, the following message should be shown
when the program runs :- Usage: java Main {average | median | beststudent} <module code>
In order to simplify the system development, you can assume the marks of the GRS are stored
in a two dimensional array and the other data are stored in one dimensional arrays, i.e. you
should declare the following in your program:
String[] moduleCode;
String[] studentID;
int[][] marks;
You can hard code the initialization of the arrays with data for testing. This will save your
time from writing the extra code for reading data from files. You can use the following data
for testing:
You are asked to develop the GRS using structure analysis and design approach that you have
learnt. Since you are using structure approach, you are only allowed to define one class
in your program. ALL FUNCTIONS AND DATA MUST RESIDE IN THE CLASS.
1. Design the program skeleton for the class by specifying the data declaration and
method header of each required method.
2. Implement and test the system.
You may use the following test cases for checking your program.
After you have finished this stage, you can ask the lecturer-in-charge to check your work
before proceeding to the next stage.
Stage 2
Make a back up copy of the GRS before proceeding to this stage. You will need the back up
copy of the GRS later.
The GRS that you just implemented is only suitable for numeric marks. Some other colleges
would prefer to record the marks using a six-letter grade system: A, B, C, D, E, F. You are
asked to re-implement the GRS with the following changes in requirements:
You may use the following test data for this part:
After you have finished this stage, you can ask the lecturer-in-charge to check your work
before proceeding to the next stage.
Make a back up copy of the GRS that you developed in stage 2 before proceeding to this
stage.
In this stage, you are asked to re-develop the GRS described in stage 1 using the object-
oriented approach. Since you do not have experience in designing object-oriented system, you
can follow the design described below:
The class GRSData is defined to hold all data related to marks, students and modules.
GRSData
private String[] moduleCode
private String[] studentID
private int[][] marks
public int[] getModuleMark(String mCode)
public String getStudentID(int i)
The private attributes moduleCode, studentID, and marks are arrays for keeping the
module codes, student ID and the marks of students for the modules. The method
getModuleMark returns the marks of students taking a module with module code
given as the input parameter of the method. The method getStudentID returns the
student ID of the i-th student.
Re-implement the GRS with the object-oriented design. You must declare all attributes of
the class GRSData as private. Access to the data of GRSData must via its public
methods.
After you have finished this stage, you can ask the lecturer-in-charge to check your work
before proceeding to the next stage.
Stage 4
Make a back up copy of the GRS that you developed in stage 3 before proceeding to this
stage.
Now, you are asked to modify the program that you developed in stage 3 so that the marks are
now represented by the six letter grades as described in stage 2. The rules for converting the
letter grades to numeric values are described in stage 2. The specification of methods of the
class GRSData remains unchanged. Test your program.
After you have finished this stage, you can ask the lecturer-in-charge to check your work
before proceeding to the next stage.
Now you are asked to compare the effort for modifying the program with Structure Approach
(from stage 1 to stage 2) and that for Object-Oriented Approach (from stage 3 to stage 4)
when the requirements of the GRS change. Fill in the necessary information in the following
table:
Why it takes shorter time to make the changes with the OO approach?
______________________________________________________________________
_______________________________________________________________________
You should have concluded that the Object-oriented approach is better in terms of the effort
to make the changes and the ease of locating the required changes. You have just learnt the
power of ‘data encapsulation’ which means the implementation and the specification of the
data structure (object) can be separately defined. Any changes in the implementation of the
data structure will not affect the object which uses the data structure via its interface (its set of
methods) provided that its interface remains unchanged.
Now you will learn how the concept of ‘Polymorphism’ of Object-Orientation can further
reduce the effort of maintaining software systems.
Now, you are asked to re-develop the GRS so that it can handle both numeric marks and letter
grade marks. Integrate the programs that you developed for stage 1 and stage 2. You will
need to declare two set of data in your program for testing. Again, you have to put all data
and functions in one class as you are using the structure approach. The user can invoke the
system with the following command:
Command Meaning
java Main numeric average ITD2322 Display the average mark of module
ITD2322 where the marks are represented
by numeric values.
java Main letter median ICT2669 Display the median mark of the module
ICT2669 where the marks are represented
by letter grades.
java Main numeric beststudent ITD2321 Display the students who have the best
performance in module ITD2321 where the
marks are represented by numeric values.
After you have finished this stage, you can ask the lecturer-in-charge to check your work
before proceeding to the next stage.
Stage 7
Repeat the same kind of work for the Object-Oriented approach, i.e. integrate the programs
that you developed in stage 3 and stage 4. Change the declaration of the class GRSData as
follows :
private int[][] marks = { {30, 40, 50, 60, 45, 55, 65, 75},
// mark for ITD2322
{80, 70, 60, 40, 34, 56, 78, 90}, // mark for ICT2422
{76, 45, 67, 89, 12, 45, 67, 54}, // mark for ITD2321
{56, 76, 54, 55, 50, 43, 66, 44}}; // mark for ICT2669
private char[][] marks = { {'F', 'D', 'C', 'B', 'C', 'B', 'C', 'A'},
// mark for ITD2322
{'D', 'B', 'A', 'A', 'F', 'B', 'C', 'C'}, // mark for ICT2422
{'D', 'B', 'E', 'B', 'C', 'F', 'F', 'D'}, // mark for ITD2321
{'C', 'B', 'E', 'D', 'C', 'B', 'C', 'A'}}; // mark for ICT2669
Now you are asked to compare the effort for modifying the program in stages 6 and 7. Fill in
the necessary information in the following table:
Ease of handling of
similar data structures
but different
implementations
Compare the structure of the program developed by using Object-oriented Approach and the
structure of the program developed by using the Structure Approach. Which one is easier to
maintained and extended?
______________________________________________________________________
_______________________________________________________________________