0% found this document useful (0 votes)
56 views

Test2 DDWD2713

Here are the answers to fill in the blanks: 1. setContentView(R.layout.activity_login); 2. findViewById(R.id.button); 3. findViewById(R.id.editTextTextPersonName); 4. findViewById(R.id.editTextTextPassword); 5. findViewById(R.id.button2); 6. @Override 7. public void onClick(View view) { 8. if(usernameED.getText().toString().equals("admin")&& passwordED.getText().toString().equals("admin")) { 9. Toast.makeText(Login

Uploaded by

thisisnoobworld
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)
56 views

Test2 DDWD2713

Here are the answers to fill in the blanks: 1. setContentView(R.layout.activity_login); 2. findViewById(R.id.button); 3. findViewById(R.id.editTextTextPersonName); 4. findViewById(R.id.editTextTextPassword); 5. findViewById(R.id.button2); 6. @Override 7. public void onClick(View view) { 8. if(usernameED.getText().toString().equals("admin")&& passwordED.getText().toString().equals("admin")) { 9. Toast.makeText(Login

Uploaded by

thisisnoobworld
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/ 10

Sekolah Pendidikan Profesional dan

Pendidikan Berterusan
(UTMSPACE)

TEST 2
SEMESTER II – SESSION 2021 / 2022

COURSE CODE : DDWD 2713


KOD KURSUS

COURSE NAME : MOBILE PROGRAMMING / PENGATURCARAAN MUDAH ALIH

YEAR / PROGRAMME : 2DDWD


TAHUN / PROGRAM

DURATION : 1 HOUR AND 15 MINUTES


TEMPOH

DATE : APRIL 2022


TARIKH

INSTRUCTION :
ARAHAN
1. Answer ALL questions in the question paper.
Jawab SEMUA soalan dalam kertas soalan.

2. Candidates are required to follow all instructions given by the examination invigilators.
Calon dikehendaki mematuhi semua arahan daripada penyelia peperiksaan.

( You are required to write your name and your lecturer’s name on your answer script )
( Pelajar dikehendaki tuliskan nama dan nama pensyarah pada skrip jawapan )

NAME / NAMA PELAJAR : ………………………………………………………………………………

I.C NO. / NO. K/PENGENALAN : ………………………………………………………………………………


YEAR / COURSE
TAHUN / KURSUS
: ………………………………………………………………………………

STUDENT’S SECTION
SEKSYEN : ………………………………………………………………………………
LECTURER’S NAME
NAMA PENSYARAH
: ………………………………………………………………………………

This examination paper consists of 11 pages including the cover


Kertas soalan ini mengandungi 11 muka surat termasuk kulit hadapan
-3-
DDWC2713
Answering Sheet:

Sec A: Objective Question Answer (30M)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Sec B: Fill In The Blank Question Answer (15M)

No. Answer Mark

1 1M

2 1M

3 1M

4 1M

5 1M

6 2M

7 1M

8 1M

9 1M

10 1M

11 1M

12 1M

13 1M

14 1M
-4-
DDWC2713
Sec C: Content of fragment_home.xml (5M)
-5-
DDWC2713
SECTION A: OBJECTIVE QUESTIONS [30 MARKS]

1. What is the use of content provider in android?


A. To share the data between applications
B. To send the data from an application to another application
C. To store the data in a database
D. To provide content to activity

2. How to pass the data between activities in Android?


A. Broadcast Receiver
B. Content Provider
C. Services
D. Intent

3. Which of it is android activity life cycle?


A. onCreate() −> onStart() −> onActivityStarted() −> onResume() −> onPause() −> onStop() −>
onActivityDistroy() −> onDestroy()
B. onCreate() −> onStart() −>onResume() −> onPause() −> onStop() −> onRestart() −> onDestroy()
C. onCreate() −> onStart() −> onPause() −> onResume() −> onStop() −> onDestroy()
D. onResume()

4.The callback function that is called when activity interaction with user is started
A. onStart
B. onStop
C. onResume
D. onDestroy

5. Each time new activity created, it must be defined in


A. res/layout
B. res/values
C. Build.gradle
D. AndroidManifest.xml

6. Button option can be choose from the palette category


A. textfields
B. containers
C. widgets
D. layouts

7. The tab in android studio which error is shown is called


A. logcat
B. memory
C. ADB logs
D. CPU
-6-
DDWC2713
8. Suppose that there are two activities in an application named ActivityOne and ActivityTwo. You want to
invoke ActivityTwo from ActivityOne. What code you will write?
A. Intent intent=new Intent (this, ActivityTwo.class);
startActivity(intent);
B. startActivity(new Intent(this, ActivityTwo.class));
C. Option A and B are correct.
D. None of the above.

9. What is the permission for using the camera?


A. android.permission.hardware.CAMERA
B.android.permission.USE_CAMERA
C.android.uses.permission.CAMERA
D.android.permission.CAMERA

10. When the data being passed from firstActivity to secondActivity. How will you get that data in
secondActivity?
A. Intent intent=new Intent;
String str= intent.getStringExtra("name");
Toast.makeText(this, str , Toast.LENGTH_LONG).show();

B. Intent intent=getIntent();
String str= intent.getStringExtra("name");
Toast.makeText(this, str , Toast.LENGTH_LONG).show();

C. Intent intent=getIntent();
String str= intent.getText("name");
Toast.makeText(this, str , Toast.LENGTH_LONG).show();

D. None of the above.

11. What is the default layout in android application?


A. RelativeLayout
B. ConstraintLayout
C. LinearLayout
D. FrameLayout

12.What code you will write to create an array in strings.xml fi le located in the res/values folder?
A. <string name=”days”>
<item>Sunday</item>
<item>Monday</item>
<item>Tuesday</item>
</string>
-7-
DDWC2713
B. <string-array name=”days”>
<item>Sunday</item>
<item>Monday</item>
<item>Tuesday</item>
</string-array>

C. <string-arr size [3] name=”days”>


<item>Sunday</item>
<item>Monday</item>
<item>Tuesday</item>
</string>

D. <string>
<name>days</name>
<item>Sunday</item>
<item>Monday</item>
<item>Tuesday</item>
</string>

13 Which of the following is NOT a valid usage for Intents?


A. Activate an Activity
B. Activate a Service
C. Activate a Broadcast receiver
D. Activate a SQLite DB Connection

14. Whichof the following is not a valid Android resource filename?


A. my_layout.xml
B. mylayout.xml
C. myLayout.xml
D. mylayout1.xml

15. To change the font size of a text in Android layout, you should use attribute “android:textSize”. Which of
the following choices is the recommended syntax to change the font size to 18?
A. android:textSize="18sp"
B. android:textSize="18dp"
C. android:textSize="18point"
D. android:textSize="18sd"
-8-
DDWC2713
SECTION B: FILL IN THE BLANK QUESTIONS [20 MARKS]

Below is the structure of the myTest project in android studio. You need to fill the blank with the write
code.

Username: admin
Password: admin

DISPLAY RESULT DISPLAY RESULT


-9-
DDWC2713
Inside LoginActivity.java
package com.example.mytest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {

Button loginBtn,cancelBtn;
EditText usernameED,passwordED;

TextView attemptTV;
int counter = 3;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//write the coding to set content login activity layout here –no 1 answer 1M

loginBtn = //write the coding to synchronize object in xml and java for login button here –no 2 answer 1M
usernameED = //write the coding to synchronize object in xml and java for username edittext here –no 3 answer 1M
passwordED = //write the coding to synchronize object in xml and java for password edittext here –no 4 answer 1M

cancelBtn = //write the coding to synchronize object in xml and java for cancel button here –no 5 answer 1M
attemptTV = (TextView)findViewById(R.id.textView3);
attemptTV.setVisibility(View.GONE);

loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(usernameED.getText().toString().equals("admin") &&
passwordED.getText().toString().equals("admin")) {
//write the coding to navigate from LoginAcivity to MainActivity here –no 6 answer 2M

finish();
}else{
Toast.makeText(getApplicationContext(), "Wrong Credentials",Toast.LENGTH_SHORT).show();
attemptTV.setVisibility(View.VISIBLE);
attemptTV.setBackgroundColor(Color.RED);
counter--;
attemptTV.setText(Integer.toString(counter));

if (counter == 0) {
loginBtn.setEnabled(false);
}
}
}
});

cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
- 10 -
DDWC2713
Inside activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools = "http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height = "match_parent"
android:paddingLeft= "16dp"
android:paddingRight = "16dp"
android:paddingTop = "16dp" <TextView
android:paddingBottom = "16dp" android:layout_width="wrap_content"
tools:context = ".LoginActivity"> android:layout_height="wrap_content"
android:text="Attempts Left:"
<TextView android:text = "Login" android:id="@+id/textView2"
android:layout_width="wrap_content" android:layout_below="@+id/passwordED"
android:layout_height = "wrap_content" android:layout_alignParentLeft="true"
android:id = "@+id/textview" android:layout_alignParentStart="true"
android:textSize = "35dp" android:textSize="25dp" />
android:layout_alignParentTop = "true"
android:layout_centerHorizontal = "true" /> <TextView
android:layout_width="wrap_content"
<TextView android:layout_height="wrap_content"
android:id="@+id/textView1" android:text="New Text"
android:layout_width="wrap_content" android:id="@+id/textView3"
android:layout_height="wrap_content" android:layout_alignTop="@+id/textView2"
android:layout_below="@+id/textview" android:layout_alignParentRight="true"
android:layout_centerHorizontal="true" android:layout_alignParentEnd="true"
android:text="TEST 2 DDWC2713" android:layout_alignBottom="@+id/textView2"
android:textColor="#ff7aff24" android:layout_toEndOf="@+id/textview"
android:textSize="35dp" /> android:textSize="25dp"
android:layout_toRightOf="@+id/textview" />
<EditText
android:layout_width = "wrap_content" <Button
android:layout_height = "wrap_content" android:layout_width="wrap_content"
android:id = "@+id/usernameED" android:layout_height="wrap_content"
android:hint = "Enter Name" android:text="login"
android:focusable = "true" android:id="@+id/loginBtn"
android:textColorHighlight = "#ff7eff15" android:layout_alignParentBottom="true"
android:textColorHint = "#ffff25e6" android:layout_toLeftOf="@+id/textview"
android:layout_marginTop = "46dp" android:layout_toStartOf="@+id/textview" />
android:layout_below = "@+id/imageView"
android:layout_alignParentLeft = "true" <Button
android:layout_alignParentStart = "true" android:layout_width="wrap_content"
android:layout_alignParentRight = "true" android:layout_height="wrap_content"
android:layout_alignParentEnd = "true" /> android:text="Cancel"
android:id="@+id/cancelBtn"
<ImageView android:layout_alignParentBottom="true"
android:layout_width="wrap_content" android:layout_toRightOf="@+id/textview"
android:layout_height="wrap_content" android:layout_toEndOf="@+id/textview" />
android:id="@+id/imageView"
android:src="@drawable/utm" </RelativeLayout>
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/passwordED"
android:layout_below="@+id/usernameED"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/usernameED"
android:layout_alignEnd="@+id/usernameED"
android:textColorHint="#ffff299f"
android:hint="Password" />
- 11 -
DDWC2713
Inside HomeFragment.java
package com.example.mytest;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

public class HomeFragment extends Fragment {

public View onCreateView(@NonNull LayoutInflater inflater,


ViewGroup container, Bundle savedInstanceState) {
//write the coding to set content home fragment layout here –no 7 answer 1M

EditText carrymarkED = __________ no 8 answer 1M __________(R.id.carryMarkED);


EditText finalmarkED = __________ no 9 answer 1M ___________(R.id.finalMarkED);
EditText totalmarkED = __________ no 10 answer 1M __________(R.id.totalMarkED);
Button processBtn = __________ no 11 answer 1M __________(R.id.processBtn);

processBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((carrymarkED.getText().equals(""))||(Double.parseDouble(carrymarkED.getText().toString())>50))
carrymarkED.setText("0.0");

if((carrymarkED.getText().equals(""))||(Double.parseDouble(carrymarkED.getText().toString())>50))
carrymarkED.setText("0.0");

double carrymark = __________ no 12 answer 1M __________


double finalmark = __________ no 13 answer 1M __________
double totalmark = carrymark+finalmark;

totalmarkED.setText(totalmark.toString());
String result;
if (totalmark >= 45)
result="PASSED";
else
result="FAILED";

//Displaying Toast with result value - no 14 answer 1M

}
});

return root;
}
}

Write the possible code inside fragment_home.xml (5M)


(Tips: use linearLayout or tableLayout or both of it)

You might also like