CSC 216 F09/BeanExceptions

From Expertiza_Wiki
Revision as of 01:10, 23 November 2009 by Pjfinega (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Game: Bean Exceptions

by Max Gallagher and Patrick Finegan.

Purpose

This excercise is to help a class more actively participate in learning about throwing and catching exceptions.

Setup

A team is 6-9 people (or one row). In the team there is one "catcher" and the rest are "staff."

The catcher for each team goes and stands in the front of the room with the other catchers. The staff stays in their seats. The staff will be handed different colored (and possibily numbered) bean bags.

The different colored beanbags will represent common exceptions (NullPointerException(), ArrayIndexOutOfBounds(), etc...). On the screen will be a powerpoint presentation with different scenarios where exceptions would be thrown and caught.

The Game

For each scenario the staff throw beanbags to the front where the catchers catch these exceptions/bean bags. (It is suggested that all laptops be removed from deskspace for this activity)

The staff's job is to throw the correct beanbag. The catcher's job is to catch the correct beanbag. The catchers do not neccesarily have to catch the beanbag thrown by his/her team, and is encouraged to try to catch other staffs' correct exceptions, or interfere with the catching of other catchers.

A beanbag counts as thrown when it has left a staff members hands and is headed to the front of the room.

A beanbag counts as caught if the catcher is still holding the beanbag when the time to tally scores is called.

After 10 seconds of bean bag filled chaos, the scores are tallyed.

Scoring

  • 1 Point will be awarded for the correct beanbag thrown by the staff.
  • 1 Point will be awarded for the correct beanbag caught by the catcher.
  • 0 Points will be awarded for uncaught/unthrown exceptions.
  • -1 Points will be deducted for incorrectly thrown beanbags.
  • -1 Points will be deducted for incorrectly caught beanbags.

Victory

The team that scores the most points will win a delicious cake.

Example

Example 1

A powerpoint presentation slide will be shown on the screen. It will have an example exception situation on it.

You are provided a code snippet:

public class MyArray{
     public static void main(String[] args){
          int[] array = new int[5];
          System.out.println("First Element: "+array[0]);
          System.out.println("Last Element: "+array[5]);
     }
}

Also on the powerpoint slide (and every slide) is a key for which color bean bag represents which exception.

The staff then has 20 seconds to evalute the exception that would be thrown by the code, agree upon the answer, and throw the appropriate beanbag to a runner (ideally their own)

Example 2

A second example to show how this activity can be used to show students they can write their own exceptions:

public class SquareRootException extends Exception{
     public SquareRootException(){
          super("Square Root of negative number");
     }
     
     public SquareRootException(String message){
          super(message);
     }
}

public class MyMathClass{
 
. . .
 
     public double squareRoot(double value){
          if( value  >= 0 )
               return Math.sqrt(value);
          else
               throw new SquareRootException("Attempted Square Root of negative number");
     }
}

Now admittedly the answer should be a no-brainer. But you can use this example to test how many students are paying attention and as a trial run for the first round of the game.