data留学生辅导、讲解Java设计、Java编程语言调试

- 首页 >> Matlab编程
Part A – Short answer question (21 x 4 = 84 marks)
Answer these questions in your exam booklet. You should be able to answer these in a few lines.
General comments:
- Some questions are harder than others. You will need to prove you deserve a HD. However, there are
enough easy questions to pass the exam if you have studied a reasonable amount and completed most of
the assignments.
- Some questions ask for simple code segments. Simple syntax errors will be ignored however you must
show the main ideas in the code. You could answer in English but code-ish answers are probably easier.
1. Explain the difference between the heading (similar to compas) and GPS sensors in mobile devices. Give
two examples of apps that could use the heading and two example that could use the GPS sensors. With
your examples, explain how they would use these sensors.
The heading is the compass reading and the GPS is the longitude, latitude and altitude from the worlds GPS
network. (2 marks)
There are thousands of applications that you could mention. The aim hear is to demonstrate your
understanding of the devices.
Some for heading would be a simple compass, car driving assistant, walking assistant. You could mention
combinations, e.g. in co-operation with google maps. (1 mark). Explaining how to use the heading should
be brief, e.g. for a simple compass you just print the heading.
For GPS you could mention driving instructions, aircraft location, height measurement, or walking
instructions. This would work best with a mapping tool. (1 mark) How to use the GPS should be brief, e.g.
driving instruction may just give distance to destination “as the crow flies”.
2. What are the advantages and disadvantages of developing an app in the ionic development environment
over Java (Android) or Objective-C/Swift (iOS)?
Advantages (2 marks):
- Target multi-OS for same source code
- Easier to program
- Re-use web skills
Disadvantages (2 marks)
- Apps larger and slower
- Multiple API’s involved (Typescript, Angualar, Ionic, other Web APIs)
- Lack of support from OS developers (Google, Apple)
3. The following is a JavaScript function header:
function getData(name, studentID) {
… return “”+name+”,”+e-mail; …. }
If the name is a string, the studentID is an integer, and the returned value is a string, how this would be
declared in Typescript to fully specify the types in the function header (Note that we have not always fully
specified function types in the unit).
function getData(name:string, studentID:number) : string
{ … }
Also, how a variable or parameter would be specified that could be assigned as the above functions of its
type.
let f: (n:string, id:number) => string;
Note that variable names can be anything you choose. Some variations in syntax would be fine as long as
you have the main elements (parameters and return types).
4. The following is a TypeScript interface definition:
interface Car {name: string; rego: number; colour?: string};
Which of the following objects is not a correct type? Why?
{name:”Mazda”}
{name:”Mazda”, rego:1234}
{name:”Mazda”, rego:1234, colour:”red”}
{name:”Mazda”, rego:1234, model:”RX-8”}
One mark each:
{name:”Mazda”} no – ‘rego’ is compulsory
{name:”Mazda”, rego:1234} yes
{name:”Mazda”, rego:1234, colour:”red”} yes
{name:”Mazda”, rego:1234, model:”RX-8”} no = ‘model’ not in def
5. What is an injectable service (dependency injection) in Angular? How is an injectable service managed in
a running multi-page app, when each page accesses the service?
(2 marks) – an injectable service is a component that runs independently of the other components. It is
accessed by calling methods on the object that represents the service. You could mention it is a class,
decorated with @Injectable() but not necessary.
(2 mark) – an injectable is managed by the ionic runtime. A component accesses it by declaring it in the
constructor parameters. You could mention it is started when the app starts, configured in the ngmodule
code (app.module.ts) but these are low level details.
6. What is the role of a template in angular? Explain two ways that the typescript code in an app interfaces
with the template.
(2 marks) A template is the HTML specification of the displayed area of a component. It could be a whole
page or part of a page.
(2 marks)
Describe 2 of:
- Interpolation {{xxx }} – display variable value in DOM
- attribute assignment [att]=’xxx’ – adding DOM element attribute to expression
- event handler (tap)=”f()” – assign DIOM event handler to function
- two-way assignment [(xxxx)] – set up two way assignment between DOM variable and component
variable
- *ngif=”xxxx” - only generate DOM if expressions true
- *ngFor=”xxx” – loop expression to generate list or other DOM elements
- *ngSwitch – generate DOM element based on switch values
The description is the main thing. If you said HTML instead of DOM then that is not correct (HTML
generates initial view but DOM maintains dynamic view).
7. The following is an example of an Angular widget definition:

name=”user”/>
From this definition explain:
a) What does this field look like and what does a user do with it?
This is a text field (1 mark).
b) How does the Angular component access the data entered by the user?
The component attribute “userID” has the current value in the text field (1 mark).
c) What is the ‘#userField’ used for and where is it used?
This is a name that is only available in the template code. It can be used anywhere in the template (1 mark).
d) What is the role of the ‘id=”field1”’ attribute?
This links the label to the text field so a user clicking on the label is the same as clicking on the text field (1
mark).
8. Suppose we have an array declared in an Angular component as follows:
name: string;
Using the *ngIf attribute, how would we code a paragraph in the template (using

tags) that displays
the following only if name is an empty string “”:
Name field must be filled.
Solution is:

Name field must be filled


Syntax error is OK but must have *ngIF as attribute with the expression and a paragraph tag (4 marks).
9. Suppose we implement a checkbox in an Angular template as follows:

name="like"/>
What needs to be declared in the component class? Write down the declaration.
(2 marks) We need to declare likeAngular
likeAngular: boolean
Suppose we wanted to use the state of the checkbox answer elsewhere in the template to display one of
the following messages:
User likes Angular: true
Or
User likes Angular: false
How would that be coded in the template?

User likes angular: {{likeAngular}}


You can use another tag, e.g.

, , etc. (2 marks)
10. What is the difference between the POST and GET message types in the HTTP protocol? In a REST
system, describe the different ways these message types can be interpreted.
(1 mark) POST is for sending new data to the server to be saved as a new object.
(1 mark) GET retrieves an object from the REST server
(1 mark) If an object already exists the server may allow updating the object or return an error.
(1 mark) GET may be used to retrieve a list of objects rather than a single one. The list can be a multi-object
message or a list or URLs that can be used then in separate GET requests.
11. Why are Observables more advanced parallel processing that Promises in JavaScript/Typescript
environments? Give an example of an application of Observable that could not easily be done using
Promises. (Answer in plain English would be easiest here but code is OK)
(2 marks) Observables provide processing for a stream of multiple events, whereas Promises only provide
processing provide a single event. Not required but Observables also have a large library of functions to
manipulate the stream of events.
(2 marks) There are many correct answers for the examples part. Many of the ionic native interfaces
provide Observables that could not be implemented easily as Promises. For example, the heading plugin,
the GPS plugin, battery status, etc. provide continuous update streams. The Observables were also used in
AJAX processing but we never explained how a stream of data could occur.
12. What is CORS (Cross Origin Resource Sharing)? How does it improve security?
(2 marks) CORS is to specify which sites a script, web page or other resources may be loaded from inside a
web page. It is usually relative to the source of the webpage loading the resources. A server specifies which
web page sources may access the resources on the server (web pages from same server or different server).
(2 marks) It improves security by preventing rogue code from injecting code which loads data from a server
without permission. In the client side, browsers always check with the server if their CORS implementation
allows access to the resource.
13. What attributes of a web page do the Content Security Policy (CSP) headers control?
CSP headers control what may be loaded into the Webpage from the client point of view and where they
may be loaded from (CORS is a Server implementation). (1 mark)
The attributes are (3 marks – 1 for each):
Scripts
HTML
Styles
Media resources such as images, video, sound.
Note that the first part is probably not answered separately but as a part of the description of the
attributes.
14. Explain the role of Cordova in an ionic app. In your answer describe the role of Cordova plugins.
(1 mark) Ionic native is the ionic typescript interface to mobile device hardware and software features. It is
a series of components, one for each feature. Each component interfaces with a JavaScript Cordova plugin.
(1 mark) Cordova manages separate platforms (IoS, android and others) so that the correct compatible
plugin is loaded for each platform.
(2 marks) A plugin is a module which provides the JavaScript interface to a mobile device hardware feature
or a software feature on the device.
15. Why do mobile apps usually require many pages? Describe the standard structure of ionic code used to
cater for multipage apps. (This is the source file and code structure)
(2 marks) Most mobile devices have small screens so the amount of information displayable does not fit on
one page.
(2 marks) Ionic arranges pages into separate source code directories with a Typescript file for the
component code, a html file for the template and a SCSS file for the styles to apply to the page. The pages
are usually managed by a separate component (e.g. tabs, sidemenu) or you can use the push and pop
operations to program your own page management.
For part two there are technical details you have answered with but if the English shows understanding of
the management that is fine.
16. Ionic components may be ‘declarative’ components, e.g. the Nav component and the NavPush
component. What does ‘declarative’ mean in respect to components? How are other (non-declarative)
components used in ionic apps?
(2 marks) Declarative components are specified as tags in the template.
(2 marks) Non-declarative components are injectable components that are specified as parameters in the
component constructor. The component calls methods on these injectables to do stuff.
17. The following is a button declaration in a template that launches another page.


a) What is the ”newpage” in the ionic code?
(1 mark) ‘newpage’ is a reference to an ionic component representing the page to be displayed.
b) What is “params” in ionic the code? It represents parameters but how are they structured and
passed to the new page?
(1 mark) ‘params’ is a JavaScript object contain the data that is the parameter to be passed. An
example would be fine here.
c) How does the new page retrieve parameters?
(1 mark) the new page uses the navParams injectable to retrieve the parameter using the
JavaScript attribute.
d) How does the user normally return to this page?
(1 mark) Use the pop operation. e.g. the button attribute.
If you knew the code then c,d and e could have been answered by code but this is not necessary.
18. A basic ionic list can be defined as follows:


{{ item }}


Where is this code placed?
(1 mark) This code is placed in the template where the list is to be displayed.
What other code needs to be implemented? State what needs to be defined and where it should appear.
(3 marks) ‘items’ need to be an array attribute of some type that can be displayed in the template.
The array can be an array of string, number, boolean but string is the most logical answer here. It cannot be
a more complex object or you will get [object Object] being displayed
19. Cordova implements the W3C Web Storage interface which is also implemented by most browsers (it
has an interface very similar to the ionic storage interface).
a) What main types of storage are provided?
(2 marks) Name value pairs in either sessional storage or local storage (persists between sessions).
This can be explained in more basic terms related to mobile devices but the above is the W3C Web Storage
terminology. For example, session storage is storage during one app execution (remember an app stays
executing when you switch between apps) and local storage is permanent file storage on a mobile device.
b) Can one page/app easily access another page/app’s storage? Why?
(2 marks) No. The storage area is separate sandboxes for each app that does not overlap between apps.
20. The following is ionic code to read a file.
filesystem.readAsText(this.filesystem.datadirectory,“mydata.dat”)
.then(
(txt) => { process(txt); },
(err) => { error(err); }
);
What does the readAsText() function return? What happens if the file does not exist?
The readAsText() function returns a Promise (1 mark). The Promise is a string representing the whole file if
the read is successful (1 mark).
(2 marks) if the read fails, the err object contains an error object with message and error codes. The code in
the braces next to it is executed.
21. What needs to be added or deleted from the study guide (Topics and Labs) to allow students to reach
the same Ionic level at the end of the unit? (You will receive 4 marks if you write anything here so do not
skip this)
Any answer is fine
Part B – Longer answer question (16 marks)
Read carefully the specification below. The remainder of this part of the exam refers to this mobile
application.
An app is required for parents to track their children. The app has the following features:
− There are two apps, the one that tracks (installed on the parent’s device) the one that is tracked
(installed on the child’s device)
− The app will send a message to the parent’s device every 30 minutes (configurable) showing the
location of the tracked mobile device.
− The parent can configure locations where the app will immediately send a message.
− The app will interface with a public mapping software to show a history of the mobile device’s
location on a map on the parent’s device.
− The app is configurable:
o Period for sending messages
o Locations that prompt immediate messages
o Alarms on both app (warning to child/parent)
− The app does not:
o have a channel for voice contact
o prevent uninstall operations on the child’s device (the parent will have last location)
o implement a configuration interface on the child’s app (it’s on the parent’s app)
(16 Marks) Consider all the privacy and security aspects of this system by explaining (4 marks each):
a. Who is responsible for the privacy and security of the app (which aspects are allocated to whom)?
b. How should transparency be applied (privacy policy, notice and consent)?
c. Are there data management issues? How should they be handled?
d. How should the security of data be handled?
Note that a. – d. overlap somewhat so it is OK to mix answering each part. There are also many approaches
for each of the issues above but you will only need to describe one valid one.
In answering this your will see that Topic 10 is divided into 4 main sections that correspond to each of the a.
– d. The additional section in the topic refers to specific applications (health, finance and children) that have
their own legislated requirements. In this case the child protection laws apply.
The marking for this has 4 marks for addressing each of the 4 main sections in Topic 12 but also the
additional section where it applies (child protect in this case). In marking for each section, half will be for
general understanding (so you can prepare before the exam!) and half will be for the specific application to
the case study.
In answering the four parts follows. Note that you could take a different approach and you may come up
with other ideas in the exam. The following is just example answers and optional answers.
a. A developer is morally and legally responsible for the privacy of app users. That applies to
employees as well as organisations. In this app the developer is responsible for ensuring the privacy
of the location information (both real time and stored information). This includes accessibility by
other apps and accessibly of data in transmission between the two apps above. It also applied to
any temporary location, e.g., a server could be used to store and forward the location information.
A developer, due to children being involved, is responsible for securing the child’s app so other
people cannot access or modify the private information. For example, the child’s app may need a
password to access its configuration and this needs to be implemented by the developer.
Physical security of the devices is not the developer’s concern, the users are responsible.
There are other things that optionally be listed here, e.g. strength of password (should the
programmer enforce this or leave it to user), should the programmer disable device location
services that are accessible by other apps (is that the user or the other app developer) or the
telephone network (is that the telephone network’s responsibility?), etc.
b. The privacy notice should only be accepted by the parent and it should be accepted for both apps in
this case. This is complicated because we have not specified the age of the child. Theoretically a
child under 15 cannot accept a notice. A child 15 to 18 may be consider able to accept their own
notice but, since this is an app tracking children, some sort of acknowledgement by a child over 15
would be advisable, even if not enforceable by law. This raises the question of when the child’s app
should be visible or hidden on their device.
If the app is hidden then the purpose of the app may be changed, allowing one adult to install the
app on another adult’s device without their knowledge. A solution could be to have periodic
messages appearing on the child’s device notifying them that some else has accepted the privacy
condition.
c. The general data management rule is that only enough data as necessary should be stored on a
device. The minimum amount in this example specification is that the recent locations of the child’s
device is stored on the parent’s device but not on the child’s device. The data should not be stored
on the child’s device or on a server, except perhaps in transit to the parent’s device.
The length of time to store the data has not been specified so a reasonable choice should be made
by the programmer. For example, the last 100 locations or perhaps the last week’s locations could
be chosen. You could also say that the user will be given the option.
d. Securing data is related to the previous points. Data should be encrypted as it passes between child
and parent’s apps. Data on the parent’s and child’s app should be kept in sandboxed storage only
accessible to the app. Any passwords (child or parent’s app) should be encrypted and stored on the
device. You should also ensure data is deleted when the app is deleted. You should also ensure all
the software components used in the app do not “leak” data to servers or other apps, i.e. there are
no security issues with the development software.

站长地图