首页 > > 详细

辅导CSSE4004-Assignment 1辅导Java

The University of Queensland
School of Information Technology and Electrical Engineering
Semester 1, 2020
CSSE4004 - Assignment 1
Due: 5pm on Monday 21/04/2020
Weighting: 25%
1. Introduction
In this assignment, students will be required to develop an application, namely Enviro Smart, which makes
use of sensed environmental and weather information to provide users with suggestions and warnings on
their potential risk from the current environmental conditions. This sensed environmental information is
also referred to as “context information”. Applications that adjust to changes in context information are
considered to be context-aware and fall under the research field of pervasive computing.
Using the context-aware Enviro Smart application, users will be able to receive warnings when various
environmental conditions such as incoming heavy rain or the air pollution level is above a predefined
threshold as well as receive suggestions for activities/places that will minimise the exposure. These
suggestions are based on user-specified preferences.
The Enviro Smart application will make use of the both Remote Method Invocation (RMI) and
Publish/Subscribe architecture for communication between its components.
1.1 Ice Distributed Computing Platform
You will be introduced to Ice in the lab class tasks.
Ice provides two communication paradigms: RMI and notifications (publish/subscribe). You should use
both in the assignment and for this you need to evaluate which communication should be of the type
RMI and which one is more suitable for publish/subscribe.
Publish/subscribe is provided in Ice by IceStorm, as discussed in the labs.
1.2 Assignment components
We assume for the scenario used in this assignment that each person will have the latest smart watch. The
smart watch has several sensors or sensor-like devices (accelerometer, GPS, light, microphone, camera).
However, for the purpose of this assignment we assume that our smart watches not only have an improved
location sensor that can work indoor and outdoor (not only outdoor as GPS does), but also include an Air
Pollution (AP) sensor that can measure Air Quality Index (AQI), a temperature sensor, and also a weather
alarm.
The readings from the sensors are gathered by a Context Manager as described in the following sections.
The location information produced by the location sensor is pre-processed by a Location Server before it
is sent to the Context Manager. The Context Manager evaluates the context (such as the current
temperature, AQI, and location) and issues warnings to the user if an AP overexposure (APO) threshold
or a temperature threshold is reached, or a weather alarm is triggered. The Context Manager also provides
suggestions on alternative places/activities based on user preferences. The application has a user interface
that allows multiple users to query the application on items of interest.
The application, Enviro Smart, has the following components:
 Sensors (Location sensor, Air Pollution (AP) sensor and a Temperature sensor). AllSensors.java
 Weather alarm provides alarms on extreme weather conditions such as heavy rain, hail storm,
strong wind. WeatherAlarm.java
 A Location Server provides Indoor/Outdoor mapping of location coordinates to Context Manager.
LocationServer.java
 A Context Manager evaluates extreme weather warnings, current temperature and APO thresholds
so as to make appropriate suggestions to users based on user preferences captured in the Preference
Repository. ContextManager.java
 A Preference Repository responds to queries issued by the Context Manager regarding preferences
on how the application should make recommendations to users. PreferenceRepository.java
 User Interfaces for users to manage the Enviro Smart application. EnviroAppUI.java
For this assignment, we are not interfacing with actual physical sensors. Instead, your sensor
components will simulate sensor behaviour by reading values from files, and exporting that sensor
data in the appropriate manner for consumption by other system components.
Students are asked to figure out the order in which the components should start, the order in which they
exit, and which communication paradigm (RMI or Publish/Subscribe) to use when communicating
between each component.
1.2 Deliverables

For this assignment, you will deliver:
 Java programs for each of the system components described and named in Section 1.1
 Associated ICE data files, including ‘Slice’ files necessary to build and run the full system
 Test data files that define the behaviour and sensor data produced by the various components,
according to the specifications in Sections 2 through 5 below
 A PDF document describing your design (see Section 10 for details).

See Section 11 for full details on deliverables.
2. Sensors and global weather alarm
The context-awareness of the Enviro Smart application is based on context information collected by three
types of sensors and a global weather alarm. These are:
 A temperature sensor that produces integer readings in the range 0 to 50
 A location sensor that monitors the user’s location.
 An AP sensor that shows the current level of air pollution in the unit of AQI (Air Quality Index)
from 0 to 200.
 A global weather alarm that returns monitoring of extreme weather. The value is one of these
integers:
o 0 - normal weather condition – no alarm is triggered and no weather warning is delivered
o 1 - heavy rain
o 2 - hail storm
o 3 - strong wind
All sensors produce readings every second. The information sent by sensors is in the format: username,
sensor type, sensor reading.
The global weather alarm produces a signal every 60 seconds.
2.1 Starting the sensors and the weather alarm
The temperature sensor, the AP sensor and the location sensor are all started in Eclipse together at the
same time in one java file, AllSensors.java, accepting the following argument:
[username]
where [username] is the name of a user logged into a user Interface, and every user has his/her own
sensors.
AllSensors reads in three different predefined files at start-up. The three files contain readings of the three
sensors for each person.
The name of each predefined files must be named:
Temperature.txt e.g. JamesTemperature.txt
AQI.txt e.g. JamesAQI.txt
Location.txt e.g. JamesLocation.txt
Each line of the predefined files is in the format:
value, number of seconds
value is the value that should be in the update notification.
number of seconds is the number of seconds that value should be used.
The sensors produce the “value” every second for “number of seconds”.
An example content for the predefined file of the location sensor for Alice (i.e., AliceLocation.txt) are as
follows:
A,20
C,10
B,20
D,10
This can be interpreted that the location sensor will report the user to have the location A for the first 20
readings (seconds), then the location B for the next 10 seconds then the location C for the 20 seconds after
that. The location of the user will then be D for 10 seconds.
Once the end of the file is reached, the sensor will return to the beginning i.e. after sending D for 10
seconds, the location tracker will send A for 20 seconds and so on until the application exits.
2.2 Shutting down the Sensors and weather alarm
The sensors and weather alarm shut down (and stop sending information) when the user exits the User
Interface.
3. Location Server (LS)
The Location Server receives location coordinates from the location sensor, determines the current
indoor/outdoor status of the user, and forwards these context information to the Context Manager. The
mapping of the status to location coordinates is specified in the server’s configuration file using the
following structure:
Status : Location Coordinates
Indoor : A, B,
Outdoor : C, D,
The server notifies the Context Manager about the current location coordinate of the user and its
indoor/outdoor status. The server also is responsible for returning a list of all indoor locations to the
Context Manager upon request.
The Location Server is started in Eclipse, and must take the following argument:
location_file.txt
where location_file.txt is the file containing the mapping of the indoor/outdoor status to location
coordinates.
4. Context Manager (CM)
The Context Manager:
 gathers information about Air Quality Index (0-200), weather alarm, and user location from
sensors.
 gathers personal information about temperature threshold and air pollution tolerance threshold of
a user from the Preference Manager.
 calculates a threshold for AP overexposure, and sends a warning together with suggestions of items
of interest when the APO threshold of the user is reached. The suggestions are based on user
preferences and they must be located indoor.
 evaluates temperature and sends a warning together with suggestions of items of interest when the
temperature threshold for a user is reached. The suggestions are based on user preferences.
 responds to queries from the User Interface.
4.1 Evaluating AP Overexposure (APO)
The AQ Index (AQI) gives an indication of the level of air pollution and the potential danger of exposure
to air pollutants. The Context Manager uses AQI, personal medical type and duration of AP exposure to
calculate an AP Overexposure (APO) threshold. The following AQI exposure recommendations is used
by the context manager in the evaluation of a user’s APO threshold.
AQI Air Quality Recommendation Base time
0 to 50 Good You can safely enjoy being outside!
30
seconds
51 to 100 Moderate
People with medical conditions should consider
reducing prolonged or heavy exertion.
15
seconds
101 to 150
Unhealthy for
Sensitive Groups
People with heart or lung disease, older adults, and
children should reduce prolonged or heavy exertion.
10
seconds
150 to 200 Unhealthy
People with heart or lung disease, older adults, and
children should avoid all physical activity outdoors.
Everyone should avoid prolonged or heavy exertion
5 seconds
Table 1. AQI exposure recommendations
A AP Overexposure Threshold of a user is calculated by multiplying a Base Time of the current AQI
(according to Table 1) and the user personal reference to air pollution level (i.e., APO Threshold = Base
Time * Medical Condition Type).
Medical condition types are categorised as follows:
Medical Condition Type 1: People with heart and lung disease, and asthma
Definition: People with heart or lung such as coronary artery disease, congestive heart failure, and
asthma or chronic obstructive pulmonary disease.
Medical Condition Type 2: Children and old adults
Definition: Children age between 0-17 and old adults age above 45.
Medical Condition Type 3: Healthy adults
Definition: Adults age between 18-45 without medical history relevant to lung and heart diseases
The medical condition type of particular users is stored in the Preference Repository. The context manager
queries the Preference Repository for the medical condition type when the user first login to
the User Interface.
A user is considered to be overexposed when the AP Overexposure Threshold is said to be reached. That
is, when the amount of time a user has been located outdoor is greater or equal to the current APO threshold
of the user (i.e. APO Threshold reached = outdoor time ≥ APO threshold).
For example, for user with Medical Condition Type 2 exposed under an AQI of 90, the APO Threshold is
30 (2*15 seconds). The threshold will be reached when the user spent 30 seconds or more in outdoor
locations.
When a user is overexposed (or the APO threshold is reached) the Context Manager will send an AP
Overexposure Warning to the particular user, and make suggestions for items of interest base on his/her
preferences, providing the items of interest are located indoor. The Context Manager is required to query
the location server regarding a list of indoor location, so as to make appropriate suggestions to users.
NOTE:
 The timer (for counting the outdoor duration of a user) starts counting from zero when: (1) the user
moves from an indoor to an outdoor location, or (2) there is a change to current AQ Index (the
APO threshold of the user is also re-evaluated).
 The timer continues to count when the user moves from an outdoor to an outdoor location,
providing the AQ Index stays constant and the APO threshold for the user has not been reached.
 The timer stops counting when: (1) the user is located indoor, or (2) the APO threshold is reached.
4.2 Evaluating weather alarm
The weather alarm takes the highest priority in suggesting users to stay outdoor or to move indoor. The
alarm events must be stored in a predefined weather_alarm.txt file. The context manager queries the next
weather alarm every 60 seconds.
When a weather alarm is triggered (i.e., warning of incoming heavy rain or strong wind), the Context
Manager will send a Weather Warning event to the user and make suggestions for items of interest base
on user’s preferences in any location. In addition, because the alarm has the highest priority in suggesting
users to stay outdoor/indoor, the Context Manager will only give suggestions which are located indoor
until the weather condition has changed to ‘normal’.
4.3 Evaluating temperature
The temperature threshold for a particular user is stored in the Preference Repository. The context manager
queries the Preference Repository for the temperature threshold when the user first login to
the User Interface.
When the threshold is reached (i.e., the current temperature is equal to the threshold predefined in the user
preference), the Context Manager will send a Temperature Warning to the user and make suggestions for
items of interest base on user’s preferences in any location.
NOTE:
 When a temperature threshold is reached, the temperature is not evaluated again until there is a
change of temperature.
4.3 Storing information about the city
The Context Manager maintains a knowledge base which it populates using a city information file read at
start-up. This file contains a number of entries corresponding to items of interest within the city. Each
entry has:
 a unique name for an item of interest, indicated with name
 a location coordinate exists in the accepted by the Location Server (such as A, B,
C, D).
 a short paragraph of information about the item of interest
 a list of services offered at the item of interest
An example of an item of interest entry in the file is:
name: Indooroopilly Shopping Centre
location: A
information: Indooroopilly Shopping Centre is a major regional shopping centre in the western suburb
of Indooroopilly, Brisbane, Queensland, Australia. It is the largest shopping centre in the western suburbs
of Brisbane, by gross area, and contains the only Myer store in that region.
services: cinema, restaurants, pool, shops
name: Garden City
location: B
information: Garden City Shopping Centre is located 10km South of the Brisbane central business district
(CBD) and includes Myer, David Jones, Hoyts Cinema, Freedom and over 230 specialty stores.
services: cinema, restaurants, pool, shops
name: South Bank Parklands
location: C
information: The South Bank Parklands area was created as part of the rejuvenation
of the industrial water front undertaken for World Expo 1988. The Parklands area contains many shops, a
cinema complex, and a large number of restaurants as well as a man-made beach. A river promenade
stretches the length of South Bank Parklands.
services: restaurants, pool, shops, Ferris wheel
name: Brisbane City
location: D
information: The Brisbane central business district (CBD), or 'the City' is located on a point on the
northern bank of the Brisbane River. The triangular shaped area is bounded by the Brisbane River to the
east, south and west. The point, known at its tip as Gardens Point, slopes upward to the north-west where
'the city' is bounded by parkland and the inner city suburb of Spring Hill to the north. The City is bounded
to the north-east by the suburb of Fortitude Valley.
services: restaurants, shops, market, bowling
name: Grey Street
location: C
information: Grey Street is south of the South Bank Parklands and hosts many restaurants and bars. The
street is 1.4km in length and is home to attractions such as the Cineplex Cinema, Queensland Museum
and Brisbane Convention Exhibition Centre.
services: restaurants, cinema, conference centre, museum
Note: If you are using real-world points of interest (this is optional), the places of interest for a given
location should be reasonably close by so this does not confuse the user (e.g. South Bank Parklands
and Grey Street are both close to Location C).
4.4 Making suggestions to users
The Context Manager makes suggestions of item of interest when either a weather alarm is triggered, or
the AQI or temperature thresholds of a particular user is reached. In order to take into account the user
preferences, the Context Manager must indicate to the Preference Manager which threshold has been
reached in the following format:
[Username], weather warning in the case when a weather alarm has been triggered, or
[Username], APO in the case when the APO threshold has been reached, or
[Username], [Temperature Threshold] in the case when the temperature threshold has been reached.
where:
[Username] is the name of the user,
[Temperature Threshold] is the threshold of the temperature that has been reached.
The Preference Repository returns a list of services the Context Manager should suggest to the user. The
weather alarm, which is updated every 60 seconds, has the highest priority. Should both temperature and
APO threshold are reached at the same time, the APO threshold take higher precedence, and the Context
Manager should only request a list of services corresponding to the APO preference. Upon the return of
the list of services from the Preference Repository, the Context Manager sends a list of items of interest
that provide those services to the User Interface of the Enviro Smart Application, but ensures these items
of interest are located indoor if the user’s AP threshold is reached.
To determine whether a list of items of interest is located indoor, the CM queries the Location Server
regarding the indoor/outdoor mapping of the location of the list of items. Such query should be made to
the Location Server for every suggestion
4.5 Responding to queries from User Interface
The Context Manager is also required to respond to queries issued by the User Interface.
Two queries are supported:
 Search for items of interest in the current location
 Search for information about a specific item of interest
Search for item of interest in the current location
The Context Manager responds with an item of interest in the user’s current location.
Search for information about a specific item of interest
The Context Manager searches for the specified item of interest in its knowledge base and returns the
information associated with that item of interest.
More detailed information regarding how the queries are generated is specified in the User Interface
section 6.1.
4.6 Starting the Context Manager
The Context Manager is started from Eclipse, accepting the following argument:
cm_file.txt
where cm_file.txt is the name of the text file containing the information about the city.
4.7 Shutting down the Context Manager
The Context Manager shuts down automatically when all User Interfaces have exited. The shutdown
process of the Context Manager involves deregistering its subscriptions with Ice Storm and exits. The exit
will also trigger shutdown of other components.
5. Preference Repository (PM)
The Preference Repository stores user preferences and evaluates these preferences when requested by the
Context Manager.
5.1 Preference format
A weather alarm preference is in the following format:
when weather warning suggest [service]
An APO preference is in the following format:
when APO suggest [service]
A temperature preference is in the following format:
when [temperature value] suggest [service]
[temperature value] is one of the readings that the temperature sensors can produce.
[service] is the name of a service (e.g., shops) provided by item of interests
APO is just a word indicating the user is being overexposed to air pollution.
Preferences must be loaded from a preference file when the Preference Repository starts up.
The preference file contains at least one and at most three user.
For each user in the file contains at least one temperature preference, exactly one weather alarm
preference, and exactly one APO preference.
The preference file is formatted as follows:
 Each entry has the name of the preference owner
 Each field in the entry is terminated with a new line character
 Each entry is separated from other entries by an empty line
An example entry in the preference file is:
name: Bryan
Medical Condition Type: 2
pref-1: when 30 suggest pool //temp. threshold example
pref-2: when APO suggest cinema //APO threshold example
pref-3: when weather suggest cinema //weather alarm example
5.2 Preference Evaluation
Preference evaluation is initiated by a request from the Context Manager when a weather alarm is triggered
or either one of the APO or Temperature threshold is reached.
This request contains:
 the name of the user whose preferences should be checked
 the triggered weather alarm
 the current temperature readings or the word “APO” depending on which threshold is reached
The Preference Repository checks the preferences for the specified user to see if the context values in the
preferences match with any of the sensor readings. The services suggested by any matching preferences
must then be returned to the Context Manager as the result of the request.
For example, a user Alice has defined the preference:
when 25 suggest pool //temp. threshold example
If a request from the Context Manager contains “Alice, normal, 25”, the Preference Repository will return
“pool” to the Context Manager, which will then return “Indooroopilly”, “Garden City” and “South Bank
Parkland” to the User Interface.
Another example, a user Alice has defined the preference:
when 30 suggest pool //temp. threshold example
when APO suggest shops //APO threshold example
If a request from the Context Manager contains “Alice, normal, APO”, the Preference Repository will
return “shops” to the Context Manager, which will only return “Indooroopilly” and “Garden City” to the
User Interface without “South Bank Parkland”.
5.3 Starting the Preference Repository
The Preference Repository is started from Eclipse, accepting the following argument:
preference_file.txt
where: preference_file.txt is the name of the file containing the user preferences.
5.4 Shutting down the Preference Repository
The Preference Repository shuts down when it receives a notification from the Context Manager
instructing it to do so. The Preference Repository deregisters its subscription with Ice Storm before exiting.
6. The User Interface (UI)
The Enviro Smart Application provides an interface through which users can issue queries for information
about the city, and also receive warnings and suggestions based on predefined preferences when user’s
APO threshold is reached.
Users interact with the Enviro Smart Application using a text-based menu. User menu choices must be
read off standard in. All spec-related Enviro Smart Application output is printed to standard out. All non-
spec Enviro Smart Application output must be printed to standard error.
6.1 Initialisation and queries
The Enviro Smart Application initially asks for a name of the user:
Context-aware Enviro Smart Application
Please enter your user name:
If an invalid name is entered, an error message must appear, and the program must terminate.
Error: The provided name was not found. Please check the name, restart the user
interface, and enter the name again.
Then a main menu will initially appear as:
Context-aware Enviro Smart Application Main Menu

--Please select an option--:
1. Search for information on a specific item of interest
2. Search for items of interest in current location
E. Exit
The user then has the option of selecting 1, 2 or E.
Option 1: Search for a specific item of interest
The user is presented with a prompt requesting the name of an item of interest.
Please enter name of item of interest:
The user enters the name of an item of interest. A request is then made to the Context Manager querying
for information on the item of interest.
The information returned by the Context Manager is then displayed on the screen in the format:
Information about

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!