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 pattern, String message) The constructor should take a list of strings. Every time it sees that pattern, in that order, it should print out the message. public void listen(String input) Receive the input. As an example, Li s t 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!