Zookal
Zookal

We’d love to hear any feedback or comment from you!

© 2011-2021 Zookal Pty Ltd

View question and answer

From our collection of questions and answers
Engineering · Computer Science
Question details

Java:

Modify the program in the Publish/Subscribe design pattern tutorial so that three subscriber objects are notified of changes when the count variable is three or greater. Each subscriber object should display a customized message that reads “Subscriber x has been notified”, where x will be 1, 2, or 3.

public class Publisher private Subscriber subscriberList private int maximumSubseribers: private int nextIndex; An array stores subseribers //Maximum number of subscribers / Array index of next subscriber public Publisher int max / Initialize attributes & ereate subseriber array maximumSubseribers-maxi subscriberList-new Subscriber maximumSubscribers i next Index-0i public void register Subseriber // Register a subscriber unless the subseriber array is Eu11 if (nextIndex <maximum Subseribers subscriberListi nextIndex++-s else System.out-printin ERROR: Subscriber List is full public void notifySubscribers () // Iterate through the subscriber array&invoke update) methods for ( int i-0; i < nextIndex ; i++ ) subscriberList[ ǐ ].update();

public class MyPublisher extends Publisher private int count; public MyPublisher int mx) super(mx count 0 public void increment count++ NotiEy subseribers if count-3 if count3 notifySubseribers)public void update )

public class TestPattern public static void main( String 1 args // Create Publisher & Subscriber objects MySubscriber aSubscribernew MySubscriber MyPublisher aPublisher-new MyPublisher 2 // Register a Subscriber aPublisher.register aSubseriberi // Increment Publisher object to cause state changes aPublisher.increment aPublisher.increment aPublisher.increment aPublisher.inerement

Answer
Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.

Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.