Building Parsers with Java

sjm.examples.karate
Class KaratePuzzle

java.lang.Object
  |
  +--sjm.examples.karate.KaratePuzzle

public class KaratePuzzle
extends java.lang.Object

Each of four martial arts students has a different specialty. From the following clues, can you determine each student’s full name and her special skill?

  1. Ms. Ellis (whose instructor is Mr. Caldwell), Amy, and Ms. Fowler are all martial arts students.
  2. Sparring isn’t the specialty of either Carla or Dianne.
  3. Neither the shoot-fighting expert nor the pressure point fighter is named Fowler.
  4. Children’s techniques aren’t the specialty of Dianne (whose instructor is Ms. Sherman).
  5. Amy, who disdains pressure point fighting, isn’t Ms. Goodrich.
  6. Betti and Ms. Fowler are roommates.
  7. Ms. Hightower avoids sparring because of its point scoring nature.


Field Summary
protected  Student amy
           
protected  Student betti
           
protected  Student carla
           
protected  Student dianne
           
protected  java.lang.String[] lastNames
           
protected  java.lang.String[] specialties
           
protected  Student[] students
           
 
Constructor Summary
KaratePuzzle()
           
 
Method Summary
protected  void assembleStudents(java.lang.Object[] lasts, java.lang.Object[] specs)
           
protected  boolean cluesVerify()
           
static void main(java.lang.String[] args)
          Solve the karate puzzle.
protected  void showStudents()
           
protected  void solve()
          Generate all permutations of last names and specialties, and check each arrangement to see if it passes all the clues that the puzzle specifies.
protected  Student studentNamed(java.lang.String lastName)
          Return the Student who has the given last name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

amy

protected Student amy

betti

protected Student betti

carla

protected Student carla

dianne

protected Student dianne

students

protected Student[] students

lastNames

protected java.lang.String[] lastNames

specialties

protected java.lang.String[] specialties
Constructor Detail

KaratePuzzle

public KaratePuzzle()
Method Detail

assembleStudents

protected void assembleStudents(java.lang.Object[] lasts,
                                java.lang.Object[] specs)

cluesVerify

protected boolean cluesVerify()
Returns:
true, if the student objects meet all the clues in the puzzle

main

public static void main(java.lang.String[] args)
                 throws CombinatoricException
Solve the karate puzzle.
Throws:
CombinatoricException - Shouldn't happen

showStudents

protected void showStudents()

solve

protected void solve()
              throws CombinatoricException
Generate all permutations of last names and specialties, and check each arrangement to see if it passes all the clues that the puzzle specifies.
Throws:
CombinatoricException - Shouldn't happen

studentNamed

protected Student studentNamed(java.lang.String lastName)
Return the Student who has the given last name
Parameters:
lastName - String
Returns:
Student, the Student with the given last name

by Steve Metsker