Question: Please write code that follows the UML in java. You will be implementing the Observer Pattern to create a scenario with watchman and city folk.
Please write code that follows the UML in java. You will be implementing the Observer Pattern to create a scenario with watchman and city folk. Subject: Our subject is the watchman. They are hanging out at the watch tower. When they see trouble coming they play the trumpet. One trumpet call is a moderate warning, two calls is a sever warning. Before notifying the observers they display one of the following messages. "WARNING: trumpet was played!" "WARNING: trumpets were played!" Observers: Our observers are the town folk. We have a Teacher, a Shop Owner, and a Knight. When the watchman issue trumpet calls, they are going to act based on how many calls they hear. They will display the corresponding messages. Teacher: Trumpet Call: "Teacher: Helps get every kid home safe" Trumpet Calls: "Teacher: Brings all students to the underground shelter" Shop Owner: Trumpet Call: "Shop Owner: Close down shop and head home" Trumpet Calls: "Shop Owner: Drops everything and find nearest hideout" Knight: Trumpet Call: "Knight: Helps everyone get home safe" Trumpet Calls: "Knight: Prepares for battle" DRIVER: package observer; public class TownDriver public static void mainString args System.out.printlnA Happy Little City"; Watchman watchman new Watchman; Observer fredrick new ShopOwnerwatchman; Observer lillian new Teacherwatchman; Observer monte new Knightwatchman; System.out.println; watchman.issueWarning; System.out.println; watchman.issueWarning; OUTPUT EXAMPLE: A Happy Little City WARNING: trumpet was played! Shop Owner: Close down shop and head home Teacher: Helps get every kid home safe Knight: Helps everyone get home safe WARNING: trumpets were played! Shop Owner: Drops everything and find nearest hideout Teacher: Brings all students to the underground shelter Knight: Prepares for battle
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
