Implements exercises 29-31 (boolean logic)