22IIITCW011
22IIITCW011
Programme Board
Instructions:
(a) This paper has a total of THIRDTEEN pages
HIGHER DIPLOMA IN
including the covering page.
GAME SOFTWARE DEVELOPMENT
(b) This paper contains TWO Sections. (IT114107)
SEMESTER 2
MAIN EXAMINATION
11 MAY, 2023
1:30 PM TO 3:30 PM (2 hours)
© Vocational Training Council
© Vocational Training Council
A2 Implement with the following Java and Kotlin code skeleton to create and
display an AlertDialog box with the title “Examination Reminder” with the
content “The examination is going to start tomorrow” with an “OK” button.
You may answer in either Java or Kotlin.
// Java code skeleton begin
private void createReminderDialogBox() {
AlertDialog.Builder adRM = new _(i)__ (this);
adRM. _(ii)__ (R.drawable.android);
adRM. _(iii)__ (false);
adRM. _(iv)__ ("Examination Reminder");
adRM. _(v)__ ("The examination is going to start tomorrow.");
adRM. _(vi)__ ("OK", new DialogInterface. _(vii)__ () {
@Override
public void onClick (DialogInterface dialog, int which) {
AlertDialogDemoActivity.this. _(viii)__;
});
});
adRM. _(xi)__;
adRM. _(x)__;
}
// Java code skeleton end [10 marks]
A3 Implement with the following Java and Kotlin code skeleton based on the logic
below:
(I) If the value x is 70+, show a Toast message with A.
(II) If the value x is 60-69, show a Toast message with B.
(III) If the value x is 50-59, show a Toast message with C.
(IV) If the value x is 40-49, show a Toast message with D.
(V) In any case for the value x lower than 40, show a Toast message with
F.
Value is declared in Integer. You may answer in either Java or Kotlin.
// Java code skeleton begin
private void exam(int x) {
//_(code block to be completed)__
}
// Java code skeleton end
// Kotlin code skeleton begin
private fun exam(x: Int) {
//_(code block to be completed)__
}
// Kotlin code skeleton end
A4 Implement with the following Java and Kotlin code skeleton to:
(I) A SharedPreferences named et store the shared preferences in the app.
(II) Retrieve the SharedStringPreferences named time and store in a
String variable named t while the app restores to the main display. The
default value is “” if there is no record.
(III) Store the value from the variable t to the ShareStringPreferences
named time while the app goes off-screen.
B1 (a) Suppose the following Sprite class contains one bitmap for one object (without using
Sprite Sheet) and the origin of sprite are set at the centre position.
/**
* Sprite Class in Java
**/
public class Sprite {
private int x, y, spriteWidth, spriteHeight, vSpeed, hSpeed;
private Bitmap bitmap;
private Paint paint;
private boolean isTouched;
/**
* Sprite Class in Kotlin
**/
open class Sprite {
var x: Int
var y: Int
var spriteWidth: Int
var spriteHeight: Int
var vSpeed: Int
var hSpeed: Int
private var bitmap: Bitmap
var paint: Paint
var isTouched = false
/**
* MainGamePanel Class in Java
**/
public class MainGamePanel extends SurfaceView implements
SurfaceHolder.Callback {
private MainThread thread;
Sprite sprite;
public MainGamePanel(Context context) {
super(context);
getHolder().addCallback(this);
thread = new MainThread(getHolder(), this);
setFocusable(true);
}
public void surfaceChanged( // …Implementation not shown
public void surfaceCreated( // …Implementation not shown
public void surfaceDestroyed( // …Implementation not shown
@Override
public boolean onTouchEvent(MotionEvent event) {
// TO BE COMPLETED in B1(b)(ii)
return true;
}
/**
* MainGamePanel Class in Kotlin
**/
class MainGamePanel : SurfaceView, SurfaceHolder.Callback {
private var thread: MainThread
private lateinit var sprite: Sprite
@+id/btnRandom
@+id/tvCity
@+id/tvName
@+id/tvLocation
@+id/imgPhoto
// In Java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// TO BE COMPLETED in B2(a)
}
// In Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// TO BE COMPLETED in B2(a)
}
[3 marks]
(B2 CONTINUES IN NEXT PAGE)
(b) While the user clicks on the “Random” button, the program calls the method
requestWebAPI() with a random number. The requestWebAPI() method request
the API and wait for the response data in JSON format. The sample JSON content of
the response is shown as follow:
{
"stadium": {
"id": 4,
"n": "Kaliningrad Stadium",
"c": "Kaliningrad",
"location: {
"lat": 54.698157,
"lng": 20.533859
}
"img": "https://upload.wiki.org/wikipedia/com/a/a4/_2018-04-07.jpg"
}
}
Implement the following Java or Kotlin code block to display the text
data only to the designated TextViews defined at the beginning of B2.
// In Java
String responseString = responseTextFromAPI;
// TO BE COMPLETED in B2(b)
// In Kotlin
val responseString = responseTextFromAPI
// TO BE COMPLETED in B2(b)
[12 marks]
(c) In the JSON response, there is a URI which points to the Internet resource (image). A
thread is required to retrieve the data and display at the ImageView. Implement the
following Java or Kotlin code block with the Executor and display the image to the
ImageView (imgStadium).
Hints:
1. You need to apply the decodeStream() in BitmapFactory class to decode the
image from the Internet.
2. You need to apply setImageBitmap() in ImageView to read the decoded
Bitmap image.
// In Java
ExercutorService imgThreadPool = new Executors.newFixedThreadPool(1);
imgThreadPool.execute(new Runnable() {
@Override
public void run(){
try {
URL url = new URL(_(i)_);
url. _(ii)_;
Bitmap image = BitmapFactory. _(iii)_;
runOnUiThread(() -> imgStadium. _(iv)_ (image));
} catch (_(v)_ e) {
e.printStackTrace();
}
}
}
// In Kotlin
val imgThreadPool: ExecutorService = Executors.newFixedThreadPool(1)
val json = JSONObject(r)
imgThreadPool.execute {
try {
val url = URL(_(i)_). _(ii)_
val image = BitmapFactory. _(iii)_
runOnUiThread {
imgStadium. _(iv)_ (image)
}
} catch (e: _(v)_) {
e.printStackTrace()
}
[15 marks]