0% found this document useful (0 votes)
43 views13 pages

2223 2 Sehh3165

The document describes a mobile app development exam question paper containing five questions related to mobile app development topics like listviews, spinners, activities and touch events. The questions test concepts like making keyboard disappear on button click, updating listviews, passing data between activities, and handling touch events for moving images.

Uploaded by

LL 3708
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views13 pages

2223 2 Sehh3165

The document describes a mobile app development exam question paper containing five questions related to mobile app development topics like listviews, spinners, activities and touch events. The questions test concepts like making keyboard disappear on button click, updating listviews, passing data between activities, and handling touch events for moving images.

Uploaded by

LL 3708
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

College of Professional and Continuing Education (CPCE), an affiliate of PolyU

THE HONG KONG POLYTECHNIC UNIVERSITY


HONG KONG COMMUNITY COLLEGE

Subject Title : Mobile Apps Development Subject Code : SEHH3165

Session : Semester Two, 2022/23 Time : 16:00 – 18:00

Date : 20 May 2023 Time Allowed : 2 Hours

Subject : Dr Hon-sun CHIU


Examiner(s) Dr Thomas LAM

This question paper has a total of THIRTEEN pages (including this covering page).

Instructions to Candidates:

1. Answer any FOUR out of the FIVE questions in the answer book provided. Each question
carries 25 marks. If you answer more than four questions, only the first four attempted
questions will be marked. Indicate in your answer book clearly which four questions you are
attempting.
2. Begin each question on a new page in the answer book provided.
3. Electronic calculators, including programmable calculators, may be used provided that the
calculators are battery powered, silent in operation, with neither printout nor graphic /
word display facilities and do not use dot-matrix technology in the main display. All
programmes stored in the calculator should have been cleared. Other electronic devices
with graphic / word-display facilities (such as databank watches) are not permitted.

Authorised Materials:
YES NO
CALCULATOR [✓] [ ]
(All programmes stored should be cleared.)
A4 REFERENCE PAPER [✓] [ ]
A

DO NOT TURN OVER THE PAGE UNTIL YOU ARE TOLD TO DO SO

Page 1 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Answer any FOUR out of the FIVE questions in the answer book provided. Each question
carries 25 marks. If you answer more than four questions, only the first four attempted
questions will be marked. Indicate in your answer book clearly which four questions you are
attempting.

Question 1

A mobile app is developed as follows with custom listview as shown in Figure 1.

EditText [ID: et_name]

Button [ID: btn_save]

ListView [ID: lv]

Figure 1. App Design

(a) Write TWO Java statements so that the keyboard disappears when the SAVE button is
clicked. (5 marks)

(b) Write ONE Java statement so that user input ‘New season’ is removed when SAVE button is
clicked. (2 marks)

(c) An object instance adapter is declared using custom MyListAdapter class which accepts 3
arguments, namely, context, array list of text information, and array list
of drawable.

Write ONE Java statement to inform adapter to update whenever there are changes in the
listview items (3 marks)

Page 2 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 1 (continued)

(d) Two arrays are declared below to provide adapter object instance in part (c). Briefly
explain why custom MyListAdapter class is designed to accept array list instead of array.
Write Java statements to convert s1 and c1 arrays into season and icon arraylist
respectively.

(10 marks)

(e) Two arrays are modified as follows. Briefly explain why there is an error when the app is
launched and suggest a solution to solve this error.

(5 marks)

Page 3 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 2

A mobile app is developed in Figure 2 with spinner showing a list of fruit.

Figure 2. A mobile app with spinner

(a) The following program is used to initialize ‘spinner’ in mobile application:

An error appears at line 12 when the following is typed:

‘implements AdapterView.OnItemSelectedListener’

Briefly explain the reason for the error and suggest a solution to solve it. (5 marks)

(b) Suppose a correct solution is provided in part (a), errors are underlined in line 14, 15 and 19.
Briefly explain the reason behind the errors and provide corresponding solutions. (5 marks)

(c) Suppose ArrayAdapter adapter and Spinner spin are object variables to link the
array fruit object to xml spinner view (id = ‘spinner’) within onCreate function.
The fruit array contains six elements, namely, Apple, Banana, Lemon, Orange,
Strawberry and Melon. Write ONE Java statement to initialize fruit array. (5 marks)

(d) Refer to (c), write Java statements to initialize spinner and adapter so that (i) fruit list appears
and (ii) spinner can detect item tap when the app is run. (10 marks)

Page 4 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 3

A mobile app is developed in Figure 3a with two screens using two activities.

1st screen 2nd screen

TextView
id = tv_click_me
text = “Click Me!”

Activity MainActivity2.Java MainActivity.Java


Layout activity_main.xml activity_main2.xml
Figure 3a. Mobile app using two activities

Figure 3b shows the steps to add MainActivity: Right-click packet name ➔ New ➔ Java
Class

Figure 3b

Figure 3c shows the steps to add activity_main2.xml: Right-click layout ➔ New ➔ XML
➔ Layout XML file

Figure 3c. Steps to add activity_main2.xml

Page 5 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 3 (continued)

The mobile app does not have any errors when it is launched. However, when TextView is
clicked to show the 2nd activity (2nd screen), the following error appears when the app is
running.

(a) Briefly explain the cause of the error. (5 marks)

(b) Suggest a solution to solve the error mentioned in (a). (5 marks)

(c) TextView id ‘tv_click_me’ is modified directly in Code screen of design editor as


shown below:

However, when the following statement is typed at activity Java, it is underlined with error.

Briefly explain the cause of the error and suggest a solution for it. (5 marks)

(d) Given the following TextView, write the Java statements for TextView so that the 2nd
screen (activity) will be displayed when the TextView is clicked.

(10 marks)

Page 6 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 4

A mobile app is developed in Figure 4a using OnTouch event. The buttons are used to control the
movement of the ball in the screen.

Background:
TextView [ID: tv_xy]
• Relative
Layout
• [ID: RL]
Screen size:
• Width:1080dp
• Height:1850dp ImageView [ID: iv_ball]
Size = 150dp x 150dp

ID: ib_n

Image ID: ib_nw ID: ib_ne


Buttons
direction

ID: ib_e
ID: ib_w

ID: ib_star

ID: ib_sw
ID: ib_se

ID: ib_s

Figure 4a Mobile app using OnTouch event

(a) What is the abstract class needed to enable OnTouch feature to the activity? (2 marks)

Page 7 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 4 (continued)

(b) Suppose each directional image button, when on touch, moves the ball around as indicated in
Table 1.

Image button Direction and distance


ib_n North 10dp
ib_e East 10dp
ib_s South 10dp
ib_w West 10dp
ib_ne North 10dp and East 10dp
ib_se South 10dp and East 10dp
ib_sw South 10dp and West 10dp
ib_nw North 10dp and West 10dp
Table 1. Movement when buttons are on touch

Write Java statements for iv_ball movement when ib_e is touched (action down), such
that the coordinates are shown in tv_xy (as shown in Figure 4b). Make sure that the ball will
not go beyond the screen. (5 marks)

Figure 4b. iv_ball movement when ib_e is touched

Page 8 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 4 (continued)

(c) Similar to (b), write Java statements for iv_ball movement when ib_nw is touched (action
down), such that the coordinates are shown in tv_xy (as shown in Figure 4c). Make sure that
the ball will not go beyond the screen. (5 marks)

Figure 4c. iv_ball movement when ib_nw is touched

(d) Suppose an integer variable no_of_star_btn_touch (initial value = 0) is used in activity


class to count the number of touches (action down) on ib_star. The value is displayed via
tv_xy as shown in Figure 4d. Write Java statements for such counting and displaying.
(3 marks)

Figure 4d. Mobile app scrreen when ib_star is touched

Page 9 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 4 (continued)

(e) Continued from (d), apart from incrementing no_of_star_btn_touch and showing its
value to tv_xy when ib_star is touched (action down), there are more operations to be
processed afterwards, as shown in Figure 4e, depends on whether the value of
no_of_star_btn_touch is odd or even.

Figure 4e. Action when the value of no_of_star_btn_touch is odd or even

- If the value of no_of_star_btn_touch is odd, then x and y coordinates of


iv_ball are saved to ball_info.xml file using the key/value pair, for example,
key: “xy_key” and string value: ”60.0,160.0” by shared preferences. Short toast
message appears on screen ‘X, Y coordinates are saved.’

- If the value of no_of_star_btn_touch is even, then the coordinates stored in


ball_info.xml is retrieved using shared preferences and short toast message
appears on screen ‘(60.0,160.0) coordinates are retrieved.’

Given the string variables and SharedPreferences sp below, write Java program to
implement the operations as mentioned above. (10 marks)

Page 10 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 5

A mobile app is developed to generate security code for ABC Bank. Figure 5a shows the layout
xml design.

Figure 5a. Layout xml design of a mobile app

Figures 5b and 5c shows the app screen when ‘GENERATE CODE’ is clicked,

1. ‘Progress’ is changed to ‘Code generation is in progress, please wait …’


2. Progress bar takes 1 second to increase from 0 to 100.
3. Star icon moves from left to right and back to the left in 1 second.
4. Six digits is shown after the above steps are completed.
5. ‘Code generation is in progress, please wait …’ is changed to ‘Code generation is
completed’.

Figure 5b. App screen changes when ‘GENERATE CODE’ is clicked (steps 1-3)
Page 11 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 5 (continued)

Figure 5c. App screen changes when the code is generated (steps 4-5)

(a) The program below shows MainActivity.Java with init_object() function


containing tv_code object initialization. Write the Java statements to initialize
tv_progress, progressBar, iv_star and btn_gen so that they link to
corresponding views in layout xml. Write the method for btn_gen so that it can
detect user click. (5 marks)

(b) Given the following sample Java Random class and statements to generate random
number. Write the Java statements for GenerateCode function so that it can generate a
6-digit code [range from 000000 – 999999] and show it to tv_code directly.
(5 marks)

Page 12 of 13
College of Professional and Continuing Education (CPCE), an affiliate of PolyU

Question 5 (continued)

// create instance of Random class


Random rand = new Random();
// Generate random integers in range 0 to 9999
int rand_digit = rand.nextInt(10000);

(c) Write the function MoveLeftRight to move star icon from left to right and then back to
the left in 1 second. (5 marks)

(d) Write the function setProgressValue to increase progress bar value from 0 to 100 in
1 second. Then it calls GenerateCode() in part (b) and shows "Code generation
is completed." in tv_progress. (5 marks)

(e) Write the Java statements to call the animation function, trigger the progress bar and
update the display "Code generation is in progress, please wait ..."
when btn_gen is clicked. (5 marks)

- END OF PAPER -

Page 13 of 13

You might also like