COVID Simulation - Social Distancing

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 Repo

Project overview:

The 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.

People in plastic bubbles

Some people are going a bit too far.

Spring breakers spreading the love...and the virus

While others are as-yet unwilling to change their habits from the status quo.

Project Requirements:

Your application must function as described below:

  1. A graphical interface component must be present to allow a user of the application to update the percentage of the population complying with social distancing recommendations.
    1. Changes to the value should be reflected in the graphical simulation.
  2. A display of color spots shall indicate the status of members of the population. Green for healthy, red for infected and black for deceased. Optionally, add some additional indicator for non-compliant persons. In the demo below, an orange outline is used.
  3. The program must run in time steps indicating the effects of social distancing on the spread of infectious diseases such as the Coronavirus.
    1. In each time step, every person (cell in the grid) should be analyzed and displayed according to their status.
    2. If the person has not yet been exposed to the virus, there is a 75% possibility that they will contract the virus if they come into contact with an infected person.
      1. Coming into contact means that one of the two people involved is not complying with social distancing guidelines.
    3. After four time steps an infected person should stop being contagious. The probability of death should be set as 3%. The other 97% go back to a healthy state but will no longer be vectors for the spread of the virus. This means that they will remain green for the remainder of the program run and will not transmit the virus.
    4. Choose 5% of the initial population at random to be infected.


Icon of summary report


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.

Icon of bulletized list


  • Random numbers
  • Time-based display updates
  • Graphical User Interfaces
  • Interfaces

Icon of small group of people


This project is geared toward the end of the semester in a course on intermediate Java development.

Icon showing exploding head


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.

Icon of flexed bicep


  • Visually appealing
  • Timely/relevant
  • Socially responsible
  • Brings together several concepts from the course
  • Encourages student's use of Java API

Icon of weak bicep


  • Requires topics not covered in the course
  • Dependent on multiple topics
  • Grading cannot be automated
  • Depends upon graphical interface and might not be easy to adapt to other programming languages

Icon showing dependency graph


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.

Icon indicting ways to tweak the project


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.


  1. Create a project that is object oriented, therefore there should be several classes.
  2. A Timer can be used to trigger an action to occur every X milliseconds. For example:
    // Infector is a class that you need to define, which implements the ActionListener interface
    ActionListener infect = 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 
  3. repaint() is needed inside a JComponent to re-draw the display after updating the data.
  4. All of the % probabilities can be implemented using a Random object. Simply create a 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