Planning a Railroad Crossing Data Collection System

On this page, you will plan a railroad crossing data collection system by creating an abstract data type to organize crossing activation data with timestamps and speed.

  1. Talk with Your PartnerWhat happens when a train approaches a railroad crossing?
    Think about what data a railroad crossing system might need to collect. Consider sensors, timing, and safety information. Brainstorm 3-5 different types of data points that would be important to track.
  2. Take turns speakingRead the following section about organizing railroad crossing data. (Don't build these in Snap!. You'll build your own data structures later in this lab.)

: Sublist

A sublist is a list used as an item of another list.

(The word sublist is also used to refer to some subset of a list.)

You'll use a list to store your railroad crossing activation records in a global variable and use a sub list for each data record. This allows you to work with one activation record at a time while keeping all the data organized.

Example: Railroad Crossing Data Structure

Without abstraction, accessing this data looks messy:

But code like is hard to read and understand. A better approach is to use abstraction to organize the crossing data. The abstraction hides the complex list and item of blocks, making your code much easier to write, read, and debug.

With Abstraction: Cleaner Railroad Crossing Code

Now the code becomes much more readable:

: Data Types
: Abstract Data Types The constructor and selector together implement the crossing record abstract data type.

💡 Real-World Connection: Railroad Safety Systems

Modern railroad crossings use sophisticated data collection systems to ensure safety. These systems track:

photo of Reshma Saujani

Reshma Saujani (born 1975) founded the nonprofit organization Girls Who Code in response to the historical decline in the number of women employed in computer science fields. According to their website, in 1995, 37% of computer scientists were women. As of 2023, it’s only 24%. Reshma and Girls Who Code aim to fix this imbalance by running clubs that teach girls CS. In addition to being an activist, Reshma was the first Indian American woman to run for Congress and has served as New York City’s Deputy Public Advocate, where she created innovative partnerships to support DREAMers and promote campaign finance reform, among other initiatives.

Video: Teach girls bravery, not perfection