Skip to content

Latest commit

 

History

History

CAT 1

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

CAT 1

Table of Contents

Exercise 1

a)

To enable full-screen (immersive) mode on an Android application, the minimum API Level where this feature is available is API Level 19 (Android 4.4 KitKat).

b)

According to the Android Developers Documentation, the use of a local SQLite database (android.database.sqlite) has been available since API Level 1, all the way to the current latest API Level (31). The version of SQLite changes with every API Level.

Exercise 2

a)

var name : String = " hello "
name = null

Problem

name is not nullable, so trying to make it null will throw an error.

Solution

var name : String? = " hello "
name = null

Now, the name variable can be set to null.

b)

val v1 : Int = 5
v1 = 10

Problem

v1 is a constant value, so trying to change its value will throw an error.

Solution

var v1 : Int = 5
v1 = 10

Now, the v1 variable can be reassigned.

c)

var v2 : String ? = null
var v3 : Any = "cat"
v2 = v3

Problem

Cannot assign the value of v3 of type Any to a variable v2 of type String. In order to assign the value, a cast operation must be called to ensure that v2 receives a String.

Solution

var v2 : String? = null
var v3 : Any = "cat"
v2 = v3.toString()

Now, the v2 variable can be set to the String value of v3.

Exercise 3

a)

val shopping_list = ArrayList<String>()
shopping_list.add("Apples")
shopping_list.add("Bananas")
shopping_list.add("Watermelon")
shopping_list.add("Oranges")
shopping_list.add("Pineapple")
shopping_list.removeAt(0)

b)

val dic =  HashMap<Int, String>()
dic[1] = "value1"
dic[2] = "value2"
for ((key, value) in dic) {
    Log.i("$key","$value")
}

Exercise 4

a)

class Seminary(pname: String, pduration: Int) {
    var _name: String = pname
    var _duration: Int = pduration
}

Note: to match the usual standard, private attributes are preceded by an underscore _.

b)

class User(pid: Int) {
    var _name: String = "Unknown"
    var _id: Int = pid
    var _attendance: ArrayList<Seminary>
}

c)

Here is the updated User class.

class User(pid: Int) {
    var _name: String = "Unknown"
    var _id: Int = pid
    var _attendance: ArrayList<Seminary>
    fun addSeminary(d:Seminary) {
        _attendance.add(d)
    }
}

Exercise 5

a)

var user1 = User(8)

b)

var seminary1 = Seminary("AI for dummies", 50)

c)

user1.addSeminary(seminary1)

October 16th, 2023