$30
1
Software Engineering
Assignment 2
You are given the classes of three sensors “TemperatureSensor”, “RadiationSensor” and
“PressureSensor”. You are not given the source codes but instead byte-codes. The sensors do
not have a common supertype. The API’s for each sensor is provided below:
Package sensor
Class TemperatureSensor
Field Summary
private double temperature
Method Summary
public double senseTemperature()
returns the value of temperature
public String getTempReport()
returns the status indicating
whether it is “OK”, “Danger” or
“Critical”.
public String getSensorType()
returns the name of the sensor such
as “Temperature Sensor”
Package sensor
Class PressureSensor
Field Summary
private double pressure
Method Summary
public double readValue ()
returns the pressure value
public String getReport()
returns the status indicating
whether it is “OK”, “Danger” or
“Critical”.
public String getSensorName()
returns the name of the sensor such
as “Pressure Sensor”
Package sensor
Class RadiationSensor
2
Field Summary
private double radiationLevel
Method Summary
public double getRadiationLevel() ()
returns the radiation level
public String getStatusInfo()
returns the status indicating
whether it is “OK”, “Danger” or
“Critical”.
public String getName()
returns the name of the sensor such
as “Radiation Sensor”
Each sensor decided the status according to following table.
You are asked to implement a sensor tracker GUI application using Adapter design pattern.
Hints:
There will be three separate views for each sensor. In GUI, you need to create three separate
JPanel objects to draw the sensor display. You are given SensorApplication class as an example.
You can see how to create and add JPanel objects.
Note that none of sensor classes has set method. So you cannot set the value of pressure
sensor object. So you can assume that each sensor will create a random value as sensor value.
Just as an example, a sample implementation for readValue() method of PressureSensor
is given below.
public double readValue() {
Random r = new Random();
int value = r.nextInt(10);
pressure = value;
return pressure;
}
3
Sample runs are provided below:
Sample Run-2:
CRITICAL - - 3.5