ECSI 2206 Advanced Visual Programming Exam PP1 by Felix Okoth

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

TECHNICAL UNIVERSITY OF KENYA

FACULTY OF APPLIED SCIENCES AND TECHNOLOGY


SCHOOL OF COMPUTING & INFORMATION TECHNOLOGY
END OF SEMESTER MAY 2017 EXAMINATION SERIES
SECOND SEMESTER EXAMINATIONS 2016/2017
SECOND YEAR EXAMINATIONS FOR THE DEGREE OF
BACHELOR OF TECHNOLOGY IN COMPUTER TECHNOLOGY
BACHELOR OF TECHNOLOGY IN INFORMATION TECHNOLOGY
BACHELOR OF TECHNOLOGY IN COMMUNICATION AND COMPUTER NETWORKS
ECSI 2206/ ECII 2206/ ECCI 2206: ADVANCED VISUAL PROGRAMMING
TIME: 2 Hours MAY 2017

Instructions to candidates:
This paper consists of FIVE Questions.
Answer Question ONE [30 Marks] and any other TWO Questions [20 Marks Each].
Write your college number on the answer sheet.
This paper consists of 5 printed pages

Candidates should check the question paper to ascertain that all the pages are
printed as indicated and that no questions are missing.

© May 2017 The Technical University of Kenya Examinations

Page 1 of 6
Section A Compulsory
QUESTION ONE (30 Marks)
Below are the artifacts for an android app that is composed of MainActivity and UserProfileActivity.
MainActivityhas:
- User-Name (EditText),
- Password (EditText), and
- An “OK” Button.
UserProfileActivity has:
- A TextView that displays the user’s full names.
Steps:
1. Start the application by clicking the icon on the android device/emulator
2. On the login screen, enter user-name and password
3. Click “OK” button to sign-in.
i. If successful, display UserProfilesActivity, and fetch user’s full name from the server
otherwise, display an “Invalid username or password” message to the user.
Fill up the missing code within the artifacts.
AndroidManifest.xml
a) Hint:Add the necessary permissions and specify the minimum sdk version. 3 Marks
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tuk.avp.avp">
<!— your answer -->
<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>
<activity android:name=".UserProfileActivity"></activity>
</application>
</manifest>
Layouts
b) Hint: Add the necessary layouts and components. Remember to attach the right events.
activity_main.xml 10 Marks
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context="com.tuk.avp.avp.MainActivity">
<LinearLayout

Page 2 of 6
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<! — Your answer -->
</LinearLayout>
</android.support.constraint.ConstraintLayout>

c) activity_user_profile.xml 2 Marks
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context="com.tuk.avp.avp.UserProfileActivity">
<!—Your answer --
</android.support.constraint.ConstraintLayout>
d) Classes:
Hint: Use HttpHelper to make the necessary call to the server for
authentication and
fetching user name. 10
Marks
The urls are http://192.168.43.168:8080/tuk/api/signin/{username}/{password}
(this returns a session
key when successful, otherwise null)
http://192.168.43.168:8080/tuk/api/profile/{sessionkey} (this returns the full
names for the user
whose session key was provided)
Remember to display appropriate messages and handle errors.
public class MainActivityextends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void signIn(View view){
<!—your answer --->

}
}
e)
5 Marks
public class UserProfileActivityextends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_profile);
<!— Your answer 
}
}

Page 3 of 6
Helper class.
public class HttpHelper extends AsyncTask<String, Void, String>
{
// 10.0.2.2
private static String BASE = "http://192.168.43.168:8080/tuk/api/";
private IExecute exec;
private HttpURLConnection con;
private String data;
public HttpHelper(String uri)
throws IOException, InvalidParameterException {
if (uri == null || uri.trim().equals("")){
throw new InvalidParameterException("address is null!");
}
URL url = new URL(BASE + uri);
this.con = (HttpURLConnection)url.openConnection();
this.data = null;
}
private String read(){
if (this.data != null){
try {
Writer writer = new BufferedWriter(new OutputStreamWriter(this.con.getOutputStream(),
"UTF-8"));
writer.write(data);
writer.close();
} catch (Exception e){
Log.e("HttpHelper", e.getMessage(), e);
return null;
}
}
StringBuilder sb = new StringBuilder();
try {
InputStream content = new BufferedInputStream(this.con.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line = null;
while ((line = reader.readLine()) != null){
sb.append(line);
}
} catch (IOException e) {
Log.e("HttpHelper", e.getMessage(), e);
}finally {
con.disconnect();
}
return sb.toString();
}
@Override
protected String doInBackground(String... urls) {
return this.read();
}
@Override
protected void onPostExecute(String s) {
this.exec.run(s);
}
public void processVals(IExecute execute){
this.exec = execute;
this.execute();
}
}
public interface IExecute {
void run(String val);
}

Page 4 of 6
Section B: Answer any Two Questions
QUESTION 2 [20 Marks]
a) Given the classes below, and the instantiation that follows, itemize the initialization order for
the variables when the Child is instantiated i.e. Child c = new Child().Specify their default
values.
5 Marks
publicclass Child extends Parent {
privatebytefalg;
privatelongwaist;
publicvoid sums(inta, intb){
Integer x;
x = a + b;
}
}
publicclass Parent {
privateintage;
privatefloatheight;
privatebooleanistall;
publicvoid multiply(inta, intb){
Integer y;
y = a * b;
}
}
b) Write the instance initialization methods the java compiler will create for each of the classes
above. 4 Marks
c) What are the major features of Android Runtime (ART) 3 Marks
d) Using a diagram, list android platform stacks and describe their functions. 5 Marks
e) What are the Java built-in initialization mechanisms? 3 Marks

QUESTION 3 [20 Marks]


a) What are the default initial value for the data types below for instance variable?4 Marks.
Boolean, byte, short, int, long, char, float, double
b) List and explain access modifiers. 3 Marks.
c) How does Just-In-Time (JIT) Compiler work in ART? 6 marks.
d) Which variable type within a class don’t have access modifier? 1 Mark
e) List the primary information contained in an Intent. 6 Marks.
QUESTION 4 [20 Marks]
a) Compare constructor and a method in Java. 6 Marks
b) What is Intent and what are its uses? 4 Marks.
c) What are the steps for enabling developer options on Android 4.2 and higher. 2 Marks

Page 5 of 6
d) Name and give a brief description of the callbacks that you could typically use to handle transitions
between states in an Activity. 8 Marks
QUESTION 5 [20 Marks]
a) Name and give a brief description of the callbacks that you could typically use to handle
transitions between states in a Fragment. 8 Marks
b) List the common layouts that you can use when programming in android to layout your UI.
6 Marks
c) What are the Android Build process? 6 Marks.

Page 6 of 6

You might also like