Computer Science 210
Data Structures
Fall 2016, Siena College
SpellsVector BlueJ Project
Click here to download a BlueJ project for SpellsVector.
SpellsVector Source Code
The Java source code for SpellsVector is below. Click on a file name to download it.
/* $Id: SpellsVector.java 901 2009-09-15 21:16:54Z terescoj $ */
/**
Spell lookup program to demonstrate the use of Vectors
<P>
Special thanks again to J.K. Rowling.
@author Jim Teresco, jteresco@mtholyoke.edu
*/
import structure.*;
public class SpellsVector {
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
Vector spells = new Vector();
spells.add(new Association("Reparo","Fixes damaged object"));
spells.add(new Association("Evanesco","Makes something vanish"));
spells.add(new Association("Expelliarmus","Disarm opponent"));
spells.add(new Association("Accio","Summon object"));
spells.add(new Association("Alohomora","Open a locked door"));
spells.add(new Association("Lumos","Illuminate wand"));
spells.add(new Association("Crucio","Inflict death with great pain"));
spells.add(new Association("Engorgio","Cause target to swell"));
spells.add(new Association("Immobulus","Stop an object's motion"));
spells.add(new Association("Incendio","Start a fire"));
// we can use the Vector's search capability to simplify our code
int spellnum = spells.indexOf(new Association(args[0]));
if (spellnum >= 0) {
Association spell = (Association)spells.get(spellnum);
System.out.println(spell.getValue());
}
}
}