Foreshadow arrays right after teaching for loops by showing students how to create a 1x6 grid using the rectangle object in the Java objectdraw library because visualizations built off of recently introduced material provide a useful transition.

  • Before demonstrating, ask students to try creating a 1x6 grid of rectangle objects to students.
    • The goal is to give students a chance practice their problem solving and programming skills before scaffolding them through the process.
  • Activity:
    • Demo how to draw 6 overlapping rectangles by repeatedly drawing a rectangle in the same spot.
    • Now, show students how to shift the x position of each rectangle so they draw rectangles one after the other on the screen.
    • Finally, it’s time to foreshadow arrays.
      • Explain that you can’t access the rectangles after you create them.
        • Even if you make a global variable outside the loop for the rectangles you will only ever have access to the last rectangle created.
      • Introduce arrays as a structure and draw parallels, like the fact above, to the shapes they just drew.
  • For more information on this activity, check out the worksheet McAvoy uses for this activity.

More about this tip

External Source

Interview with Dani McAvoy