9/2/18

mini programming course - summary & demos

This year we tried a small Java class at my community center - we've had Python and Scratch in the past. I worked with a group of middle & high schoolers. Our goal is to provide basic exposure to programming. I loosely followed the same topic order as UW's CSE 142, which I grew familiar with in college. We only have an hour on Sundays and therefore ignored many concepts (large program decomposition, stylistic best practices, objects/inheritance). Everyone seemed to have fun - and they've all added computer science to their planned coursework.

Classroom

Our room had a whiteboard and I hooked up my laptop to a TV monitor. Students occasionally brought their laptops in for lab-type days, but mostly stuck to paper and pencil. An average Sunday looked like this:

• before class, look over homework solutions submitted on Google drive
• get settled (sometimes accompanied with a problem on the whiteboard)
• go over the homework, discuss common mistakes, make sure everyone is up to speed
• explore / practice new content (mix of lecture, whiteboarding, pair worksheets)
• after class, send out examples from class with practice problems / starter code

We assigned homework (small practice problems) some weeks. The prompts came with starter code to play with. Here are some examples:

• Write a program that uses escape sequences
• Integrate variables into a "receipt" program that prints out the total price of a restaurant meal with tax/tip
• Draw various star figures using for loops, parameters, etc
• Write a method area that computes and returns the area of a circle with a given radius
• Interactive program that comes up with "ship names", e.g. "Brad" + "Angelina" = "Brangelina"
• Expressions to generate random numbers, e.g. 1-10 or odd numbers between -5 and 5

We had two assessments. Some of the classes at the center (such as foreign language) have more formal tests that factor into placement. We leveraged these exam dates and asked students to do homework-sized problems on paper to see how well we were teaching the content. The first assessment was in class. Results varied widely, and we allowed students to do the second assessment at home. This felt better to us given our relaxed goals & freed up a day for a new topic. In both cases we spent the following week reviewing answers and working with students to revise their work.

Occasionally, we reused UW examples - these seemed to transfer well. For example, we explored a "party" example (password required at the door) to explore Scanner and String methods. After completing the program, my students decided to blacklist me from the party (regardless of whether I have the password). I was a bit sad about that, but it led to some fun student-directed adjustments:

```public class Example {
public static void main(String[] args) {
System.out.println("Welcome to our birthday party!");
Scanner console = new Scanner(System.in);
String firstName = getFirstName(console);
if (firstName.equalsIgnoreCase("Karan")) {
System.out.println("Get lost!!!");
} else {
String secret = "coolbeans";
System.out.println("you're invited. the party is at 8pm");
} else {
System.out.println("911 is on their way to your location.");
}
}
}
public static String getFirstName(Scanner console) { ... }
}
```

Projects

When a few weeks remained, my co-teacher and I decided to try class projects. By this point we had made it through basic array concepts. We split students into 3 pairs and explained & assigned projects. Students did some work on their own in pairs and checked in with us each week to get some help. Afterwards, students gave presentations at a end-of-year project fair. Other students from the Python/Scratch groups went through a similar process.

We hoped to find project ideas that were interesting, self-contained (e.g. no external libraries), and could be completed in a few weeks. Here are the three projects we chose:

Stick game

This program implements a game where players alternate between picking up 1-3 sticks from a pile, and the player to pick up the last stick loses. Try playing the game to see if you can beat their code:

Here's a picture from a brainstorming session. If it is your turn with n sticks left, the program is guaranteed to win if there is a checkmark at n. For example, you must lose if there is one stick left on your turn - so there is a checkmark next to the number one.

Try beginning a game with fifteen sticks. The closest checkmark below fifteen is at thirteen, so the program chooses two sticks. No matter what you choose next (1, 2, or 3), the program can force you to another checkmark. This pattern repeats and the student pair was able to incorporate it into their program.

The original project idea comes from a SIGCSE resource. In that implementation, the program simulates hundreds of games to build up success counts per choice (1, 2, or 3) at each possible game state. This was more complex than we wanted - so we began with a human vs. human implementation. Then the students replaced one side with a random number generator. Lastly, the random chooser was replaced with the method described above.

Authorship stats

Given text from books by Mark Twain and Jane Austen, the program comes up with similarity scores between various books. It does this by comparing word usage - for example, perhaps one author/book uses "am" more often, and a different author/book uses "I'm" instead. The program counts how often popular words are used by each author, converts these counts to percentages of total word count, and compares percentage arrays to find a resulting difference. We found that this project was more difficult than intended - it required some new content (more complex array wrangling) and a level of abstraction / decomposition beyond what we had practiced in homeworks. At the end, we took the student code and ran it between all sets of books to come up with the matrix in the last slide below. Smaller numbers (like 0) demonstrate that the two books had similar word usage. Large numbers illustrate the relative word usage varied.

Trump & Obama speech generator

This program recycles old quotes from President Trump & President Obama to generate new speeches. We used subsets of text files like this and this. This process is similar to a Markov chain. Given the first word W1 of a new speech, we search through old speeches for all the words following W1. We choose one at random to print, and repeat the process with W2.

Compared to the authorship project, this program didn't demand as much decomposition. Instead, the students faced challenges with end-of-file parsing issues and using new constructs (e.g. ArrayList to build up the word list). The students expanded the original idea to include speeches from Obama & function with multi-word speech beginnings (a speech can start with 'I went' instead of just 'I').

For example, here's a quote from Donald Trump:

"You know I've always said it's very, very hard for a person who is very successful. I have done so many deals. Almost all of them have been tremendously successful. You'll see that when I file my statements. I mean you will see; you will be very proud of me, okay."

Let's say you decide to generate a new speech starting with the word I. The program searches through the quote for the word "I" and builds up a list of the words succeeding "I" - in this case [have, file, mean]. Then the program picks one of these words at random and prints it out. So now we have I have.

The program repeats this process with the word "have". It finds all the words after "have" - [done, been] and prints one at random. So now we have I have been. And so on...try it for yourself:

the student projects (originally in Java) were ported to JS for the console-like demos above

thank you to my co-instructor who suggested we start the course, the students, and to many maintainers of UW curriculum & tools