Write My Paper Button

WhatsApp Widget

You are provided with a partially working application that is intended to graphically demonstrate the operation of a clustering algorithm. The program is very simple, having only a start and a stop

Advanced Programming Coursework Assignment


You are provided with a partially working application that is intended to graphically demonstrate the operation of a clustering algorithm. The program is very simple, having only a start and a stop button. On pressing start the program will generate a random set of points in a two dimensional area. It then runs a clustering algorithm to group the dots into clusters based on their locations. The algorithm used is DBSCAN (Density-based spatial clustering of applications with noise) and this requires a radius parameter in order to perform its clustering. The program repeatedly performs clustering increasing the radius parameter each time until 90% of the points have been included in a cluster. For interest you can read about the algorithm at https://en.wikipedia.org/wiki/DBSCAN but this assignment is not really concerned with the problem itself, only the threading issues involved in displaying an animation of it. No information about DBSCAN is required in your report.

The intended behavior of the program is as follows:

On launching, the program displays a GUI which has a “Start” and a “Stop” button. On pressing “Start” a random set of points should be generated, and displayed as white points on a grey background in the window. Then the clustering algorithm will repeatedly repaint the window showing the clusters it has identified by colouring groups of points accordingly. At each step the window also displays the current radius used, the minimum number of points to form a cluster, the number of clusters found and the percentage of points clustered. The user should be able to stop this process early by pressing the “Stop” button, or close the window to terminate the application. Resizing the window during the animation should work with the displayed image being stretched to fit the window. When pressing “Start” the initial size of the window determines the size of the data area and hence how closely grouped the points are. A bigger area is more interesting and takes longer.

As it stands the program does not behave as described above.

Your tasks are as follows:

1. Run the application and observe its behaviour. Consider especially the behaviour of the various parts of the GUI (including the window closing/resizing behaviour) and the difference between the intended functionality and what the program actually does.

2. Analyse the application code and explain every aspect of the behaviour you have documented above that does not match the intended behaviour. Try to be as detailed as possible in doing this and make sure you identify the significance of threads and the event dispatch architecture in this.

3. Modify the program so that it works correctly, in particular ensuring that:

• The clustering process is correctly displayed as a series of updated images.

• The stop button works to cancel the clustering process, and allows the user to start with a new clustering process after stopping.

• That all accesses to components belonging to the swing framework are made only on the Swing event dispatch thread (your program may work properly without doing this, but it is not correct without doing this).

• That all data passed between threads can be guaranteed free of memory-consistency problems (again your program may work properly without doing this, but it is not correct without doing this).

• That the main window close button cancels all the background threads before closing the window so that the program does not continue running after the window has been closed.

The whole process of modifying the program must be clearly documented, explaining your reasoning and the details of your code. You must include the relevant code in the body of your report while discussing it. You should describe the modifications you made in the order that you did them, and discussing any issues or problems you had as you went along. You should explicitly refer to lecture, lab and other technical materials that you used to find out how to solve specific problems as you go along. You should also discuss alternative approaches you considered and rejected and explain why.

Make sure you clearly explain all issues of threading, including the behaviour of the event dispatch architecture, ensuring events occur in the required sequence, and all possible memory-consistency problems.

Note: It is intended that you modify the existing code rather than extensively rewrite the program because (a) identifying the specific issues in the code as given is an important part of the assignment and (b) this involves less work. In particular, while there exist utility classes in Java that are explicitly intended to help write background threads for GUI applications, making use of them in this case is likely to involve a lot more complexity than a “simple fix” would. Should you choose to make significant changes to the design of the program, you should also explain what a simple direct fix would consist of and why you have chosen to do things differently.

Provided files:

Clusterer.java– the UI application that provides the window and has a main method.

ImagePanel.java– an extension of JPanel that displays an image.

ClusterData.java – a class that contains the data the clustering algorithm produces – which points are in which cluster.

LocationWrapper.java– a class that contains a single data point in a format suitable for the clustering algorithm.

apache-maths-for-cw.jar – a jar file containing maths libraries from the Apache software foundation, required for the clustering algorithm.


In order to run the application you must add the provided apache-maths-for-cw.jar library to your IDE’s classpath. To do this in eclipse, copy the file into your project, right-click it in the navigator and choose “Add to build path”. To do this in NetBeans, right-click the Libraries node in the project structure, select “Add JAR/Folder” then browse to the downloaded jar file. It will be a similar process in other IDEs.


Your report needs to address the tasks detailed above and should be separated into three clear sections:

Task 1:Description of initial behaviour or program and what is not working properly.

Task 2: Analysis of the underlying causes of the problems identified in task 1. Task 3: Narrative explaining the modifications made to the program.


1. Written
report as specified above.

2. Zip file containing your modified version of the source code
in an easily compilable form (that is, a valid package hierarchy).

The written report must not be contained in the zip file.

Marking Criteria

This assignment will be marked using an adaptation of the University’s standardised marking criteria. It is important that you pay attention to the criteria that will be applied and address them in the text of your report.

Please note that the primary criterion being assessed in this assignment is your understanding of the material and your ability to analyse and reason about it. Submitting a working program is not sufficient to demonstrate this and will not in itself obtain a high grade.

Note that marks are awarded for the following main criteria:

1.     Subject Knowledge (35%)

Understanding and application of subject knowledge. Contribution to subject debate.

Mainly assessed by your written documentation of the behaviour of the existing application, the analysis of the code and your explanation of your own code.

2.     Critical Analysis (15%)

Assessed by the rationale you give for your design approaches and their contrast to alternative approaches and your ability to reason about threading issues.

3.     Testing and Problem-Solving Skills (30%)

Design, implementation, testing and analysis of product/process/system/idea/solution(s) to practical or theoretical questions or problems.

Assessed on the basis of the software you develop and document – that is, your solutions to the problem at hand. It is important to note that very little credit will be given to any code you provide without explanation.

4.     Practical Competence (10%)

Skills to apply theory to practice or to test theory.

Assessed on documented evidence of your use of technical documentation (for example Oracle’s tutorials, Java documentation and course materials) in working out how to accomplish the assignment.

5.     Personal and Professional Development (10%)

Management of learning through self-direction, planning and reflection.

Assessed on the basis of the quality of your submitted report, how well it addresses this assignment specification, clarity of writing and general presentation. Program code should be presented in a clearly legible fixed-width font. Screenshots should not be used to present code, only to illustrate the behaviour of the application if you feel it is necessary.

Scroll to Top