I need some help coming up with good tests for this program. Here is the assignment info
Question:
I need some help coming up with good tests for this program. Here is the assignment info as well as the code I have so far.
One of MedCo's big accounts is Kirkland Grace Hospital (KGH). Kirkland Grace loves MedCo's automatic thermometer that displays and updates a patient's temperature every 10 seconds. KGH is asking if the automatic thermometer can be enhanced to add limit checks after each update. Specifically, they want to start out with a high temperature check of 37.6C and a low check of 36.5C. If the value for the temperature is outside this defined range, they want to see an alarm message in the format:
3:02:10 PM Alarm: Temperature is 37.9C Over High Limit of 37.6C
4:26:30 PM Alarm: Temperature is 36.4C Under Low Limit of 36.5C
When the temperature is back in range, they want to see a message in the format:
11:17:00 PM Return: Temperature is 37.4C In Range
Note that a temperature that exactly matches the high or low limit is still good, the value must be outside the range to cause an alarm.
MedCo's programmers get together and decide this can be done with Java by making a class called Limit that hold the high and low values. Limit needs:
- an Init Method (Constructor) with no arguments,
- an Init Method that passes the high and low arguments,
- Setter Methods for high, low, and both,
- Print (toString) method to display the settings,
- 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.
- 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.
- For testing, the Limit class can use a simulated clock. The clock should start at 1:00:00 PM and every time CheckLimit is called, the clock should increment 10 seconds.
Submission:
Submit both your source file (Limit.java) with code for all of the Methods discussed above and submit the Test Code - preferably in a separate .java file
import java.io.FileOutputStream;
import java.text.DecimalFormat;
enum LimitState {
NORMAL, LOW, HIGH
}
public class Limit {
double high;
double low;
public Limit() {
high = 37.6;
low = 36.5;
}
public Limit(double high, double low) {
super();
this.high = high;
this.low = low;
}
public void print() {
System.out.println("Below are the Settings");
System.out.println("High Temprature " + high);
System.out.println("Low Temprature " + low);
}
LimitState currentState = LimitState.NORMAL;
public void checkLimit(double temp, String filePath,String time) {
String message;
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 ";
}
try {
FileOutputStream outputStream = new FileOutputStream(filePath, true);
byte[] strToBytes = (" " +message).getBytes();
outputStream.write(strToBytes);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
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;
}
public static void main(String [] args) {
//simulate the clock
//Always show two digits.
DecimalFormat formatter = new DecimalFormat("00");
// Simulate the clock.
for (int hours = 1; hours <= 3; hours++)
{
for (int minutes = 0; minutes <= 59; minutes++)
{
for (int seconds = 0; seconds <= 59; seconds+=10)
{
String time = formatter.format(hours) + ":" +
formatter.format(minutes) + ":" +
formatter.format(seconds) + "PM";
Limit l = new Limit();
double temp = 35 + (Math.random() * (38 - 35)+1);
l.checkLimit(temp, "tempFile.txt",time);
}
}
}
}
}
Management Accounting
ISBN: 978-0132570848
6th Canadian edition
Authors: Charles T. Horngren, Gary L. Sundem, William O. Stratton, Phillip Beaulieu