0% found this document useful (0 votes)
63 views17 pages

MT201 Examination 2021 Answer

The document is an exam answer booklet for a Mobile Application Development module. It contains instructions for candidates and 10 questions worth a total of 100 marks. Question 1 asks students to develop the XML code for a simple calculator app layout with input fields and a button. It also asks students to get references to the UI elements in the activity's onCreate method and implement an onclick listener for a button. Section B contains 3 questions asking students to define different mobile app development approaches, differentiate explicit and implicit intents, and explain layout attributes like id, @ and +.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views17 pages

MT201 Examination 2021 Answer

The document is an exam answer booklet for a Mobile Application Development module. It contains instructions for candidates and 10 questions worth a total of 100 marks. Question 1 asks students to develop the XML code for a simple calculator app layout with input fields and a button. It also asks students to get references to the UI elements in the activity's onCreate method and implement an onclick listener for a button. Section B contains 3 questions asking students to define different mobile app development approaches, differentiate explicit and implicit intents, and explain layout attributes like id, @ and +.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

School of Computing and Information Systems

BSC (HONS) MTECH, CSE

MT 201 – MOBILE APPLICATION DEVELOPMENT Year 2 Semester1

Open Book Final Examination Answer Booklet


Date: 18 November 2021 Time: 14:00-18:00hrs
Total Marks: 100 Duration: 4 hrs

Instructions to candidates

CANDIDATE NUMBER: FCSE20-015

CANDIDATE NAMES: BOFELO


MAGOSI

CONTACT NUMBER: 75708202

PROGRAMME: MAD

MODULE LEADER: [email protected]

EXAMINATION DATE: 18.Nov.2021

This marking guide consists of ten (10) printed pages excluding this cover page

Section A – Answer All questions in this section

Question 1
Scenario
A simple Mathematical Calculator is used to make simple mathematical calculations. You
are required to build a Simple Calculator App for making some mathematical calculations.
Use the figure below for guidance on building the layout of the Calculator App.

Figure 1: Calculator App Project

Develop a mobile code for this application following the guidelines below;

a) Create the XML code that contains the main layout of the calculator APP with just one
(1) button and the input text field. [12 marks]
Answer Mark
Awarded

Page 1 of 18
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android "
    xmlns:app="http://schemas.android.com/apk/res-auto "
    xmlns:tools="http://schemas.android.com/tools "
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#8BC34A"
    android:backgroundTint="@android:color/darker_gray"
    tools:context=".MainActivity">
 
    <!-- Text View to display our basic heading of "calculator"-->
    <TextView
        android:layout_width="194dp"
        android:layout_height="43dp"
        android:layout_marginStart="124dp"
        android:layout_marginLeft="124dp"
        android:layout_marginTop="60dp"
        android:layout_marginEnd="107dp"
        android:layout_marginRight="107dp"
        android:layout_marginBottom="500dp"
        android:scrollbarSize="30dp"
        android:text=" Calculator"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        android:textSize="30dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
 
    <!-- Edit Text View to input the values -->
    <EditText
        android:id="@+id/num1"
        android:layout_width="364dp"
        android:layout_height="28dp"
        android:layout_marginStart="72dp"
        android:layout_marginTop="70dp"
        android:layout_marginEnd="71dp"
        android:layout_marginBottom="416dp"
        android:background="@android:color/white"
        android:ems="10"
        android:hint="Number1(0)"
        android:inputType="number"
        app:layout_constraintBottom_toBottomOf="parent"

Page 2 of 18
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
 
    <!-- Edit Text View to input 2nd value-->
    <EditText
        android:id="@+id/num2"
        android:layout_width="363dp"
        android:layout_height="30dp"
        android:layout_marginStart="72dp"
        android:layout_marginTop="112dp"
        android:layout_marginEnd="71dp"
        android:layout_marginBottom="374dp"
        android:background="@android:color/white"
        android:ems="10"
        android:hint="number2(0)"
        android:inputType="number"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
 
    <!-- Text View to display result -->
    <TextView
        android:id="@+id/result"
        android:layout_width="356dp"
        android:layout_height="71dp"
        android:layout_marginStart="41dp"
        android:layout_marginTop="151dp"
        android:layout_marginEnd="48dp"
        android:layout_marginBottom="287dp"
        android:background="@android:color/white"
        android:text="result"
        android:textColorLink="#673AB7"
        android:textSize="25sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
 
    <!-- A button to perform 'sum' operation -->
    <Button
        android:id="@+id/sum"
        android:layout_width="wrap_content"

Page 3 of 18
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="292dp"
        android:layout_marginEnd="307dp"
        android:layout_marginBottom="263dp"
        android:backgroundTint="@android:color/holo_red_light"
        android:onClick="doSum"
        android:text="+"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

b) Get handle to components in onCreate() for the four (4) buttons (add, divide, subtract,
multiply, as well as the input field. [5 marks]
Answer Mark
Awarded
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// for text views


no1 = findViewById(R.id.first_no);
no2 = findViewById(R.id.second_no);

// for button with operations


add = findViewById(R.id.add);
mul = findViewById(R.id.mul);
div = findViewById(R.id.div);
sub = findViewById(R.id.sub);

Page 4 of 18
c) Implement the Calculator setOnClickListener method to set the input text to 7 when the
user presses the button number 7 on the calculator.
[8 marks]

Answer Mark
Awarded
@Override
public void onClick(View v) {

int value = v.getId();

if (value == R.id.button7) {
InputText.setText("7");
}
}

Total Marks [25]

Section B - Answer any 3 questions in this section

Question 2

a) Define the following mobile ecosystem components which are native, hybrid and html 5. 3
marks each component definition [9 marks]
Answer Mark
Awarded
1.NATIVE - This is to create a mobile application exclusively for one platform. The app is
built with specific programming languages and tools for a single platform. For example, you
can develop a native Android app with Java or Kotlin and choose Swift and ObjectiveC for
iOS apps.
2.HYBRID is a mobile programming approach that combines the strengths of native
programming and HTML5 mobile application development. To create a hybrid mobile app,
developers write the core of the app as an HTML5 mobile app and then insert a native
device wrapper into it.

3.HTML5 HTML5 offers a host of new features such as advanced video and audio
streaming capabilities as well as integration. HTML5 mobile app development can easily
scale to different resolutions, device screen sizes, aspect ratios, and guidelines.

Page 5 of 18
b) Differentiate between an explicit and implicit intents [ 6 marks]
Answer Mark
Awarded

The explicit intent can perform the application-specific action defined by the code, such as
modifying the task, downloading the file in the background, while the implicit intent
specifies the only action to be performed and does not directly specify Android components.

c) Study the layout attributes given below:


android: id="@+id/ my_button"
i. Explain what each of the following means: id, @ and + [6 marks]
Answer Mark
Awarded
1. @ indicates that the XML parser should parse and expand the rest of the ID string and
identify it as an ID resource.

2. + means this is a new resource name that needs to be created and added to our resources
(in the R.java file).

3.id Unique resource name for the item, which you can use to get a view reference from
your application.

d) With an aid of code example, Explain type-casting in Android


[4 marks]

Answer Mark
Awarded
Type casting is the process of converting the data type of the result of any operation
to another data type.
Example;
#include<stdio.h>

Page 6 of 18
#include<conio.h>
void main()
{
float i=3.54;
int p;
p = (int) i;
printf("Explicit value is %d",p);
getch();
}

Output is 3

Total Marks [25]

Question 3
a) With an aid of code example, Explain the difference between a void method and a value-
returning method? [8 marks]

Answer Mark
Awarded
A void method is a method that simply executes a task and then exits. A method that returns
a value not only performs a task, but also returns a value to the code that called it.

An example of a method that returns a value: A method that returns a value not only
performs a task, but also returns a value to the code that called it.
For example:
public Bicycle seeWhosFastest(Bicycle myBike, Bicycle yourBike,
Environment env) {
Bicycle fastest;
// code to calculate which bike is
// faster, given each bike's gear
// and cadence and given the
// environment (terrain and wind)
return fastest;
}

Page 7 of 18
Void method: This simply performs a task and then terminate.A method which does
not return any value. Call to a void method must be a statement i.e.
methodRankPoints(255.7);. It is a Java statement which ends with a semicolon as
shown in the following example.

public static void main(String[] args) {


methodRankPoints(255.7);
}

public static void methodRankPoints(double points) {


if (points >= 202.5) {
System.out.println("Rank:A1");
}else if (points >= 122.4) {
System.out.println("Rank:A2");
}else {
System.out.println("Rank:A3");
}
}
}

b) List the components of the Android stack Architecture. [8 marks]

Answer Mark
Awarded

Linux kernel
Libraries
Android Libraries
Android Runtime
Application Framework
Applications
Broadcast Receivers
Activities

c) State and explain 3 ways of handling user interaction within android application
[3 marks]

Page 8 of 18
Answer Mark
Awarded
Event handlers
Event handlers are the actual methods that have the action to take. After an event has
occurred and the event listeners have been registered, the event listeners call the event
handler. These are useful for defining certain callback methods.

Event listener
An event listener is an interface in the Android View class. It has only one callback
method. This method will be called when the view saved with the listener is triggered by
user action.

Event Listener Registration

Event registration is the process in which event listeners are registered with event handlers.
This is important because the handler will not work until the listener triggers an event.

d) Show a code implementation of a service and activity in android programming


[4 marks]

Answer Mark
Awarded
public class MyService extends Service {
private MediaPlayer player;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "Service was Created", Toast.LENGTH_LONG).show();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
player = MediaPlayer.create(this,
Settings.System.DEFAULT_RINGTONE_URI);
// This will play the ringtone continuously until we stop the service.
player.setLooping(true);
// It will start the player
player.start();
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;

Page 9 of 18
}
@Override
public void onDestroy() {
super.onDestroy();
// Stopping the player when service is destroyed
player.stop();
Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="startService"
android:layout_marginLeft="130dp"
android:layout_marginTop="150dp"
android:text="Start Service"/>
<Button
android:id="@+id/btnstop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="stopService"
android:layout_marginLeft="130dp"
android:layout_marginTop="20dp"
android:text="Stop Service"/>
</LinearLayout>

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// Start the service
public void startService(View view) {
startService(new Intent(this, MyService.class));
}
// Stop the service
public void stopService(View view) {
stopService(new Intent(this, MyService.class));
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tutlane.services">

Page 10 of 18
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MyService" />
</application>
</manifest>

e) List the two (2) main IDE options for building android mobile applications.

[2 marks]

Answer Mark
Awarded

 Eclipse

 Android Studio

Total Marks [25]

Page 11 of 18
Question 4
a) Consider the following mobile application and write down the layout code for it using the
Relative Layout. [9 marks]

Answer Mark
Awarded

b) Explain the following Android Project Structure [6 Marks]

I. app/src/main/java 
Answer Mark
Awarded

II. app/src/test/java 
Answer Mark
Awarded

III. app/src/androidTest/java 

Page 12 of 18
Answer Mark
Awarded

c) Write a basic android code that implements an intent [3 Marks]

Answer Mark
Awarded

d) State and explain any Three (3) benefits of using native mobile language
[3 Marks]

Answer Mark
Awarded

e) State and explain any Four (4) benefits of using native mobile language
[4 Marks]

Answer Mark
Awarded

Page 13 of 18
Total Marks [25]

Question 5
a) List and explain fully the 3 key loops of an activity life cycle [9 marks]
Answer Mark
Awarded
onStop ()
When your activity is no longer visible to the user, it goes into a Stopped state and the
system calls the onStop () callback. This can happen, for example, when a newly started
task covers the entire screen. The system can also call onStop () when the task is complete
and is about to complete.

onStart ()
When the task enters the Started state, the system calls this callback. Calling
onStart () makes the activity visible to the user, while the application prepares for
the activity to be highlighted and become interactive. For example, this method is
where the application initializes the code that handles the user interface.

onPause ()
The system calls this method as the first indication that the user is leaving your company
(although this does not always mean that the company is destroyed); indicates that the
activity is no longer in the foreground (although it may still be visible if the user is in multi-
window mode). Use the onPause () method to pause or adjust operations that should not
continue (or should continue in moderation) while the activity is paused and should resume
soon

b) With an aid of code example, Explain what an android toast is [4 Marks]


Answer Mark
Awarded
An Android Toast is a small message displayed on the screen, similar to a tip or other
similar pop-up notification. A toast appears above the main content of an activity and only
remains visible for a short time.

Page 14 of 18
Toast.makeText(getActivity(), "This is my Toast message!",
Toast.LENGTH_LONG).show();

c) List the six (6) different states that a java thread could reach during its life-cycle.
[6 marks]

Answer Mark
Awarded
Blocked
New
Runnable
Terminated
Waiting
Time Waiting

d) State and explain any three (3) types of Android menus. [6 Marks]

Answer Mark
Awarded
Popup Menu
A popup menu is a type of menu that displays items in a vertical list. This list is
attached to the view on which the user clicked to bring up this menu. It's important
to keep in mind that when choosing a context menu, you don't want the user's
choice to affect previous content pressed by the user.

Options menu
This menu is usually located at the top of the application and you must enter actions that
affect the application as a whole. It can be application settings or a search field.

Contextual menu

Page 15 of 18
This menu is displayed when a user makes a long click on one of the elements of the user
interface. The options in this menu affect the user interface element that the user clicked. It
is common to use this type of menu in list or grid views, where user interaction with each
item can lead to a specific action.

Total Marks [25]

End of Exam

Page 16 of 18

You might also like