Question: Design a program with the following methods: public PatternDetector(List pattern, String message) The constructor should take a list of strings. Every time it sees that
Design a program with the following methods: public PatternDetector(List pa t t e r n = new A r rayLi s t ( ); pa t t e r n . add (" Blue " ) ; pa t t e r n . add ("Red " ) ; pa t t e r n . add (" Green " ) ; pa t t e r n . add (" Blue " ) ; Pa t t e r nD e t e c to r pd = new Pa t t e r nD e t e c to r ( pa t te rn , " Pa t te rn found ! " ) ; pd . l i s t e n ("Red " ) ; pd . l i s t e n (" Yellow " ) ; pd . l i s t e n (" Blue " ) ; pd . l i s t e n ("Red " ) ; pd . l i s t e n (" Green " ) ; pd . l i s t e n (" Blue " ) ; / / w i l l p r i n t out " Pa t te rn found ! " pd . l i s t e n ("Red " ) ; pd . l i s t e n (" Green " ) ; pd . l i s t e n (" Blue " ) ; / / w i l l p r i n t out agai n . Note from the example above, patterns can overlap. (This can be surprisingly harder than it looks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
