Test2 DDWD2713
Test2 DDWD2713
Pendidikan Berterusan
(UTMSPACE)
TEST 2
SEMESTER II – SESSION 2021 / 2022
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 )
STUDENT’S SECTION
SEKSYEN : ………………………………………………………………………………
LECTURER’S NAME
NAMA PENSYARAH
: ………………………………………………………………………………
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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]
4.The callback function that is called when activity interaction with user is started
A. onStart
B. onStop
C. onResume
D. onDestroy
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();
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>
D. <string>
<name>days</name>
<item>Sunday</item>
<item>Monday</item>
<item>Tuesday</item>
</string>
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
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;
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;
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");
totalmarkED.setText(totalmark.toString());
String result;
if (totalmark >= 45)
result="PASSED";
else
result="FAILED";
}
});
return root;
}
}