/*
Chapter 10:
EntryAlarm
Programmer:
Brad Shedd
Date:
May 6, 2004
Program Name: EntryAlarm.java
Purpose:
Inherits from the security alarm
*/
import java.lang.Math;
import java.text.DecimalFormat;
public
class
EntryAlarm
extends SecurityAlarm
{
final
double ENTRY_THRESHOLD = 0.5;
int
alarmNumber;
double
entrySensor;
String location;
public
EntryAlarm(String loc,
int alarmNumber)
{
location =
new
String(loc);
alarmNumber
= alarmNumber;
}
public
int sensorSample()
{
int
status = NO_ALARM;
entrySensor
= Math.random()*10;
if(entrySensor
> ENTRY_THRESHOLD)
{
alarm();
status = ALARM_ACTIVATED;
}
return
status;
}
public
void alarm()
{
DecimalFormat twoDigits =
new
DecimalFormat("##,##0.0");
System.out.println("***
The "+location+" entry
sensor #"+alarmNumber+" has detected a
potential entry.");
System.out.println("***
The reading of "+twoDigits.format(entrySensor)+"
has exceeded the threshold of "+ENTRY_THRESHOLD+"\n");
}
}