teaching machines

Code Scrambler

September 7, 2016 by . Filed under public, teaching.

Some of the most engaging learning I’ve ever experienced was in high school Spanish class. What magic did Mrs. Lee possess that made instruction so enjoyable? She had us play countless games. I try to emulate her foreign language classroom when I teach folks a new programming language and am therefore always on the hunt for games and puzzles that my students can play.

Recently, I’ve been doing a lot of reading about scrambling up programs and asking students to reorder the lines, and I thought I’d create a little blog widget to support that style of question. The lines in the following program are scrambled. Reorder them by dragging them around!

  1. public class Greeter {
    
  2.   public static void main(String[] args) {
    
  3.     System.out.println("Goodbye, Pluto!");
    
  4.   }
    
  5. }
    

Currently there’s no feedback for getting the order correct. “Nice job!” is more heartfelt when it comes from a fellow human being. Plus sometimes several different orderings are legal.

Here’s another, longer one to print out a countdown:

  1. import java.util.Scanner;
    
  2. public class CountDown {
    
  3.   public static void main(String[] args) {
    
  4.     Scanner in = new Scanner(System.in);
    
  5.     System.out.println("Starting from? ");
    
  6.     int max = in.nextInt();
    
  7.     for (int i = max; i >= 0; ++i) {
    
  8.       System.out.println(i);
    
  9.     }
    
  10.   }
    
  11. }