Proposed Solution
To Parts Of
Mandatory
Fall 2012
PhoneBook
- owner : String
Contact
- name : String
- address : String
Friend
-firstMeet : String
- contacts *
Relative
- relationship : String
PhoneBook
- ownerName : String
Contact
- name : String
Friend
-firstMeet : String
- contacts *
Relative
- relationship : String
Place
+ getAddress() : String
«interface»
City Municipality
* 0..1
- address :String - address :String
PhoneBook
- ownerName : String
Contact
- name : String
- localPhone: String
- countryPhoneCode: String
- completePhoneNumber : String
Friend
-firstMeet : String
- contacts *
Relative
- relationship : String
Place
+ getAddress() : String
«interface»
City Municipality
* 0..1
- address :String - address :String
Country
- countryPhoneCode: String
* *
1
There are some software that is available to you:
The CommandProcesser class has two methods that will be called from some other
UserInterfaceController
+ getMeHome() : void
+ getMeHomeIAmSick( emergencyLevel : Integer ) : void
LocationManager
+ getLastKnownLocation() : Location
HBIntervalUpdater HeartBeatSensor
+ oneMoreBeat()
- updateIntervals()
HeartBeatSensor
+ registerHeartBeatListener( heartBeatListener: HeartBeatListener) : void
Location
+ getLatitude() : double
+ getLongitude() : double
+ getTime() : long
+ setLatitude(latitude : double) : void
+ setLongitude(longitude : double) : void
+ setTime(time : long) : void
- latitude : double
- longitude : double
- time : long
+ oneMoreBeat () : void
«interface»
HeartBeatListener
BodyTemperatureSensor
+ getTemp() : double
OperatorController
UserInterfaceController
+ getMeHome() : void
+ getMeHomeIAmSick( emergencyLevel : Integer ) : void
BodyTemperatureSensor
+ getTemp() : double
public class LocationManager {
LocationListener[] locationListeners;
public void requestLocationUpdates(int minTimeBetweenUpdates,
LocationListener locationListener) {…}
public Location getLastKnownLocation() {…}
}
public interface LocationListener{
public void onLocationChanged(Location location);
}
public class PathTracker {
public void onLocationChanged(Location location){…}
}
public class Location{
private double latitude;
private double longitude;
private long time;
public double getLatitude(){…}
public double getLongitude(){…}
public long getTime(){…}
public void setLatitude(double latitude){…}
public void setLongitude(double longitude){…}
public void setTime(long time){…}
}
Fig.1
<?xml version="1.0"?>
<JourneyRegister>
<Journey userName=“Harald“ phoneNumber=“12345678”>
<start>
<Location latitude=“58.351944” longitude=“8.544444” time=“1319534189” />
</start>
<passedLocations>
<Location latitude=“58.351997” longitude=“8.544454” time=“1319590011” />
<Location latitude=“58.351999” longitude=“8.544455” time=“1319633452” />
</passedLocations>
<end">
<Location latitude=“58.351944” longitude=“8.544444” time=“1319690012” />
</end>
</Journey>
<Journey userName=“Harald“ phoneNumber=“12345678”>
<start>
<Location latitude=“58.351944” longitude=“8.544444” time=“1319540400” />
</start>
<passedLocations>
<Location latitude=“58.351997” longitude=“8.544460” time=“1319547303” />
</passedLocations>
<end">
<Location latitude=“58.351944” longitude=“8.544442” time=“1319551234” />
</end>
</Journey>
</JourneyRegister>
Table: PhoneInfo
phoneNumber userName
12345678 Harald
phoneNumber JourneyId start start
12345678 1 11 14
12345678 2 15 17
Table: Journey
latitude JourneyId longitude time
58.351944 1 8.544444 1319534189
58.351997 1 8.544454 1319590011
Table: Location
58.351999 1 8.544455 1319633452
58.351944 1 8.544444 1319690012
58.351944 2 8.544444 1319540400
58.351997 2 8.544460 1319547303
58.351944 2 8.544442 1319551234
LocationId
11
12
13
14
15
16
17
The time attribute of class Location represents the time when the location where decided and it is given as the number of
milliseconds since 1970.
Propose one or more OCL constraints that ensure that the start time of the journey is before the end time of the journey. Also, make
a constraint that ensures that all other locations of the journey are between the start and end time (role name start identify the start
location, role name end identify the end location and role name passedLocations identifies the other locations of the journey).
Context Journey inv:
start.time < end.time
Context Journey inv:
passedLocation->forall((start.time < time) and (time< end.time))
-- The above constraint assumes that start and end is not members of passedLocation
-- The following constraint assures this
Context Journey inv:
(not passedLocation->includes(start)) and (not passedLocation->includes(end))
c) The GPS device of the phone is handled by the LocationManager which is partly described above (Fig.1). The LocationManager is our software interface to the GPS device and it has among others the following operations:
- getLastKnownLocation() : Location
- requestLocationUpdates(minTimeBetweenUpdates : int, locationListener: LocationListener ) : void Operation getLastKnownLocation returns the current location. An object of a class that has implemented interface LocationListener can be registered as listener to location updates (class PathTracker has implemented this interface). Operation requestLocationUpdates is used to do the registration, parameter locationListener must then be a reference (link) to the object that are to receive the location updates; parameter minTimeBetweenUpdates is the minimum time interval in milliseconds between two location updates. A location update is performed by the LocationManager when it calls operation onLocationChanged (see interface LocationListener Fig. 1) of the object(s) that are to receive the location update (parameter location is the new location). The locations of one journey are to be registered in the JourneyRegister and the PathTracker is in some way involved in this registration.
Start Journey
Inspect and handle
Journey(s)
End Journey
Precondition: PathTracer (PT) application started. User choose to register a journey. User gives name to journey or PT supplies default name. User choose to start the journey.
Precondition: PathTracer (PT) application started. User can view current location of ongoing journey (if any). User can view the registered locations of all registered journeys. (User can delete and in different ways manipulate journeys.)
Precondition: PathTracer (PT) application started and ongoing journey. User choose to end ongoing journey.
A use case diagram together with some “use case texts”
that describe the user interaction with the phone for a
journey from start to end.
C1
LocationManager
+ requestLocationUpdates(minTimeBetweenUpdates : int, locationListener: LocationListener ) : void
+ getLastKnownLocation() : Location
«interface»
LocationListener
PathTracker
locationListeners *
PhoneInfo Location
thePhone passedLocations 1 * start 0..1 end 0..1
journeys *
JourneyRegister
Journey
+ createJourney(name : String) : Journey
+ getName() : String
+ setName(newName : String) : void
+ addFirstLocation(loc : Location)
+ addEndLocation(loc : Location)
+ addLocation(loc : Location)
- name : String
- isOngoingJourney : boolean
currentJourney 0..1
1
The new model elements are given in red ! I’m ignoring the phone info.
C2
+ onLocationChanged(location : Location) : void
# setIsOngoingJourney(b : boolean) : void
+ getIsOngoingJourney() : boolean
+ commandNewJourney(name : String) : void
+ commandStartJourney() : void
+ commandEndJourney() : void
1
commandNewJourney(name)
:JourneyRegister :PathTracker
:Journey
setName(name)
User
Returns reference to
the created journey,
this Journey is set as
currentJourney of
the :PathTracker.
User choose to register a journey
User gives name to journey – this is not shown here (part of GUI).
In regard to the sequence diagram I assume (could have used OCL):
- The application has been started.
- The PathTracker has been registered as an LocationListener
(e.g., by some call like this: locationManager. requestLocationUpdates(<some number>, pathTracker),
where locationManager is a reference to the LocationManager and pathTracker is a reference to the PathTracker).
- That there is no ongoing journey.
Property
isOngoingJourney
is still false since the
journey has not been
started yet.
createJourney(name)
C3
commandStartJourney()
:LocationManager :PathTracker User
User choose to start the journey
I assume that the Journey has been created but not started.
:Journey
startLoc = getLastKnownLocation()
addFirstLocation(startLoc)
Property
isOngoingJourney
is set to true since the
journey has started.
:LocationManager :PathTracker
While the journey goes on
I assume that the Journey has been started.
:Journey
onLocationChanged(location)
addLocation(location)
onLocationChanged(location)
addLocation(location)
commandEndJourney()
:LocationManager :PathTracker User
User choose to end the journey
I assume that the Journey has been created and started.
:Journey
endLoc = getLastKnownLocation()
addEndLocation(endLoc)
Property
isOngoingJourney
is set to false since the
journey has ended.
C4 Translating the sequence diagrams to communication
diagrams are rather strait forward. Below is
“While the journey goes on ”
:LocationManager :PathTracker :Journey 1.onLocationChanged(location) 2.addLocation(location)
C5
choose to
register journey
:JourneyRegister :PathTracker User
asks for a new
journey
creates a new
journey and sets
its name
User choose to register a journey
choose to
start journey
:LocationManager :PathTracker User :Journey
receives
“register journey”
command
gets current
location
User choose to start the journey
current
location
forward current
location to journey current
location
add current
location as start
location I have not supplied “User choose to end a journey”
– it would be very similar to this one.
:LocationManager :PathTracker :Journey
While the journey goes on
forward current
location to journey location
add
location
new location
observed
location
D – Parts of a solution
You are to define class DangerousZoneInfo (a call to getDangerousZoneInfo returns such a
value) which should describe one dangerous zone (the zone is defined as a circle, see
description of addProximityAlert above); DangerousZoneInfo should also contain a textual
description of the type of danger.
DangerousZoneInfo
+ getCentreLatitude() : double
+ getCentreLongitude() : double
+ getRadius() : float
+ getDescription() : String
+ setCentreLatitude(latitude : double) : void
+ setCentreLongitude(longitude : double) : void
+ setRadius(r : float) : void
+ setDescription(txt : String) : void
- latitudeCentre : double
- longitudeCentre : double
- radius : float
- description : String
DangerousZoneCommunicator
+ getDangerousZoneInfo() : DangerousZoneInfo
DangerousZonePoller
+ pollingForDangerousZoneInfo() : void
1
LocationManager
+ addProximityAlert(double latitude, double longitude, float radius) : void
1
:LocationManager :DangerousZonePoller :DangerousZoneCommunicator
info = getDangerousZoneInfo()
addProximityAlert(infor.getCentreLatitude(), …)
[info not equal null]
info = getDangerousZoneInfo()
addProximityAlert(infor.getCentreLatitude(), …)
[info not equal null]
Get DangerousZoneInfo and inform LocationManager.
LocationManager
+ addAlertListener(AlertListener : alertListener ) : void
+ removeAlertListener(AlertListener : alertListener ) : void
«interface»
AlertListener + alertOn() : void
+ alertOff() : void
PathTracker
+ alertOn() : void
+ alertOff() : void
alertListeners *
LoadSpeaker
+ on() : void
+ off() : void
1
The PathTracker manages the alerts from
LocationManager and turns the speaker
on and off.
:LocationManager :PathTracker :LoadSpeaker
alertOn()
on()
alertOff()
off()