Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete PowerPlant.java by implementing a Publisher-Subscriber mechanism. PowerPlant.java: package pubsub; class Reactor extends Publisher { private double temperature = 1000; private final double critical =

Complete PowerPlant.java by implementing a Publisher-Subscriber mechanism.

PowerPlant.java:

package pubsub;

class Reactor extends Publisher { private double temperature = 1000; private final double critical = 1500; public boolean tooHot() { return critical <= temperature; } public double getTemperature() { return temperature; } public void inc(double amt) { temperature += amt; } public void dec(double amt) { temperature -= amt; } }

class BeepingAlarm implements Subscriber { Reactor myReactor; public void update() { if (myReactor.tooHot()) { System.out.println('\u0007'); // beep } } }

class PrintingAlarm implements Subscriber { Reactor myReactor; public void update() { if (myReactor.tooHot()) { System.out.println("Warning: reactor too hot!"); } } } }

public class PowerPlant { public static void main(String[] args) { Reactor r = new Reactor(); BeepingAlarm alarm1 = new BeepingAlarm(r); PrintingAlarm alarm2 = new PrintingAlarm(r); r.inc(100); r.inc(100); r.inc(100); r.inc(100); r.inc(100); r.inc(100); } }

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

Step: 3

blur-text-image

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

3. What are potential solutions?

Answered: 1 week ago