Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 17

Bahria University, Islamabad Campus

Department of Software Engineering


Mid Term Examination
Class/Section: BSE-6
(Spring 2021 Semester)
Paper Type: Descriptive
Subject: Software Application for Mobile Devices Date: 19-05-2021
Course Code: (SEN-448) Session: I
Name of Faculty: Joddat Fatima Max Marks: 20
Time Allowed: 90 Minutes Total Pages: 5 (including this)

INSTRUCTIONS:
I. Write name and enrollment numbers on the question paper in the designated space only.
II. All questions are compulsory.
III. PLAGIARIZED/COPIED submissions will be considered as 0 marks and will be dealt with Academic
dishonesty/cheating policy of Examination.

Name: Abdul Rauf Enroll No: 01-131182-003

Q. No. 1 2 3
CLO 1 2 3
Total Marks 9 5 6

Marks Obtained

Q1. Answer the following Code Questions? CLO 1 9

a. Write the default constructors for implicit intent and explicit intent. You can use
Google webpage as a reference. Write the tag you have to declare in android manifest
file.

Explicit Intent:
Intent browserintent = new Intent(this, BrowserActivity.class);
startActivity(browserintent);

Implicit Intent:
Intent intent = new Intent(Intent. ACTION_VIEW,
Uri.parse(https://www.google.com));
startActivity(browserintent);

<Intent-filter> is the tag that we have to declare in manifest file. An intent filter is an
expression in an app's manifest file that specifies the type of intents that the component would
like to receive. For instance, by declaring an intent filter for an activity, you make it possible
for other apps to directly start your activity with a certain kind of intent

Page 1 of 17
%
Enrollment Number: ____________________________

b. Write a code to display a toast that shows “Programing in Android is Fun” and
explain each parameter of Toast.

Toast.makeText(getApplicationContext(),"Programming in Android is
Fun",Toast.LENGTH_SHORT).show();

It has three parts:

 Context: it is the context of the toast ie. The context where it is to be used

 CharSequence: a text or a message that is to be displayed.

 Duration: the duration of the visibility of the toast.

c. Write a java code to display day name on Toast using Switch case statement. e.g:
input MONDAY in textbox and display “Today is Monday”.

package com.example.samdq3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Button btn;
EditText ediText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ediText = (EditText)findViewById(R.id.text1);
btn = (Button)findViewById(R.id.button);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int chk=0;
String days = ediText.getText().toString().toLowerCase();
switch(days) {
case "monday":
Toast.makeText(getApplicationContext(),"Today is
Monday",Toast.LENGTH_SHORT).show();
5
Page 2 of 17
%
Enrollment Number: ____________________________

break;
case "tuesday":
Toast.makeText(getApplicationContext(),"Today is
Tuesday",Toast.LENGTH_SHORT).show();
break;
case "wednesday":
Toast.makeText(getApplicationContext(),"Today is
Wednesday",Toast.LENGTH_SHORT).show();
break;
case "thursday":
Toast.makeText(getApplicationContext(),"Today is
Thursday",Toast.LENGTH_SHORT).show();
break;
case "friday":
Toast.makeText(getApplicationContext(),"Today is Friday",
Toast.LENGTH_SHORT).show();
break;
case "saturday":
Toast.makeText(getApplicationContext(),"Today is
Saturday",Toast.LENGTH_SHORT).show();
break;
case "sunday":
Toast.makeText(getApplicationContext(),"Today is
Sunday",Toast.LENGTH_SHORT).show();
break;
case "":
Toast.makeText(getApplicationContext(),"Enter a
weekday!",Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(getApplicationContext(),"Enter a valid
weekday!!",Toast.LENGTH_SHORT).show();
}
}
});
}
}

5
Page 3 of 17
%
Enrollment Number: ____________________________

Page 4 of 17
%
Enrollment Number: ____________________________

Q: 2. Write a java code to display the following output shown in figure below: CLO 2

package com.example.q2samd;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


CheckBox chk1,chk2,chk3;
Button button;
String s="";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chk1=findViewById(R.id.checkBox1);
chk2=findViewById(R.id.checkBox2);
chk3=findViewById(R.id.checkBox3);
button=findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

if(chk1.isChecked())
{
s="iPhone check: true\n";
}
else
{
s="iPhone check: false\n";
}
Page 5 of 17
%
Enrollment Number: ____________________________

if(chk2.isChecked())
{
s+="Android Check: true\n";
}
else
{
s+="Android check: false\n";
}
if(chk3.isChecked())
{
s+="Windows Phone check: true";
}
else
{
s+="Window Phone check: false";
}
Toast
toast=Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG);
toast.show();
}
});

}
}

XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity"
android:layout_marginTop="80dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical"

android:id="@+id/LL1">

<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="iPhone"
android:layout_marginBottom="20dp"/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"
android:layout_marginBottom="20dp"/>
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Page 6 of 17
%
Enrollment Number: ____________________________

android:text="Windows Mobile" />

<Button
android:id="@+id/button"
android:layout_marginTop="30dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display" />

</LinearLayout>

</RelativeLayout>

Page 7 of 17
%
Enrollment Number: ____________________________

Q3. Examine the following scenario in which you are required to develop a
mobile application. [CLO3]
You are requested to paste android code along with output screen shots.
Bancroft Company wants a contact management system which require a sign-up with contact
details including name, country, contact number, profile image and email address of their
clients. Store all these attributes in customize ListView.

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout 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"
tools:context=".MainActivity"
android:paddingTop="20dp"
android:paddingLeft="20dp">

<ImageView

Page 8 of 17
%
Enrollment Number: ____________________________

android:id="@+id/image_view"
android:layout_width="195dp"
android:layout_height="171dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="90dp"
android:layout_marginLeft="90dp"
android:layout_marginEnd="106dp"
android:layout_marginRight="106dp"
android:layout_marginBottom="502dp"
android:contentDescription="TODO"
android:src="@drawable/ic_launcher_background" />

<Button
android:id="@+id/btnPickImg"
android:layout_width="197dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="106dp"
android:layout_marginRight="106dp"
android:layout_marginBottom="444dp"
android:text="Select a photo" />

<LinearLayout
android:layout_width="384dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:layout_marginBottom="137dp"
android:orientation="vertical">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="84dp"
android:layout_height="wrap_content"
android:text="First Name:" />

<EditText
android:id="@+id/edtFirstName"

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:layout_width="301dp"
android:layout_height="wrap_content"
android:inputType="textPersonName" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"

Page 9 of 17
%
Enrollment Number: ____________________________

android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="84dp"
android:layout_height="wrap_content"
android:text="Last Name:" />

<EditText
android:id="@+id/edtLastName"

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:layout_width="302dp"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="84dp"
android:layout_height="wrap_content"
android:text="Contact:" />

<EditText
android:id="@+id/edtContact"
android:digits="0123456789"
android:layout_width="302dp"
android:hint="03XXXXXXXXX"
android:layout_height="wrap_content"
android:inputType="phone" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:paddingTop="15dp"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:text="Email:" />

<EditText

android:id="@+id/edtEmail"
android:layout_width="239dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="45dp"
android:layout_marginRight="45dp"
android:inputType="textEmailAddress" />
</RelativeLayout>

<LinearLayout
android:layout_width="wrap_content"

Page 10 of 17
%
Enrollment Number: ____________________________

android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="84dp"
android:layout_height="wrap_content"
android:text="CNIC:" />

<EditText
android:id="@+id/edtCNIC"
android:layout_width="299dp"
android:layout_height="40dp"
android:digits="0123456789-"
android:hint="XXXXX-XXXXXXX-X"
android:maxLength="15" />

</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="41dp">

<EditText
android:id="@+id/in_date"
android:layout_width="181dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:hint="DOB: MM-DD-YYYY" />

<Button
android:id="@+id/btn_date"
android:layout_width="172dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="35dp"
android:layout_marginEnd="202dp"
android:layout_marginRight="202dp"
android:text="SELECT Date" />
</RelativeLayout>

</LinearLayout>

<Button
android:id="@+id/btnSubmit"
android:layout_width="139dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="143dp"
android:layout_marginRight="143dp"
android:layout_marginBottom="26dp"
android:text="Submit" />

</RelativeLayout>

Page 11 of 17
%
Enrollment Number: ____________________________

MainActivity.java
package com.example.q3samd;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.icu.util.Calendar;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Date;

public class MainActivity extends AppCompatActivity {

private ArrayList<String> hobbies = new ArrayList<String>();


private Button hButton;
private Button submit, btnDate, btnpickImg;
private ImageView imageView;
private String dob, hobbiesString = "";
private Uri uriImg;
private EditText fname, lname, contact, email, cnic, inDOB;
private Spinner gender,country;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

submit = (Button) findViewById(R.id.btnSubmit);


submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(fname.getText().toString() != "" && lname.getText().toString()
!= "" && email.getText().toString() != "" &&
gender.getSelectedItem().toString() != "" &&
country.getSelectedItem().toString() != "" && dob != null &&
contact.getText().toString() != "" && fname.getText().toString() != "" &&
cnic.getText().toString() != "" && uriImg != null ) {
intent = new Intent(MainActivity.this, MainActivity2.class);
intent.putExtra("fname", fname.getText().toString());
intent.putExtra("lname", lname.getText().toString());
Page 12 of 17
%
Enrollment Number: ____________________________

intent.putExtra("email", email.getText().toString());
intent.putExtra("gender",
gender.getSelectedItem().toString());
intent.putExtra("country",
gender.getSelectedItem().toString());
intent.putExtra("dob", dob);
intent.putExtra("contact", contact.getText().toString());
intent.putExtra("cnic", cnic.getText().toString());
intent.putExtra("imgUri", uriImg.toString());
intent.putExtra("hobbies", getHobbies());
startActivity(intent);
}
else
Toast.makeText(MainActivity.this, "Please fill all the
fields", Toast.LENGTH_SHORT).show();
}
});

inDOB = (EditText) findViewById(R.id.in_date);

btnDate = (Button) findViewById(R.id.btn_date);


btnDate.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(View v) {
setDate();
}
});

btnpickImg = (Button) findViewById(R.id.btnPickImg);


btnpickImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pickImg();
}
});

fname = (EditText) findViewById(R.id.edtFirstName);

lname = (EditText) findViewById(R.id.edtLastName);


contact = (EditText) findViewById(R.id.edtContact);
email = (EditText) findViewById(R.id.edtEmail);

cnic = (EditText) findViewById(R.id.edtCNIC);


cnic.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {

@Override
public void onTextChanged(CharSequence s, int start, int before, int
count) {
if(s.length() == 5)
{
cnic.append("-");
}

Page 13 of 17
%
Enrollment Number: ____________________________

else if(s.length() == 13)


{
cnic.append("-");
}
}

@Override
public void afterTextChanged(Editable s) {

}
});
}
private void setHobbies()
{
ArrayList<Integer> temp = new ArrayList<Integer>();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose your Hobbies");

String[] hobby = {"Painting", "Writing", "Sports", "Watching Movies",


"Eating"};
boolean[] checkedItems = {false, false, false, false, false};
builder.setMultiChoiceItems(hobby, checkedItems, new
DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean
isChecked) {
if(isChecked) {
temp.add(which);
}
else
temp.remove(Integer.valueOf(which));
}
});

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {


@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(DialogInterface dialog, int which) {
String tempHobby;
for(int i =0; i<temp.size(); i++)
{
tempHobby = hobby[temp.get(i)];
hobbies.add(tempHobby);
}

}
});
builder.setNegativeButton("Cancel", null);

AlertDialog dialog = builder.create();


dialog.show();
}

private String getHobbies()


{
hobbiesString = "";
for(int i=0;i<hobbies.size();i++)
{
hobbiesString+=hobbies.get(i);
}
return hobbiesString;

Page 14 of 17
%
Enrollment Number: ____________________________

@RequiresApi(api = Build.VERSION_CODES.N)
private void setDate()
{
// Get Current Date
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(this,


new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year, int
monthOfYear, int dayOfMonth) {
dob = (dayOfMonth + "-" + (monthOfYear + 1) + "-" +
year);
inDOB.setText(dob);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}

private void pickImg()


{
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(intent, 100);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && requestCode == 100)
{
uriImg = data.getData();
imageView.setImageURI(uriImg);
}
}

Page 15 of 17
%
Enrollment Number: ____________________________

Page 16 of 17
%
Enrollment Number: ____________________________

End Paper

Page 17 of 17

You might also like