2223 2 Sehh3165
2223 2 Sehh3165
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
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) 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
‘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.
TextView
id = tv_click_me
text = “Click Me!”
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
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.
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
ID: ib_e
ID: ib_w
ID: ib_star
ID: ib_sw
ID: ib_se
ID: ib_s
(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.
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)
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)
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.
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.
Figures 5b and 5c shows the app screen when ‘GENERATE CODE’ is clicked,
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)
(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)
(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