Java Reference
In-Depth Information
3. The class, FireAlarm, inherits from SecurityAlarm and has two constant
values. One indicates a maximum temperature threshold. If the simulation
of the alarm sensor exceeds the threshold, the fire alarm is activated. The
other constant indicates a temperature failure threshold, to prevent false
alarms. If the simulation of the alarm sensor yields a temperature below this
value, the fire alarm has malfunctioned. The source code for this class,
FireAlarm.java, is located in the Chapter10 folder on the Student Data Disk.
4. The class, COAlarm, inherits from SecurityAlarm and has two constant
values. One indicates a maximum carbon monoxide threshold. If the
simulation of the alarm sensor exceeds the threshold, the carbon monoxide
alarm is activated. The other constant indicates a carbon monoxide failure
threshold, to prevent false alarms. If the simulation of the alarm sensor
yields a carbon monoxide level below this threshold, the carbon monoxide
alarm has malfunctioned.
5. The sensorSample() method is used to simulate alarm conditions by
generating a random number value simulating a sensor reading. If the
alarm is activated, this method calls the alarm() method. If the alarm fails,
this method calls the alarmFailure() method. Compile all source code and
execute the test program to obtain the output as displayed in Figure 10-63c
on the next page.
SecurityAlarm
ALARM_NORMAL = 0
ALARM_ACTIVATED = 1
ALARM_FAILURE = 2
void alarmFailure(String)
void alarm()
int sensorSample()
EntryAlarm
FireAlarm
COAlarm
ENTRY_THRESHOLD = 0.5
String location
int alarmNumber
double entrySensor
MAX_TEMP_THRESHOLD = 200.0
TEMP_FAIL_THRESHOLD = 40.0
double tempThreshold
double tempSensor
String location
MAX_CO_THRESHOLD = 150
CO_FAIL_THRESHOLD = 50
int COThreshold
int COSensor
String location
FIGURE 10-63a
(continued)
Search WWH ::




Custom Search