CSC 216 F09/MemoryNotFoundException

From Expertiza_Wiki
Jump to navigation Jump to search

MemoryNotFoundException

The age old game of memory with a computer science twist.

The Problem

This exercise is designed to further reinforce the concepts of exceptions in Java and help clarify where exceptions are supposed to be used in code, and which kind of exception to use.

This game plays much like the classic game of memory, with a slight twist to compensate for the fact that cards may or may not obviously match or not (due to the nature of coding).

Participants and Props

This is a game that is meant to be played with 2 (or more) people and a series of paper cards. The cards should be labeled prior to starting the game.

Cards

For each game 30 cards will be needed. Here are some examples, or you can create your own:

try-Block catch-Block
try {
 String str = "CSC216";
 int num = Integer.parseInt(str);
}
catch (NumberFormatException ex) {…}
try {
 int[] array = new int[5];
 array[6] = 4;
}
catch (ArrayIndexOutOfBoundsException ex) {...}
try {
 Object obj = null;
 obj.equals(null);
}
catch (NullPointerException ex) {...}
try {
 //The only file in the system is named "Dogs.txt"
 File f = new File("Dawgs.txt");
 FileInputStream fis = new FileInputStream(f);
}
catch (FileNotFoundException ex) {...}
import java.util.LinkedList;

try {
 LinkedList list = new LinkedList();
 list = list.next();
}
catch (NoSuchElementException ex) {...}
import java.util.Stack;

try {
 Stack stk = new Stack();
 stk.pop();
}
catch (EmptyStackException ex) {...}
import java.util.List;

try
{
 List list = new List();
}
catch (InstantiatedException ex) {...}
try {
 Object x = new Integer(0);
 System.out.println((String)x);
}
catch (ClassCastException ex) {...}
try {
 String str = "String";
 char ch = str.charAt(7);
}
catch (StringIndexOutOfBoundsException ex) {...}
public class A {
 private class B {}
}

try {
 B b = new B();
}
catch (IllegalAccessException ex) {...}
public void doSomething(int i) {}

try {
 doSomething("thisIsNotAnInt");
}
catch (IllegalArgumentException ex) {...}
try {
 int i = 34 / 0;
}
catch (ArithmeticException ex) {...}
try {
 int[] array = new int[-69];
}
catch (NegativeArraySizeException ex) {...}
try {...}
catch (Exception ex) {...}
try {
     Object x[] = new String[3];
     x[0] = new Integer(0);
}
catch (ArrayStoreException ex) {...}

The Script

Setup: Shuffle the cards and then set them out in a 5 by 6 grid (face-down).


Gameplay: Each player takes a turn in order to select any two of the face-down cards. If the cards match, the player collects them and is allowed to go again. If the cards do not match, the cards are reset face-down where they were. The next player may then go.

  • Definition of a "Match": When two cards are selected, a player may assert that one of the cards is the corresponding exception to a try block of code. If that is true, then the it is a match. However, if another player believes that the two blocks of code do not match, then he/she may assert as such, and challenge the match. A rulebook/the internet/a key/etc. may be consulted to determine who is correct, and the person who is decidedly wrong loses their next turn.
  • Winning: After all the cards have been collected, the player with the most cards is declared the victor. If both players have the same amount of cards, the game ends in a draw.

Acknowledgement

Game created by Rich Fay and Kyle Nicholls.