Design Patterns Java™ Workbook

(Michael S) #1
Appendix B. Solutions

Running this program looks something like:



java -classpath \oozinoz\classes com.oozinoz.applica-
tions.ShowFilters3 demo.txt



ThE "SPacesHot"
SheLl hOVers aT
100 MeterSFor
2 to 3 MINUTeS,
ERuptinG StAr
BURStS EVErY 10
sEconds THat
gENeRatE
abUnDant
REAdIng-LEvEL
liGhT for a
TypIcaL
sTaDium.


SOLUTION 27.2....................................................................................................................................


One solution is:


package com.oozinoz.io;
import java.io.*;
public class RandomCaseFilter extends OozinozFilter
{
protected RandomCaseFilter(Writer out)
{
super(out);
}
public void write(int c) throws IOException
{
out.write(
Math.random() > .5
? Character.toLowerCase((char) c)
: Character.toUpperCase((char) c));
}
}


SOLUTION 27.3....................................................................................................................................


Your solution should be pretty close to:


package com.oozinoz.function;
public class Exp extends Function
{
public Exp(Function f)
{
super(f);
}

Free download pdf