Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Nurses Union is very happy now that the deadband feature is up and working at KGH. KGH is now looking to see if MedCo


The Nurses Union is very happy now that the deadband feature is up and working at KGH. KGH is now looking to see if MedCo can step up their game. They want to be able to have multiple limits on the temperature and updates to the messages as well. After a few meetings (online, of course) MedCo's programmers and KGH agree to the following:

  • There will be a new class called Analog that will be the parent of Limit.
  • The clock timing logic must move from the Limit class to the Analog class
  • The Analog class will use the ArrayList feature to support multiple Limits. The constructor for Analog will fill in the default Limit
  • Limit will need to add some new fields:
    • id: This will be a 4-character String. For backward compatibility, the default Limit will have an ID of "STD "
    • This will default to "" (empty string).

The contents of printStr is added to the Alarm message right after the word "Alarm" (see examples below).

  • Analog will need an addLimit() method that should pass in the ID, printStr, high, low values as arguments. Example calls would be:
    • addLimit("HIGH", "High", 39.0, 36.2);
    • addLimit("CRIT", "Critical", 40.0, 36.1);

limits must be added in order. For each new Limit, high must be >= high for the previous limit added and low must be <= low for the previously added limit. Code must throw Illegal Argument Exception is this condition is not met.

  • Analog will need a deleteLimit() method that should pass in the ID to delete and return true or false if the ID was found and deleted or not.
  • Limit will need a new version of CheckLimit that will not take the file argument and it will return the current state of the Limit (enum of NORMAL, LOW, HIGH).
  • Analog will need a CheckAnalog method that is passed the temperature and a file to printout any alarm or return to normal. Any output must be appended to the end of the file.
  • CheckAnalog will need to test against all the current limits using the new CheckLimit method. Any change in overall state should result in one new line being added to the output file. If one Limit returns to normal but the next Limit below it is still in violation, then no Return message is formatted. For example:

3:02:10 PM Alarm: Temperature is 37.9C Over High Limit of 37.6C

3:47:10 PM Alarm High: Temperature is 39.2C Over High Limit of 39.0C

4:22:40 PM Alarm Critical: Temperature is 40.3C Over High Limit of 40.0C

6:05:50 PM Alarm High: Temperature is 39.8C Over High Limit of 39.0C

6:47:00 PM Alarm: Temperature is 38.9C Over High Limit of 37.6C

11:17:00 PM Return: Temperature is 37.4C In Range


At 6:05, the critical alarm clears but the temperature is still above the high Limit so that Limit is re-posted.

At 6:47, the high alarm clears but the temperature is still above the standard Limit so that Limit is re-posted.


Submission:

Submit both your source files (Analog.java, Limit.java, (and LimitState.java if it is in its own file) ) with code for all of the Methods discussed above and the Methods from Stages I & II. Also submit the Test Code - preferably in a separate .java file


Additional Details:

Here is a sequence that shows how an Analog Object should look after a sequence of calls using the Analog methods.

1) Use the constructor to create an Analog Object called "temperature". It should have one Limit in the Array List of Limit objects when done:

Analog temperature Limit[0] STD 36.5 37.6 ....

2) Make a call to the add limit method. It should now have two Limit records in the Array List of Limit objects when done:

temperature.addLimit( HIGH, 36.0, 38.5 );

Analog Temperature Limit[0] STD 36.5 37.6 .... Limit[1] HIGH 36.0 38.5 ....

3) Make another call to the add limit method. It should now have three Limit records in the Array List of Limit objects when done:

temperature.addLimit( CRIT, 35.0, 39.5 );;

Analog Temperature Limit[0] STD 36.5 37.6 .... Limit[1] HIGH 36.0 38.5 .... Limit[2] CRIT 35.0 39.5 ....

4) Make a call to the add limit method but with bad argument(s). It should still have three Limit records in the Array List of Limit objects when done:

temperature.addLimit( BAD, 35.3, 41.0 ); // Should throw Illegal Argument Exception because 35.3 > 35.0

5) Make a call to the add limit method. It should now have four Limit records in the Array List of Limit objects when done:


Analog Temperature Limit[0] STD 36.5 37.6 .... Limit[1] HIGH 36.0 38.5 .... Limit[2] CRIT 35.0 39.5 .... Limit[3] DEAD 33.0 42.5 ....


6) Make a call to the remove limit method. It should now be back to three Limit records in the Array List of Limit objects when done:

temperature.removeLimit ( CRIT );

Analog Temperature Limit[0] STD 36.5 37.6 .... Limit[1] HIGH 36.0 38.5 .... Limit[2] DEAD 33.0 42.5 ....


Stage 2 code that needs to be changed:

import java.io.FileOutputStream;

/**

*

* @author

*

*/


enum LimitState {

NORMAL, LOW, HIGH

}


public class Limit {


/* Attributes for high and low temperatures */

private double high;

private double low;

/* Attributes for text labels with defaults */

private String highText = "Over High";

private String lowText = "Under Low";

private String normalText = "In Range";

/* attribute for deadband with default */

private double deadband = 0.1;


/*

* A variable for current state of the Limit. Enum with values

* for NORMAL, LOW, HIGH. It should start out as NORMAL.

*/

LimitState currentState = LimitState.NORMAL;


/**

* An Init Method (Constructor) with no arguments

*/

public Limit() {


high = 37.6;

low = 36.5;


}


/**

* An Init Method that passes high and low arguments

*

* @param high

* @param low

*/

public Limit(double high, double low) {


super();

this.high = high;

this.low = low;


}


// Setter methods for high, low, and both

public double getHigh() {

return high;

}


public void setHigh(double high) {

this.high = high;

}


public double getLow() {

return low;

}


public void setLow(double low) {

this.low = low;

}


//getter for deadband

public double getDeadband() {

return deadband;

}

//setter for deadband

public void setDeadband(double deadband) {

this.deadband = deadband;

}

//setter for hightext

public void setHighText(String highText) {

this.highText = highText;

}

//setter for lowtext

public void setLowText(String lowText) {

this.lowText = lowText;

}

//setter for normaltext

public void setNormalText(String normalText) {

this.normalText = normalText;

}

//setter for all three texts

public void setTexts(String highText, String lowText, String normalText) {

setHighText(highText);

setLowText(lowText);

setNormalText(normalText);

}

/**

* Print (toString) method to display the settings,

*/

public void print() {


System.out.println("Below are the Settings");

System.out.println("High Temprature " + high);

System.out.println("Low Temprature " + low);


}


/**

* CheckLimit method that is passed the temperature and a file to print any

* alarm or return to normal. Any output is appended to end of file

*

* @param temp

* @param filePath

* @param time

*/

public void checkLimit(double temp, String filePath, String time) {


// Declare string variable to store message

String message;


// Check temperature and set message according to limits.

// if currentState is HIGH, also consider temp > high - deadband

if (temp > high || (currentState == LimitState.HIGH && temp > high - deadband)) {


currentState = LimitState.HIGH;

//use highText

message = time + " Alarm: Temperature is " + temp + "C " + this.highText + " Limit of " + high + "C";


// if currentState is LOW, also consider temp < low + deadband

} else if (temp < low || (currentState == LimitState.LOW && temp < low + deadband)) {


currentState = LimitState.LOW;

//use lowText

message = time + " Alarm: Temperature is " + temp + "C " + this.lowText + " Limit of " + low + "C";


} else {

currentState = LimitState.NORMAL;

//use normalText

message = time + " Return: Temperature is " + temp + "C " + this.normalText;


}


// Write message to a file

try {


FileOutputStream outputStream = new FileOutputStream(filePath, true);

byte[] strToBytes = (message+" ").getBytes();

outputStream.write(strToBytes);


outputStream.close();


} catch (Exception e) {

e.printStackTrace();

}


}


}


import java.text.DecimalFormat;

/**

* This is the Test class to MedCo's automatic thermometer that displays and

* updates a patient's temperature every 10 seconds.

*

* @author

*

*/

public class TemperatureLimitTest {

public static void main(String[] args) {

// simulate the clock

// Always show two digits.

DecimalFormat formatter = new DecimalFormat("00");

Limit limit = new Limit();

/*

* Simulate the clock.

*

* The clock starts at 1:00:00 PM and ticking till 3:00:00 PM

*/

for (int hours = 1; hours <= 3; hours++) {

/*

* For every minute in the hour of the clock

*/

for (int minutes = 0; minutes <= 59; minutes++) {

/*

* For every 10 seconds in the minute of clock

*/

for (int seconds = 0; seconds <= 59; seconds += 10) {

// Create formatted time string

String time = formatter.format(hours) + ":" + formatter.format(minutes) + ":"

+ formatter.format(seconds) + "PM";

// Create and store random temperature

double temp = 35 + (Math.random() * (38 - 35) + 1);

// Invoke checkLimit() method of Limit class

limit.checkLimit(temp, "tempFile.txt", time);

}

}

}

}

}


Step by Step Solution

There are 3 Steps involved in it

Step: 1

import javaioFileOutputStream author enum LimitState NORMAL LOW HIGH public class Limit Attributes for high and low temperatures private double high private double low Attributes for text labels with ... 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

International Marketing And Export Management

Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr

8th Edition

1292016922, 978-1292016924

More Books

Students also viewed these Programming questions

Question

Explain the characteristics of the three types of needs.

Answered: 1 week ago

Question

Recognize some of the factors that contribute to obesity.

Answered: 1 week ago

Question

Identify the physical and social factors that influence hunger.

Answered: 1 week ago