/* $Id: Spells.java,v 1.2 2005/09/15 15:05:29 terescoj Exp $ */ /** Spell lookup program to demonstrate the use of Associations
Special thanks to J.K. Rowling. @author Jim Teresco, terescoj@cs.williams.edu */ import structure.*; public class Spells { public static void main(String[] args) { if (args.length == 0) { System.out.println("Specify a spell at the command line"); System.exit(1); } // build the list of magic spells we know Association spells[] = new Association[10]; spells[0] = new Association("Reparo","Fixes damaged object"); spells[1] = new Association("Evanesco","Makes something vanish"); spells[2] = new Association("Expelliarmus","Disarm opponent"); spells[3] = new Association("Accio","Summon object"); spells[4] = new Association("Alohomora","Open a locked door"); spells[5] = new Association("Lumos","Illuminate wand"); spells[6] = new Association("Crucio","Inflict death with great pain"); spells[7] = new Association("Engorgio","Cause target to swell"); spells[8] = new Association("Immobulus","Stop an object's motion"); spells[9] = new Association("Incendio","Start a fire"); for (int spell = 0; spell < args.length; spell++){ for (int spellnum = 0; spellnum < spells.length; spellnum++) { if (spells[spellnum].getKey().equals(args[spell])){ System.out.println(spells[spellnum].getValue()); } } } } }