6098 comments
2357 subscribers
6259 on Twitter
Subscribe! Feed reader E-mail

CS21A: Smiley

I drew a smiley on the board and provided the skeleton for a new class
that drew only the circle that represented the face. I asked the
students to get it to display a smiley according to the drawing. While
they did that, I downloaded my source code for Smiley.java and
the modified classes from the BlueJ sample
project (added move() to Triangle and Circle) and showed them my
implementation. I wanted them to define a class that supported many of
the operations the basic shapes did. I started with a single Circle
attribute representing the face, a constructor that created the
circle, and a makeVisible() method that made the face visible.

The major conceptual point I wanted to make was:

You can define your own class that contains objects. You can call
methods on those objects and you don’t have to worry about the
implementation details. You can support the other methods by passing
the method calls to the different objects.

A number of students started by looking at Circle.java and trying to
model their work on it, but I suggested working from the very simple
skeleton we had on the board. This greatly helped the students who
were getting lost in the source code.

I also pointed out that they could use BlueJ to determine the
coordinates and sizes experimentally. Instead of edit-compile-test,
they could interactively create an object, manipulate it, and then
inspect it to find the necessary values.

This exercise was open-ended. After students got the smiley to
display, they added support for moveUp(), moveDown(), moveLeft(), and
moveRight(). moveHorizontal(int distance) and moveVertical(int
distance) followed shortly after. move(int x, int y) required a bit
more thought because they couldn’t just pass the request on. I also
had a simple animate() method. I suggested making it possible for the
user to change the smiley’s colors (face, eyes, and mouth – separate
methods, or one method with three parameters) or size (bit more
complicated).

I think this exercise worked very well. I did not have to tell the
students exactly what to do, although I gave them a number of hints. I
exposed my planning process – first, get the face to display, then add
the eyes, then the mouth, then add other methods one at a time.
Students learned how to plan implementation in small steps. I did not
tell them what they had to do; I just drew a figure on the board and
had a demo up on the projector. On their own, they figured out that
they needed to specify negative height in order to get an inverted
triangle and add offsets during the move.

Short URL: http://sachachua.com/blog/p/1372

On This Day...

  • 2012: Sketchnotes: Girl Geeks Toronto: Vexed in the City — Click on the image for a larger version! Please feel free to share this under the Creative Commons Attribution Licence. This [...]
  • 2012: When your personal value proposition shifts — It’s odd to notice the shifts in the value I create for people. For example, tonight, Girl Geeks Toronto is [...]
  • 2011: Weekly review: Week ending November 18, 2011 — Good week! Lots of progress on coding and testing work projects as well as Quantified Awesome. Getting there… From last [...]
  • 2010: Conversations: Stian Håklev — Stian Håklev is passionate about education – and in particular, the richness of different cultures and perspectives. Here are some [...]
  • 2009: The luxury of making — My standard for decadence used to be the microfiber robe I once had the pleasure of trying in a [...]
  • 2008: TCP window scaling, or zomg the Internet works for me again — Sites such as aircanada.com, pcfinancial.ca, and (horror of horrors!) torontopubliclibrary.ca had gotten _unbearably_ slow on Linux. Here’s how I fixed it [...]
  • 2006: Nov 13 to Nov 19 — This week, I concentrated on schoolwork and got quite a lot of things done. Mark and I submitted my CAS project [...]
  • 2006: Hooray Internet collaboration! — I hadn’t heard anything from my KMD2004 groupmates all weekend, so I was rather worried about the integrative summary that we [...]
  • 2006: Mmm, chocolate — I’m munching on a special chocolate mix from Choco Sol. The slab of sun-dried, bicycle-powered and volcanic-stone-ground chocolate contains cacao, agave, amaranth, [...]
  • 2005: Pride and Prejudice — My suitemates and I watched Pride and Prejudice last night. The tension was absolutely wonderful. Then again, it’s a Jane Austen novel. [...]
  • 2004: sacha/planner-create-note-from-task — ;; Improvements: ;; - Link back to the task? ;; - Make it possible to have your note on another page? (defun sacha/planner-create-note-from-task [...]
  • 2003: CookOrDie: Day 7: Reheated rice, sausage slices — Leftover rice plus Hungarian sausages. Okay, but not as fun as bread or potatoes. Tomorrow, will check out meat shop. Yang chow [...]
  • 2003: Words of wisdom — From William Yu: Communication effects. You can influence a person by taking time to talk with them. (from Fanny’s blog)
  • 2003: CS161 — Having breezed through the first slide set in one class day while the other teachers are just halfway through, I wanted [...]
  • 2003: Kathy has an article! — http://www.theglide.com/editorial/editorial.php?section=contests&article=siargao_cup_2003
  • 2003: My faculty load — sum cs21a 4 1st cs21a 4 1st cs123 4 1st cs231 2 2nd cs21a 4 2nd cs21b 3 2nd cs21b 3 2nd cs161 4 2nd cs161 4 2nd cs197 1

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!