Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Kirkland Grace Hospital loves the new Limit feature but now they are looking for a couple of enhancements: If the temperature is right around the

Kirkland Grace Hospital loves the new Limit feature but now they are looking for a couple of enhancements:

  1. If the temperature is right around the limit boundary, the caregivers can get peppered by messages if the temperature goes back and forth outside and within the limit. They are looking for a way to minimize this chatter. An example might be when the temperature is going back and forth between 37.6 and 37.7. Each transition would create a new message.

  1. KGH would like the option to be able to change some of the text in the messages. Specifically, they would like to have an option to change the text that describes the high, low, and return states. "Over High", "Under Low", and "In Range" are good defaults but KGH would like to be able to try different phrases.

Again, MedCo's programmers get together and decide this can be done with Java by editing the class called Limit:

  • New variables to hold the strings to display for High, Low, and Return conditions.
  • Setter methods to set each new variable individually and a 4th Setter method to update all three in one call.
  • A new feature called a deadband. The deadband will be a new variable that will default to 0.1. There will be Getter and Setter methods for the deadband. The check for return to normal will now be:
    • If previous state was HIGH, if value <= high - deadband then normal.
    • If previous state was LOW, if value >= low + deadband then normal.

Submission:

Submit both your source file (Limit.java) with code for all of the Methods discussed above and the Methods from Stage I. Also submit the Test Code - preferably in a separate .java file. If you are using the simulated clock from last week and you have it in a separate file, then submit that file also.

Here is the code from stage 1. If you could include comments so that I understand the code that would be really helpful. Thank you.

Kirkland Grace Hospital loves the new Limit feature but now they are looking for a couple of enhancements:

  1. If the temperature is right around the limit boundary, the caregivers can get peppered by messages if the temperature goes back and forth outside and within the limit. They are looking for a way to minimize this chatter. An example might be when the temperature is going back and forth between 37.6 and 37.7. Each transition would create a new message.

  1. KGH would like the option to be able to change some of the text in the messages. Specifically, they would like to have an option to change the text that describes the high, low, and return states. "Over High", "Under Low", and "In Range" are good defaults but KGH would like to be able to try different phrases.

Again, MedCo's programmers get together and decide this can be done with Java by editing the class called Limit:

  • New variables to hold the strings to display for High, Low, and Return conditions.
  • Setter methods to set each new variable individually and a 4th Setter method to update all three in one call.
  • A new feature called a deadband. The deadband will be a new variable that will default to 0.1. There will be Getter and Setter methods for the deadband. The check for return to normal will now be:
    • If previous state was HIGH, if value <= high - deadband then normal.
    • If previous state was LOW, if value >= low + deadband then normal.

Submission:

Submit both your source file (Limit.java) with code for all of the Methods discussed above and the Methods from Stage I. Also submit the Test Code - preferably in a separate .java file. If you are using the simulated clock from last week and you have it in a separate file, then submit that file also.

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;

/*

* A variable for current state of the Limit. This should be an 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 the 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;

}

/**

* 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);

}

/**

* A CheckLimit 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.

*

* @param temp

* @param filePath

* @param time

*/

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

// Declare string variable to store the message

String message;

// Check temperature and set message according to the limits.

if (temp > high) {

currentState = LimitState.HIGH;

message = time + " Alarm: Temperature is " + temp + "C Over High Limit of " + high + "C";

} else if (temp < low) {

currentState = LimitState.LOW;

message = time + " Alarm: Temperature is " + temp + "C Under Low Limit of " + low + "C";

} else {

currentState = LimitState.NORMAL;

message = time + " Return: Temperature is " + temp + "C In Range ";

}

// 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

Code import javaioFileOutputStream import javatextDecimalFormat enum LimitState NORMAL LOW HIGH public class Limit private double high private double ... 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

Essentials Of Organizational Behavior Bridging Science And Practice

Authors: Talya Bauer, Berrin Erdogan

1st Edition

1453339248, 978-1453339244

More Books

Students also viewed these Programming questions

Question

Find reactions of support 1,2 and 3 F=10KN, a=2m, ?a=60 (45%) F 2a

Answered: 1 week ago

Question

What is normal service cost? In general, how is it computed?

Answered: 1 week ago

Question

2. In which brain areas do new neurons form in adultspg109

Answered: 1 week ago

Question

1. Which develops first, a neurons axon or its dendritespg109

Answered: 1 week ago