Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PROBLEM Here is the copied and pasted code: package patt.ReactorMonitoring ; import java.util.Observable ; public class ResearchCentre extends RadiationMonitor { /** * Constructs a

JAVA PROBLEM

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedHere is the copied and pasted code:

package patt.ReactorMonitoring; import java.util.Observable; public class ResearchCentre extends RadiationMonitor { /**  * Constructs a ResearchCentre object, which observes reactor radiation readings  * and constantly prints a report with the current moving average of the  * recorded observations.  *   * @param location.  * An arbitrary location.  */ public ResearchCentre(String location) { super(null); } /**  * Updates the monitor with a new observation and prints a report.  */ public void update(Observable subject, Object o) { } /**  * Generates a report of the current moving average, updated by a new  * observation. The moving average is calculated by summing all observations  * made so far, and dividing by the quantity of observations so far.  */ public String generateReport() { return null; } }

package patt.ReactorMonitoring; public class ReactorMonitoring { public static void main(String[] args) { // Install a sensor at Reactor A RadiationSensor sensor = new RadiationSensor("Reactor A", 10); // Create sensor observers RadiationMonitor control = new ControlRoom("Reactor A Control Room", 8.0); RadiationMonitor science = new ResearchCentre("Centre for Nuclear Research"); // Attach observers to sensor sensor.addObserver(control); sensor.addObserver(science); // Simulate a scenario try { while (true) { sensor.readRadiation(); Thread.sleep(4000); } } catch (InterruptedException e) { e.printStackTrace(); } } }

package patt.ReactorMonitoring; import java.util.Observable; public class RadiationSensor extends Observable { /**  * Constructs a RadiationSensor object  *   * @param location.  * An arbitrary location.  * @param seed.  * A seed for the random number generator used to simulate radiation  * readings.  */ public RadiationSensor(String location, int seed) { } /**  * Gets the location  *   * @return location  */ public String getLocation() { return null; } /**  * Gets the radiation  *   * @return radiation  */ public double getRadiation() { return 0; } /**  * Updates radiation, changes the state to true, and notifies all observers of  * the change.  */ public void readRadiation() { } }

package patt.ReactorMonitoring; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Observable; import java.util.Observer; public abstract class RadiationMonitor implements Observer { /**  * Constructs a RadiationMonitor object.  *   * @param location.  * An arbitrary location.  */ public RadiationMonitor(String location) { } /**  * Gets the location  *   * @return location  */ public String getLocation() { return null; } /**  * Updates the monitor with a new observation  */ public abstract void update(Observable subject, Object o); /**  * Generates a report based on the observation.  *   * @param observation  * @return a report  */ public abstract String generateReport(); /**  * Gets the current time.  *   * @return The current time in yyyy-MM-dd HH:mm:ss format  */ public String now() { String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; Calendar calendar = Calendar.getInstance(); SimpleDateFormat date = new SimpleDateFormat(DATE_FORMAT_NOW); return date.format(calendar.getTime()); } }

package patt.ReactorMonitoring; import java.util.Observable; public class ControlRoom extends RadiationMonitor { /**  * Constructs a ControlRoom object, which observes reactor radiation readings  * and prints reports if the radiation exceeds a threshold.  *   * @param location.  * An arbitrary location.  * @param warningThreshold.  * The radiation threshold for when reports should be printed.  */ public ControlRoom(String location, double warningThreshold) { super(null); } /**  * Updates the monitor with a new observation and prints a report if and only if  * the observation is equal to or greater than the warning threshold.  */ public void update(Observable subject, Object o) { } /**  * Generates a report based on the current observation.  */ @Override public String generateReport() { return null; } }
Use the observer pattern to implement a system for monitoring the radiation of a reactor. To help you get started, you should first review the observer pattern as well as the JDK classes observer and Observable. Your task is to complete the implementation of four classes: RadiationSensor which extends observable. Because we do not have a real reactor to monitor, we will simulate radiation readings using a random number generator. readRadiation() should set a private radiation variable to a random double between 0 and 10. Hint: to assist you with the remainder of readRadiation(), inspect the JDK class Observable RadiationMonitor which implements the Observer interface. Note that now() is already complete, but you will need to implement the rest of the class except for the abstract methods. ControlRoom which extends RadiationMonitor ResearchCentre which extends RadiationMonitor The ReactorMonitoring class is provided to help with testing and does not need to be submitted. In its current state, the expected output (when all four classes are complete) should be: 2018-02-28 09:54:36: moving average:: 7.3043 :: Centre for Nuclear Research 2018-02-28 09:54:40: moving average 4.9412:: Centre for Nuclear Research 2018-02-28 09:54:44 :: moving average 3.4915 Centre for Nuclear Research 2018-02-28 09:54:48:: moving average: 3.2289 : Centre for Nuclear Research 2018-02-28 09:54:52 moving average :: 4.2207:: Centre for Nuclear Research 2018-02-28 09:54:52 WARNING : 8.1881 Reactor A Control Room 2018-02-28 09:54:56 :: moving average :: 4.135 :: Centre for Nuclear Research 2018-02-28 09:55:00:: moving average 4.7675 Centre for Nuclear Research 2018-02-28 09:55:00 WARNING 8.5628 Reactor A Control Room 2018-02-28 09:55:04: moving average: 5.0653 :: Centre for Nuclear Research 2018-02-28 09:55:08:: moving average: 4.8217 :: Centre for Nuclear Research Use the observer pattern to implement a system for monitoring the radiation of a reactor. To help you get started, you should first review the observer pattern as well as the JDK classes observer and Observable. Your task is to complete the implementation of four classes: RadiationSensor which extends observable. Because we do not have a real reactor to monitor, we will simulate radiation readings using a random number generator. readRadiation() should set a private radiation variable to a random double between 0 and 10. Hint: to assist you with the remainder of readRadiation(), inspect the JDK class Observable RadiationMonitor which implements the Observer interface. Note that now() is already complete, but you will need to implement the rest of the class except for the abstract methods. ControlRoom which extends RadiationMonitor ResearchCentre which extends RadiationMonitor The ReactorMonitoring class is provided to help with testing and does not need to be submitted. In its current state, the expected output (when all four classes are complete) should be: 2018-02-28 09:54:36: moving average:: 7.3043 :: Centre for Nuclear Research 2018-02-28 09:54:40: moving average 4.9412:: Centre for Nuclear Research 2018-02-28 09:54:44 :: moving average 3.4915 Centre for Nuclear Research 2018-02-28 09:54:48:: moving average: 3.2289 : Centre for Nuclear Research 2018-02-28 09:54:52 moving average :: 4.2207:: Centre for Nuclear Research 2018-02-28 09:54:52 WARNING : 8.1881 Reactor A Control Room 2018-02-28 09:54:56 :: moving average :: 4.135 :: Centre for Nuclear Research 2018-02-28 09:55:00:: moving average 4.7675 Centre for Nuclear Research 2018-02-28 09:55:00 WARNING 8.5628 Reactor A Control Room 2018-02-28 09:55:04: moving average: 5.0653 :: Centre for Nuclear Research 2018-02-28 09:55:08:: moving average: 4.8217 :: Centre for Nuclear Research

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago