CSC 216/BeanExceptions: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Game: Bean Exceptions==
==Game: Bean Exceptions==
by Max Gallagher and Patrick Finegan.
by Max Gallagher and Patrick Finegan.


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


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


Line 13: Line 16:


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


The job of the staff is to throw the correct beanbag.
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 job of the runner is catch the correct beanbag. The runner does not neccesarily have to catch the beanbag thrown by his team.


A beanbag counts as thrown when it has left a staff members hands is headed to the front of the room.
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 caught if the runner is still holding the beanbag when the time to tally scores is called.
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.
After 10 seconds of bean bag filled chaos, the scores are tallyed.


===Scoring===
===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 runner.
*1 Point will be awarded for the correct beanbag thrown by the staff.
0 Points will be awarded for uncaught/unthrown exceptions.
*1 Point will be awarded for the correct beanbag caught by the catcher.
-1 Points will be deducted for incorrectly thrown beanbags.
*0 Points will be awarded for uncaught/unthrown exceptions.
-1 Points will be deducted for incorrectly caught beanbags.
*-1 Points will be deducted for incorrectly thrown beanbags.
*-1 Points will be deducted for incorrectly caught beanbags.


===Victory===
===Victory===
The team that scores the most points will win a delicious cake.
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:
<pre>
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]);
    }
}
</pre>
Also on the powerpoint slide (and every slide) is a key for which color bean bag represents which exception.
<center>[[Image:legend.png]]</center>
The staff then has 20 seconds to <b>evalute</b> the exception that would be thrown by the code, <b>agree</b> upon the answer, and <b>throw</b> 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:
<pre>
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");
    }
}
</pre>
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.

Latest revision as of 03:05, 17 November 2009

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.