Let's build a graphical, time-step simulation that allows us to see the benefits of social distancing measures. This project will give us some insight into our ability to stop the spread of COVID using several areas of Java that we've learned this semester.
Get Starter RepoThe Covid-19 virus is dominating every single one of our lives at the moment and needs no introduction. New terms such as social-distancing are now fully ubiquitous in our everyday language. Current recommendations are that people not get within six feet of each other. Clearly this is a sudden, and drastic, change for virtually every human on the planet.
Some people are going a bit too far.
While others are as-yet unwilling to change their habits from the status quo.
Your application must function as described below:
This is a graphical Java application project that implements a time-step simulation of the spread of COVID-19 as a result of adherence to social distance metrics.
This project is geared toward the end of the semester in a course on intermediate Java development.
Most appropriate for third-year students taking their second (or later) course in Java specific development.
The time from release date until due date should be roughly two weeks. This allows students 10-20 hours to formulate the solution.
This project requires a familiarity with the Java APIs, and an understanding of object-oriented development, specifically with regard to Interfaces.
The project could readily be adapted for Python but most C++ students and courses would likely not be able to run the graphical side of the simulation.
A text only approach could be used for C++ implementation wherein an ASCII-art style of display was used.
Additional controls could be added to set the fatality rate, starting infection %, and contagion probability.
// Infector is a class that you need to define, which implements the ActionListener interface
ActionListener infect = frame.new Infector(); // Infector is an inner class of the `frame` object
// STEP_TIME, below, is the number of milliseconds between updates
Timer t = new Timer(STEP_TIME, infect);
// start the Timer. It will repeat every STEP_TIME milliseconds until stopped
t.start();
repaint()
is needed inside a JComponent to re-draw the display after updating the data.
new Random()
instance at the start of your program and any time you need to check against THRESHOLD
%. For example, if the fatality rate is 3%, you can determine if a person dies by running something like:
// Create Random object at the beginning of the applciation
Random percentageChecker = new Random();
// ... someplace else, during timestep checks
// assume FATALITY_RATE is an integer set to 3
boolean deceased = percentageChecker.nextInt(100) < FATALITY_RATE;
// take action