/** A boolean variable is a lowercase letter */ public class BooleanVariable extends BooleanExpression { private static HashTable values = new HashTable(); public BooleanVariable (char varname) { // @@@ STUB.. to do: if the variable doesn't exist yet // in the hash table, then insert it with the default value // of true. If it does exist, let it keep its current value } public BooleanVariable (char varname, boolean value) { // @@@ STUB.. to do: if the variable doesn't exist yet // in the hash table, then insert it with the value given. // If it does exist, and the value given is consistent with the // current value no problem. // otheriwse, there is a conflict--in that case, // throw new IllegalArgumentException(""); } // As variables are encountered, they are added to the hashtable. // It's static because we want the variable p to always have the same // value no matter where it appears in the expression. /** set the value of a variable @param varname the variable to set (e.g. 'p') @param newValue the new value to give it (true or false) */ public static setValue(char varname, boolean newValue) { // @@ STUB.. figure out if varname is in the hash table // as a key. If so, change its value to newValue. // If it isn't, then you can insert it into the hashtable // with the new value. } private char variableName = 'p'; /** look up the value of this variable and return it */ public boolean getValue() { return values.get(variableName); } /** */ public String toString() { return Character.toString(variableName); } }