Texts: Write a Java code using an appropriate Design pattern.
Can handle Emails (Use chain of responsibility pattern) Requirements: You need to take care of the messages reported in each email. Each email has an id, a message, and a priority: High, Medium, Low.
BoardEmailProcessor, CoachEmailProcessor, and CaptainEmailProcessor. BoardEmailProcessor can handle Emails with any priority and doesn't care about others. This will show a message containing "Email# is processed by board". CoachEmailProcessor can handle Emails with Medium priority. This will not handle Emails with Low or High priority and pass the Email to the next Email Processor if exists. This will show a message containing "Email# is processed by coach". CaptainEmailProcessor can handle Emails with Low priority. This will not handle Emails with Medium or High priority. This will show a message containing "Email# is processed by captain". If no Email Processor handles an Email, show a message containing "Email# cannot be processed".
Sample Main Class:
public class Main {
public static void main(String[] args) {
Email a = new Email(121, "who is the opener batsman?", Priority.Low);
Email b = new Email(123, "what will we choose after winning the toss?", Priority.Medium);
Email c = new Email(125, "will Bangladesh participate in the Sri Lanka series?", Priority.High);
EmailProcessor epl = new CaptainEmailProcessor(new CoachEmailProcessor(new BoardEmailProcessor()));
EmailProcessor ep2 = new CoachEmailProcessor();
epl.processEmail(a);
epl.processEmail(b);
epl.processEmail(c);
ep2.processEmail(a);
ep2.processEmail(b);
ep2.processEmail(c);
}
}
Sample Output:
Email 121 is processed by captain.
Email 123 is processed by coach.
Email 125 is processed by board.
Email 121 cannot be processed.
Email 123 is processed by coach.
Email 125 cannot be processed.