Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started