COMP5911M Advanced Software Engineering Coursework 1
This assessment is based on material from the lectures on refactoring and design patterns. There are two separate tasks, with a total of 100 marks available. Each task has multiple deliverables associated with it. You should submit all your deliverables using Gradescope (follow the link inside the Submit My Work folder in the module’s Minerva page).
This assessment is worth 15% of your overall grade for this module.
Task 1
A matrix is an array of numbers indexed by rows and columns. Matrices are widely used in computer graphics and numerical science. One common operation is to put a matrix into row echelon form, in which entries below the leading diagonal are set to zero. This is achieved by using the following algorithm.
Row Echelon Algorithm
-
find left-most column with non-zero entry.
-
if row with first non-zero element is not top swap the row with the top.
-
add multiples of top row to make all values in column below top zero
-
repeat the above for successive sub-matrices
The algorithm relies on two elementary row operations:
-
swap two rows.
-
add a multiple of one row to a second row.
Also, the ability to find the first non-zero element in a column, working down from the top must be provided.
The Task
A simple three by three matrix Java class has been written, with a method for converting the matrix to row echelon form. A Junit4 test suite has also been written that carries out two tests checking that the conversion is correct.
The row echelon function is currently a long loop with no decomposition into separate methods. Your task is to add three methods to the class, use them in the row echelon method, and add a test case to the testing class for each object, add a brief comment before each test in Javadoc format. The three methods are:
-
swapRows: to swap a pair of rows.
-
addMultipleOfRow: to add a multiple of one row to another.
-
pivotIndex: to find the index of first non-zero element in a column, retuning -1 if all elements
in the column are zero.
The Provided Code
You are provided with a zip archive holding the following items:
-
MatrixThreeThree.java source code for the matrix class
-
MatrixThreeThreeTests.java source code for the matrix test class
-
junit-platform-console-standalone-1.9.3.jar the Junit4 console test archive
To compile and run you must have an up-to-date java and javac installed on the machine you are using. Open a terminal or console window and navigate to the directory holding the code.
java -jar .\junit-platform-console-standalone-1.9.3.jar --class-path target --select-class MatrixThreeThreeTests
The ‘-jar’ flag tells the interpreter to run the program in the jar archive. The ‘--class-path’ flag tells junit to look in the directory 'target', and '--select-class' tell it which test class to run.
You should see an output looking like this:
Thanks for using JUnit! Support its development at https://junit.org/sponsoring
←[36m.←[0m
←[36m+--←[0m ←[36mJUnit Jupiter←[0m ←[32m[OK]←[0m ←[36m+--←[0m ←[36mJUnit Vintage←[0m ←[32m[OK]←[0m
←[36m| '--←[0m ←[36mMatrixThreeThreeTests←[0m ←[32m[OK]←[0m ←[36m| +--←[0m←[34mtestRowEchilonForm0←[0m←[32m[OK]←[0m ←[36m| '--←[0m←[34mtestRowEchilonForm1←[0m←[32m[OK]←[0m ←[36m'--←[0m ←[36mJUnit Platform Suite←[0m ←[32m[OK]←[0mTest run finished after 42 ms
-
[ 4 containers found
-
[ 0 containers skipped
-
[ 4 containers started
-
Deliverables (to be submitted via Gradescope):
1.1 (35 marks) Your versions of the two java files: MatrixThreeThree.java and MatrixThreeThreeTests.java.
1.2 (15 marks) Brief report, maximum 500 words (matrices count as one word), acting as documentation for the three test functions. You are free to repeat or include the comment stings in the code if you wish.
Marking scheme:
1.1 Code: 10 marks for swapRows and associated test; 10 marks for addMultipleOfRow and associated test; and 15 for the pivotIndex and associated test. Marks will be deduced for submission of unmodified code, poor implementations of the proposed design, and the lack of descriptive comment on each function and test.
1.2 Report: 5 marks for each of the descriptions. Marks will be deducted for poor description of test.
Task 2
In this task, you should extend the PictureApp we have discussed in the lecture. The extension is called PictureAppPlus, and just like its predecessor it displays a picture with a collection of shapes. I provided you the code of PictureAppPlus, which has the same functionality as the original PictureApp, but has been configured with a different window size and collection of shapes for this task. A snapshot of its user interface is shown below in Figure 1:
Figure 1 – PictureAppPlus snapshot – initial shape selection
The feature that must be added to PictureAppPlus is the ability to add shapes to any instance of the class Circle. Once a shape is added to an instance of Circle using the method add(Shape s), the added shape will be assigned the X and Y coordinates of the circle it was added into, and it should be drawn within the draw method of that circle. For example, the lines of code shown in Figure 2 below (from the provided PictureAppPlus class, some of which are commented out in the provided code) show a few shapes added to instances of Circle using the add method. Notice that the shapes added to an instance of Circle are not added to the instance of the class Picture.
Circle c1 = new Circle(150, 420, 90, Color.CYAN);
picture.add(c1);
Circle c2 = new Circle(500, 185, 50, Color.MAGENTA);
picture.add(c2);
Circle c3 = new Circle(450, 420, 60, Color.RED);
picture.add(c3);
Circle c4 = new Circle(220, 70, 70, Color.WHITE);
picture.add(c4);
Circle c5 = new Circle(0, 0, 42, Color.YELLOW);
c1.add(c5);
c2.add(new Triangle(0, 0, 30, 30, Color.ORANGE));
c3.add(new Rectangle(0, 0, 40, 40, Color.BLUE));
c4.add(new Rectangle(0, 0, 55, 20, Color.BLUE));
c5.add(new Triangle(0, 0, 18, 18, Color.RED));
Figure 2 – PictureAppPlus code excerpt
Figure 3 below shows all the shapes included in the provided PictureAppPlus class, including those added to circles (by uncommenting lines 46-53). Your task is to extend the provided code so the extended functionality of PictureAppPlus can be enabled.
Figure 3 – PictureAppPlus snapshot showing circles containing other shapes
There is a well known design pattern that can be useful for this particular problem. Your first task is to identify that design pattern, and decide the best way to apply it to the problem. Once you identified the pattern and decided your approach, create a UML class diagram showing all the PictureAppPlus classes, including all the provided classes as well as changes you performed and any classes, attributes, operations, and associations you may have created. Then, implement your changes and make sure your code can support the new feature described in this task.
Deliverables (to be submitted via Gradescope):
-
2.1 (15 marks) UML class diagram showing your proposed design.
-
2.2 (20 marks) Brief report describing your design decisions, your choice of the pattern, and
explaining how you applied the pattern to PictureAppPlus (i.e. which classes play which of the roles described in the pattern). Maximum length: 500 words.
2.3 (15 marks) Code of the classes you have changed or created.
Marking scheme:
2.1 15 marks for a correct UML class diagram describing a valid design of a solution to the problem; 10 marks for a UML class diagram missing minor elements of the design; 5 marks for a UML class diagram missing a major element of the design; 0 marks for UML diagrams failing to describe a valid design or for diagrams that are not valid UML class diagrams.
2.3 15 marks for correct and efficient implementations of the proposed design by extending the provided code. Only submit code of classes you have created or modified as part of your solution. Do not submit code of classes you did not modify. Marks will be deduced for unnecessary modifications, submission of unmodified code, and poor implementations of the proposed design. Your submitted code will be compiled along with the code of the classes you did not modify and all standard Java libraries, and only code that can be compiled successfully will be marked.