CS-115: Programming 2
Coursework 2
Troy Astarte
Due: 2026-04-20 at 14:00
W eighting: 10% of the 15 credit module
T otal Marks: 100
Document version: 1.2
Scenario
In this coursework, you will build a simulation system for infection disease modelling. The key components
are Pathogens—the diseases—and Disease Centres, locations around the country where diseases originate
and spread. You will base this on a GUI map of the UK and you will be able to see the pathogens as
they move around. Finally, the system will produce traces of pathogen routes.
Learning Outcomes
This coursework will help you learn:
• inheritance hierarchies
• polymorphism, with overloading and overriding
• file reading and writing
• working with data structures
• modifying an existing codebase (the provided files)
• integrating your work with a remote and opaque codebase (Autograder)
Java Version
Your code will be tested with Java 17 and I strongly suggest you use Java 17 to write it.
Marking, Autograder & Feedback
Each task within this coursework has multiple tests associated with it on Autograder. The tests you
will be able to see will be worth some marks and provide you with some knowledge that your code is
functioning as it should. However, there are hidden tests which will also award marks for code quality
and presentation; these are checking your understanding of the more in-depth concepts, such as ensuring
you’re using object-oriented principles (e.g. encapsulation) along with following the coding conventions.
You will be able to see your scores on these tests, as well as additional feedback on where you might have
lost marks once the final mark is published.
You must submit your code to Autograder. We would advise you to upload and test your code regularly,
at least at the end of each task completion. This will help to ensure you are on the right track.
Setting up the environment is worth 0 marks and is to ensure your environment is set up appropriately.
Tasks 1-8 are worth 65% of the total. If you complete all of these tasks, then your code is fully functional.
This is a base mark that will not be reduced.
Regardless of how much functionality you complete from the specification, you can obtain an additional
10% by completing Task 9 (Test & Impress). This is manually checked and we will add this on should
your submission be satisfactory.
Page 1 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Up to 25% is also awarded based on your code quality and ability to follow conventions and best practices
as outlined in this module. If you have done very little code you will not be able to obtain this full 25%.
This 25% is awarded via a mixture of automatic tests, plus some manual handgrading which may or may
not reduce the automatically awarded mark.
The GUI
Tasks 1, 2, 3, 4 and 5 will not impact the Java FX GUI produced - you could still get full marks
for these without getting Java FX working. Task 6-8 will require Java FX and will impact the
GUI in different ways. These green boxes will indicate what the GUI output should be at the end
of each task.
Each mark on autograder is equivalent to 1%. The table below shows the potential marks you could get
based on how many tasks you complete:
T ask
1
T ask
2
T ask
3
T ask
4
T ask
5
T ask
6
T ask
7
T ask
8
T ask
9
Marks A vailable
for completing task
(and passing all
visible tests)
9 8 4 10 4 15 5 10 10
Maximum marks
for code quali-
ty/conventions
(summative)
6 12 19 25 25 25 25 25 25
Maximum mark
possible (assuming
all tests passing
and no issues with
code quality/con-
ventions)
15 29 40 56 60 75 80 90 100
Example Mark Calculations
• Completing and passing all tests up to Task 2, would mean you would visibly see all of
the tests passing and a score of 17%. If you’ve followed all coding conventions and have a
very high standard of code, you can obtain another 12%, taking your total to 29%. In this
situation you haven’t completed much of the coursework at all and thus fail the component.
• Or perhaps you manage to successfully complete up to Task 4. This means on Autograder
you would visibly see all of the tests passing and a score of 32%. Now let’s say you have
adhered to all of the coding conventions and have very high code quality. You can therefore
obtain another 25%, taking your total to 56%. You’ve completed half of the tasks, but still
have a relatively okay mark.
• Or maybe you’ve attempted to complete the whole of the functionality (Task 1-8). Perhaps
you have 1-2 issues with your code however (e.g. a test in Task 6 fails). You can see a score
of 63%. As you attempted all tasks, the maximum additional marks applies so you could
get up to an extra 25%, however let’s say you end up with only 15 extra marks (maybe
you had a few encapsulation methods missing, or incorrect variable names and some magic
numbers); This takes your total to 88%. You’ve had a really good go at the coursework and
demonstrated the majority of functionality, as well as relatively good coding practice.
• For all of these examples, you could boost your mark by a further 10% by completing task
9 by writing tests for your code and also impressing the marker with some changes/features
outside of the score. It’s worth bearing in mind however, the fewer tasks you complete, the
more limited your code is to be able to do this.
Page 2 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Pre-existing Code & Description
This section briefly describes the existing code that is provided. For more in-depth descriptions please
read the comments within the files.
• Display .javaThis is the file you should use to run the program. It manages creation and updating
of the GUI and there are only two methods you will need to complete. Do not edit any of the rest
of this file—including using IDE-suggested changes.
• Data.java This class acts as a Database class which holds the relevant information required for the
implementation. You may wish to make use of the methods in this class throughout the coursework
and you also need to add methods to this class as described. Again, do not edit any of the rest of
the file beyond adding new methods.
• DiseaseCentre.java This is a stub class. You will be expected to edit the majority of the imple-
mentation of this class.
• Pathogen.java This is an interface class that will be used to implement the pathogens. You
will be expected to utilise this within your implementation. The spread method is utilised every
time a pathogen visits a Disease Centre on its path, starting at the epicentre and ending at the
endpoint. A pathogen could visit any number of Disease Centres but must visit a minimum of 2
(epicentre/endpoint).
Setting up the environment
The first task is to set up your development environment. It will depend on your choice of IDE (Eclipse,
IntelliJ, or some other IDE). You are advised to use an IDE because this assignment requires working
with multiple classes and the use of an IDE helps manage your project structure.
Task 0 in this assignment is to ensure the successful installation of JavaFX. How to do this depends on your
IDE. IntelliJ automates a lot of the process for you but for Eclipse you will need to do some things yourself.
W e strongly advise you to use IntelliJ. Please follow the link - https://openjfx.io/openjfx-docs/
to get started with installing JavaFX. You are recommended to install version 17 of JavaFX if working
on your own computer. Make sure to download the appropriate version for your operating system and
architecture. The assignment should work with versions 8, and 17. In the lab, you will still need to follow
these instructions and use 8 if 17 is not available.
To ensure that your machine has JavaFX, please create a JavaFX project inside the preferred IDE, and
place all the code files provided inside the src folder. If you do not create a JavaFX Project the program
will not build. There is a video on Canvas that demonstrates the project set up.
Depending on which setup you followed, your project may/may not have some pre-existing code in the
source (src) directory (e.g. HelloApplication/HelloController) and potentially in your resources directory
(e.g. hello-view.fxml). If your project does have these files, delete them before the next step.
For IntelliJ setup: place the provided java files in your project src folder and place the csv & txt files
provided into the root directory (e.g. Coursework 2). There are also several image png files that you
will need to place in your resources directory . Other IDEs may have different project setups.
Once you have added these files, you can run the program and if you should see the window panel as
shown in Figure 1 as the output; this means you have successfully installed JavaFx and you are ready to
begin working on the development of the assignment.
Page 3 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Figure 1: The output of Task 0
W arnings
When running you may see this (or similar) output to the console:
com . sun . g l a s s . u i . mac . M a c A p p l i c a t i o n l a m b d a $ w a i t F o r R e a c t i v a t i o n $
W A R N I N G: Timeout w h i l e w a i t i n g f o r app r e a c t i v a t i o n
j a v a [ 1 2 8 2 5 : 4 8 4 0 4 6 ] +[ IMKClient s u b c l a s s ] : c h o s e IMKClient_Modern
This is fine and you can continue working on the coursework.
Code Quality & Conventions [25 marks]
All tasks will be assessed on code quality and following coding conventions. You can find the coding
conventions for this module here: https://canvas.swansea.ac.uk/courses/60418/files/9619952.
As mentioned above, if you have done very little code you will not be able to obtain this full 25%.
• For every task that requires you to create attributes, you should consider the best access modifiers
to assign to these (e.g. public, private, protected), and whether or not these attributes should be
constants. This could impact the names of these attributes.
• To enable maintenance in the future, you should ensure you apply encapsulation principles by
adding accessors/mutators for attributes. Unless it goes against convention, attributes should be
able to be accessed/changed.
• All methods must use camel case irrelevant of attribute capitalisation
• Accessor methods for booleans must use is instead of get: e.g., isResearch() vs getResearch().
Page 4 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
• Any exceptions implemented within the coursework should be handled effectively (i.e. using try/-
catch at some point in the code)
• You must only use examinable concepts taught in the lecture materials and Canvas pages of CS-110
and CS-115. Advanced concepts may have been mentioned during lectures or labs but if they are
not in the static materials they are not allowed in this coursework! Concepts indicated explicitly
as advanced in CS-110 are not allow. Y ou will lose marks if you do not follow this.
Task 1: Disease Centre class [9 marks]
Within the provided files there is a DiseaseCentre Class. This is currently being used as a stub so that
the code runs, however, it does not have the full correct implementation.
Add the following attributes to the class:
• city name , a String
• dcid, an int
• x, an int
• y, an int
• country, a String
• research, a boolean
• pop density , a double
• connections, an array list of disease centres
(Note the names given above should be used exactly although you should format them as per the coding
conventions.)
x and y are used as coordinates when building the GUI. Country is the country in which the disease centre
is located. The research boolean is used to determine a couple of pieces of later behaviour. Population
density will determine pathogen behaviour. Finally, connections indicates to which other disease centres
this is connected.
Since disease centres remain static and unchanging during this particular simulation, no disease centre
attributes will change after being set.
Create a constructor which initialises the connections ArrayList to be empty, and sets every other attribute
from a parameter (in the order given above). Complete encapsulation as appropriate. This should be
done in every Task, though it will not be explicitly stated from here on.
In addition, you should you include a method addConnection that takes a DiseaseCentre as a parameter
and adds it to the connections ArrayList. This will be used to model the travel vectors through which
pathogens spread.
Your class needs two methods for giving location information. getLocation should return the the city’s
name, and if it is a research centre, “(RC)” should be appended. getLocationDetail should be formatted
with the letter X followed by that attribute’s value, the letter Y and the attribute value, and finally the
letter C followed by the country.
Examples
If you had a disease centre in Kirkcudbright in Scotland with x value of 100, y value of 100, the
location would be:
Kirkcudbright
If it were a research centre, the result would be:
Kirkcudbright (RC)
Its detailed location would be:
X100Y100CScotland.
Page 5 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Finally, your DiseaseCentre class needs a toString method that returns both location information strings
and the population density. The latter figure should be presented with a comma separating the thousands
and two decimal places.
Once you are happy with the Task you should ensure your work is saved and backed up. Then make a
submission to Autograder. Ensure you do this after every task!
Task 2: The Pathogens: Bacteria [8 marks]
Within the provided files there is a Pathogen interface class. There are two main types of pathogen:
Bacteria and Viroids. Begin by creating a Bacteria class that implements the Pathogen interface.
Add the following attributes to the class:
• epicentre, a Disease Centre
• endpoint, a Disease Centre
• aerobic, a boolean
• alive, a boolean defaulting to true
The constructor should take in epicentre, endpoint, and aerobic attributes as parameters and initialise
alive as appropriate. Note: bacteria cannot switch from being aerobic to anaerobic (not aerobic) and vice
versa.
The Pathogen methods should be overridden as follows:
• getEpicentre() - obvious
• getEndpoint() - obvious
• spread() - research centres have special zero-oxygen environments to deal with aerobic bacteria.
If one such bacteria is spread to a research centre, it should stop being alive.
• getTrace() - can be left with a blank or null return value for now.
Finish off the class with a toString method.
Task 3: The Pathogens: Viroid [4 marks]
Create a Viroid class that also implements the Pathogen interface. A Viroid is too generic to be instan-
tiated. The class will, however, be used to form a hierarchy with two subclasses, Virus and Phage. For
this task, you only need to create and edit the Viroid class. The subclasses are discussed in the next task.
Add the following attributes to the class:
• epicentre, a Disease Centre
• endpoint, a Disease Centre
• spread chance , a double.
• multiplying, a boolean
• locations, an ArrayList of Disease Centres
Spread chance indicates the probability ( 0 ≤ p ≤ 1) of the viroid beginning to multiply. We are not
modelling generational change so this is fixed per viroid. The constructor takes in three parameters:
epicentre, endpoint, and spread chance. It should initialise all relevant attributes. Complete the rest of
the implementation as required.
Page 6 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Task 4: The Pathogens: Virus and Phage [10 marks]
Add two subclasses of Pathogen, namely: Virus and Phage. Each class has several attributes and
behaviours as described below. You should decide for each what you need to implement in this class.
Phage Class
These attributes should be present in Phage objects:
• epicentre, a Disease Centre
• endpoint, a Disease Centre
• spread chance , a double
• multiplying, a boolean
• locations, an ArrayList of Disease Centres
It should have access to these methods:
• getEpicentre() - return the epicentre
• getEndpoint() - return the endpoint
• spread() - add the disease centre to the list of centres the phage has visited. You should also check
whether the centre’s population density is high enough to start the phage multiplying (see below)
• getTrace() - can be left with a blank or null return value for now.
Virus Class
These attributes should be present in Virus objects:
• epicentre, a Disease Centre
• endpoint, a Disease Centre
• spread chance , a double
• multiplying, a boolean
• locations, an ArrayList of Disease Centres
• multHistory, a String
It should have access to these methods:
• getEpicentre() - return the epicentre
• getEndpoint() - return the endpoint
• spread() - add the disease centre to the list of centres the virus has visited. You should also check
whether the centre’s population density is high enough to start the virus multiplying (see below).
Once the virus starts multiplying, each disease centre location visits should be appended to the
multHistory string, separated by > characters.
• getTrace() - can be left with a blank or null return value for now.
Population density and multiplying
Both phages and viruses begin multiplying if the population density of a disease centre is over
a certain threshold, found by multiplying the spread chance of the viroid by 10,000.
Viruses multiplying out of control is dangerous enough that we need to keep track where they
have been since they started multiplying. For example, if a virus spread via Hull, London, Cardiff,
and Bangor, and started multiplying in London, multHistory would show:
London (RC) > Cardiff (RC) > Bangor
(assuming London and Cardiff are both research centres).
Page 7 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Task 5: The Data Class [4 marks]
Write two methods called findDiseaseCentre, both of which return a disease centre. One method
should have a String as a parameter which finds a Disease Centre by looking for it by city name; the
other method should have an integer parameter, which finds a Disease Centre by its id. You may need
to add to the Disease Centre class to make these work. If no matching Disease Centre is found return
null. These are utility methods which could be used by other classes. These methods are overloading one
another.
For the purposes of this Coursework you can assume that disease centres can be uniquely identified by
both city name and ID, i.e., there will never be two different centres with the same ID or same city name.
Task 6: Read Data from Files [15 marks]
In this task, you will be updating the Display class and the Data Class.
You have been provided with 2 files: disease-centres.txt and pathogens.csv. Firstly you need to write
2 methods in the Data class: readDiseaseCentres and readPathogens. Each of these should take no
parameters, but they need to process the data from the files, create the relevant objects, and update
relevant attributes in the Data class.
This task is a particularly important point to remind yourself of the Coding Conventions and
Quality instructions on page 4. You will lose marks if you do not follow them.
disease-centres.txt contains a list of relevant attributes, formatted as follows:
cityName id x y research country population;area
From this information, you can create instances of each Disease Centre. You will have to calculate the
population density by dividing the population by the area covered.
Once you have created each disease centre you will need to add it to the Data class diseaseCentres list.
pathogens.csv contains the information of each pathogen. It is formatted as follows:
type,epicentre,endpoint,aerobic/spreadChance
Note! the final value per line varies depending on the type. For bacteria, it is whether the bacteria is
aerobic. For viroids, it is the spread chance. There is never actually a / character in the file. Disease
centre epicentres and endpoints may be given by either city name or ID. Each created pathogen should
be added to the stack of pathogens in the Data class.
There are files supplied to you which show the correct format, but you are encouraged to create additional
files for your own testing purposes.
Both the readDiseaseCentres and readPathogens methods need to be called from within the Display
class initialise method. You must call them in that order!
The GUI Result
At this point, if everything has been implemented correctly, your programme should now display
disease centres on the map in the JavaFX GUI, as well as a list of pathogens in the left pane. The
button will not yet cause the pathogens to spread around the country as there are no connections.
See Figure 2 for how this should look.
City names
For the sake of your testing purposes, the disease centres used in building the GUI are named as
follows (North to South): Inverness, Edinburgh, Newcastle, Belfast (in Northern Ireland), Hull,
Bangor, Cardiff, London.
Page 8 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Figure 2: The output of Task 6
Task 7: Creating Connections [5 marks]
Once you have read the Disease Centres you also need to create the connections between them. You need
to write a method addConnections() in the Data class, which is then called in the same initialize()
method as the file reading methods. The addConnections() method needs to contain an algorithm that
creates connections between disease centres. The algorithm should connect all disease centres that are
in the same country. Each research centre is also connected to every other research centre regardless of
country. The connection needs to go both ways (to represent a symmetrical relation).
The GUI Result
You should now be able to press the “Start Pathogen” button and watch the path of each as it
travels around the country. See Figure 3.
Task 8: Spread tracing [10 marks]
During the disease modelling simulation, the user should be able to press a button “Print Traces” that
writes output to a file traces.txt about each completed pathogen. The file does not need a qualified
path—just write to the default location.
You can assume a pathogen trace can be produced as soon as the spread has begun, and thus do not
have to wait until the animation completes before the output is written to the file. Whenever the button
is pressed, the traces file should be over-written with the details of all pathogens spread up to that point.
There should be one line in the file for each trace. Each trace should include: the type of pathogen and its
endpoint location. For bacteria, it should indicate if the bacteria is aerobic, and if it is dead. (If not, the
information should simply be absent). For phages, there should be a warning given if it is multiplying.
For viruses, there should be a warning if the virus is multiplying, and the mult history string given.
Page 9 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Figure 3: The output of Task 7
Use the example print statements below to determine how traces should be written:
T race Examples
Bacteria spread to Hull.
Aerobic bacteria spread to Belfast (RC).
Aerobic bacteria spread to Cardiff (RC). Bacteria is dead.
Phage spread to Inverness.
Phage spread to Newcastle. W ARNING! Phage is multiplying!
Virus spread to London (RC).
Virus spread to Bangor. W ARNING! Virus is multiplying! From: Cardiff (RC) > Hull.
To do this you will need to update the relative getTrace() methods. You will also need to add a button
to the Display. A button has been provided: traceButton. You need to update the addButtonTask
method to initialize the button and add the functionality required. You may wish to look at the existing
code to see how the other button was added to the display.
Updating the addButtonT ask Method
Remember: Do not update anything else in the display except for the content of the
addButtonTask method. If you want to create any attributes please do so within this method.
This is not best practice, but our tests are checking if the Display class has been altered and so
any other changes may prevent your code from being tested at all.
You will need to write your own printTraces() method in the Data class that is called when the button
is pressed.
Hint: This method could make use of the Data.getSpreadPathogens() method to retrieve items that
have begun their spread path.
Page 10 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
To obtain top marks here you should consider how code may be re-used via inheritance (using super.).
The GUI Result
To check this method works you should run the code and be able to see a new button on the display.
When you press this button after a pathogen has started spreading, a traces.txt file should be
created/updated holding the relevant information. Only pathogens that have been spread will be
output to the file if you use the hint above.
Task 9: Test & Impress [10 marks]
The marks for this task are awarded based on how you test your code and what you do to impress the
markers. You need to complete this task in a file titled TestAndImpress.java. You should have at least
one test for each stage to obtain full marks on the test side. You should not use JUnit here.
In this file you should also include a written comment or print statement on any changes/features you have
added to your code that go above and beyond the tasks set out. These must also be tested/demonstrated
to show they are working correctly.
Note: You cannot edit the Display class in the parts indicated or this will produce errors
on our checks.
Submission Instructions
The deadline for submission is 2026-04-20 at 14:00. Submission of the assignment is electronic only .
In order to submit:
Z Submit your src files to autograder. This is how you are marked.
Z Submit exactly the same files zipped to Canvas. The file must be named only with your student
number.
W arning
The deadline is the time by which you need to have uploaded your work both to Autograder and
to Canvas - it is NOT the time by which you need to have finished the assignment. Autograder
does not immediately give you a response - especially when it is busy. So late submissions caused
by delays getting results from Autograder are not an extenuating circumstance.
If you do not submit to Canvas AND Autograder, the submission will not be considered valid and
will receive a 0. Instructions for Autograder are available via a link on the Coursework page. You
can access autograder at: https://csautograder.swansea.ac.uk
Attributions
Virus icon created by Freepik - Flaticon
Phage icons created by Freepik - Flaticon
Bacterium icons created by Freepik - Flaticon
Disease Centre icons created by Freepik - Flaticon
Lab icons created by Freepik - Flaticon
Generative AI Usage Notice
The use of generative AI is forbidden for the entirety of this assignment.
For further information consult the university’s Academic Integrity pages and if you require clar-
ification please get in touch.
Page 11 of 12
CS-115 – Coursework 2 Due: 2026-04-20 at 14:00
Academic Integrity Disclaimer
By submitting coursework, electronically and/or hardcopy, you state that you fully under-
stand and are complying with the Universitys policy on Academic Integrity and Academic
Misconduct. The policy can be found at‘ https: // myuni. swansea. ac. uk/ academic-life/
academic-misconduct .
If you are unsure about Academic Misconduct make sure you have watched the induction
lecture recording carefully. Handing in your coursework after the deadline will result in a mark
of zero.
Page 12 of 12