You are on page 1of 10

ITP4909 Object Oriented Technology Workshop 1

Module Intended Learning Outcome (#1):


On completion of the module, students are expected to be able to:
 Apply use case modeling to identify and define requirements of software applications

Lesson Intended Learning Outcome:


On completion of this lab, students are expected to be able to:
 Benefits of object oriented approach

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.

The Requirements of the Grade Reporting System (GRS)

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.

A user can invoke the system with the following command :-

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

©VTC 2012 Page 1 of 10


ITP4909 Object Oriented Technology Workshop 1

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:

String[] moduleCode = {"ITD2322", "ICT2422", "ITD2321", "ICT2669"};


String[] studentID = {"1", "2", "3", "4", "5", "6", "7", "8"};
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

Stage 1 – The development of the GRS using the structure approach

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.

Perform the following tasks:

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.

©VTC 2012 Page 2 of 10


ITP4909 Object Oriented Technology Workshop 1

©VTC 2012 Page 3 of 10


ITP4909 Object Oriented Technology Workshop 1

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:

 Marks are recorded using the six-letter grade system.


 When calculation of the average mark or median mark is needed, the letter grades are
first converted into numeric values as follows: A to 5, B to 4, C to 3, D to 2, E to 1, F
to 0. Then the average or the median of the numeric values are calculated and
displayed.

Record the followings:


 The number of methods needed to be changed.
 The number of lines of code needed to be changed.

You may use the following test data for this part:

String[] moduleCode = {"ITD2322", "ICT2422", "ITD2321", "ICT2669"};


String[] studentID = {"1", "2", "3", "4", "5", "6", "7", "8"};
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

After you have finished this stage, you can ask the lecturer-in-charge to check your work
before proceeding to the next stage.

©VTC 2012 Page 4 of 10


ITP4909 Object Oriented Technology Workshop 1

Stage 3 – Object-Oriented Design and Implementation for GRS

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.

©VTC 2012 Page 5 of 10


ITP4909 Object Oriented Technology Workshop 1

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.

Record the following:


 The number of methods needed to be changed.
 The number of lines of code needed to be changed.

After you have finished this stage, you can ask the lecturer-in-charge to check your work
before proceeding to the next stage.

©VTC 2012 Page 6 of 10


ITP4909 Object Oriented Technology Workshop 1

Stage 5 – Preliminary Comparison of Structure Approach and Object-oriented


Approach

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:

Structure Approach Object-Oriented


Approach
Number of lines of
code needed to be
changed or added
Number of methods
needed to be added
Number of methods
needed to be changed
Where the changes are
located

Why it takes shorter time to make the changes with the OO approach?

______________________________________________________________________

_______________________________________________________________________

©VTC 2012 Page 7 of 10


ITP4909 Object Oriented Technology Workshop 1

Stage 6 – Further Comparison

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.

Record the following:


 The program size (in terms of number of lines of code).
 Where the changes are located.

After you have finished this stage, you can ask the lecturer-in-charge to check your work
before proceeding to the next stage.

©VTC 2012 Page 8 of 10


ITP4909 Object Oriented Technology Workshop 1

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 :

abstract class GRSData {

protected String[] moduleCode =


{"ITD2322", "ICT2422", "ITD2321", "ICT2669"};
protected String[] studentID = {"1", "2", "3", "4", "5", "6", "7", "8"};

public abstract int[] getModuleMark(String mCode);

public String getStudentID(int i) { // return ID of the i-th student


return (studentID[i]);
}
}

Declare a subclass of GRSData for the numeric data:

class NumericGRSData extends GRSData {

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

public int[] getModuleMark(String mCode) {


// fill in your code here
}
}

Declare a subclass of GRSData for the letter data:

class LetterGRSData extends GRSData {

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

public int[] getModuleMark(String mCode) {


// fill in your code here
}
}

Fill in the code in the supplied program. Test your program.

Record the following:


 The program size (in terms of number of lines of code).
 Where the changes are located.

Stage 8 – Further Comparison of Structure Approach and Object-oriented Approach


©VTC 2012 Page 9 of 10
ITP4909 Object Oriented Technology Workshop 1

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:

Structure Approach Object-Oriented


Approach
Program size
(in terms of number
of lines of code)
Where the changes are
located

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?

______________________________________________________________________

_______________________________________________________________________

©VTC 2012 Page 10 of 10

You might also like