Answered step by step
Verified Expert Solution
Link Copied!

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: 1 trumpet was played!" "WARNING: 2 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: 1 Trumpet Call: "Teacher: Helps get every kid home safe" 2 Trumpet Calls: "Teacher: Brings all students to the underground shelter" Shop Owner: 1 Trumpet Call: "Shop Owner: Close down shop and head home" 2 Trumpet Calls: "Shop Owner: Drops everything and find nearest hideout" Knight: 1 Trumpet Call: "Knight: Helps everyone get home safe" 2 Trumpet Calls: "Knight: Prepares for battle" DRIVER: package observer; public class TownDriver public static void main(String[] args) System.out.println("A Happy Little City"); Watchman watchman = new Watchman(); Observer fredrick = new ShopOwner(watchman); Observer lillian = new Teacher(watchman); Observer monte = new Knight(watchman); System.out.println(""); watchman.issueWarning(1); System.out.println(""); watchman.issueWarning(2); OUTPUT EXAMPLE: A Happy Little City WARNING: 1 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: 2 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions