COURSE 7: WORKING WITH DATA IN ANDROID QUIZ ANSWERS

Week 5: Final Project

Meta Android Developer Professional Certificate

Complete Coursera Answers & Study Guide

Enroll in Coursera Meta Android Developer Professional Certification

Meta Android Dev. Final Project INTRODUCTION

Learning Objectives

  • Build a data driven Android app

READINESS CHECK: HAVE YOU COMPLETED THE INITIAL SETUP?

These questions allow you to check if you have imported the starting project correctly.

1. After opening the starting project M5Exercise in Android Studio, which files are present in the project? Select all that apply.

  • Database.kt (CORRECT)
  • MainActivity.kt (CORRECT)
  • Network.kt (CORRECT)

That’s correct. This file is in the project.

2. What is the content of the Network.kt file?

  • Network and database data models.
  • Network data models. (CORRECT)

That’s correct. This is what Network.kt file contains.

3. What is the content of the Database.kt file? 

  • General application logic
  • Room database setup (CORRECT)

That’s correct. This is what Database.kt file contains.

READINESS CHECK: HAVE YOU SET UP THE REST API QUERIES?

These questions allow you to check if you have set up the REST API queries correctly.

1. After querying a REST API this object is retrieved. What object format is it?

{
 "menu": [
 {
 "id": 1,
 "title": "Spinach Artichoke Dip",
 "price": "10"
 },
 {
 "id": 2,
 "title": "Hummus",
 "price": "10"
 },
 {
 "id": 3,
 "title": "Fried Calamari Rings",
 "price": "51"
 }
 ]
}
  • It is a JSON dictionary containing an array of menu items. (CORRECT)
  • It is a JSON array containing several dictionaries with menu items.

That’s correct. This is the object format.

2. What is the purpose of this code?

httpClient.get("https://raw.githubusercontent.com/Meta-Mobile-Developer-PC/Working-With-Data-API/main/littleLemonSimpleMenu.json")
  • It queries a server on the specified URL. (CORRECT)
  • It queries a server on the specified URL and decodes its values.

That’s correct. This is what this API does.

3. What is the purpose of this code?

httpClient
.get("https://raw.githubusercontent.com/Meta-Mobile-Developer-PC/Working-With-Data-API/main/littleLemonSimpleMenu.json")
.body<MenuNetwork>()
  • It decodes the data obtained from the URL containing JSON data against the MenuNetwork data model. (CORRECT)
  • It decodes the data obtained from the MenuNetwork against the specified JSON model.

That’s true. This is what this API does.

READINESS CHECK: HAVE YOU IMPLEMENTED DISPLAYING THE FOOD MENU?

These questions allow you to check if you have implemented displaying the food menu correctly.

1. Which code can be used to retrieve a list of all menu items from the Room database:

  • val databaseMenuItems by database.menuItemDao().getAll().observeAsState(emptyList())
    (CORRECT)
  • val databaseMenuItems by database.menuItemDao()

That’s correct. This is the correct code.

2. Which Composable is responsible for the look-and-feel of the list of menu items?

  • MenuItemsList Composable (CORRECT)
  • List Composable
  • Text Composable

That’s correct. This composable takes a list of the MenuItemRoom items and displays them on the screen

3. When is the value of the databaseMenuItems variable updated?

val databaseMenuItems by database.menuItemDao().getAll().observeAsState(emptyList())
  • When value changes in the database (CORRECT)
  • The first time the onCreate method runs

That’s correct. This variable value reflects database changes.

READINESS CHECK: HAVE YOU IMPLEMENTED FILTERING AND SORTING THE FOOD MENU?

1. Which of the OutlinedTextField attribute’s links entered a search phrase to a searchPhrase variable?

  • onValueChange = { searchPhrase = it }
    (CORRECT)
  • onValueChange = { it = searchPhrase }

That’s correct. This is the correct attribute.

2. You need to display a list of dishes retrieved from Room on a page. You need the list to be sorted by name in alphabetically ascending order. The needed predicates must be stored in the list.
Which is the correct code to accomplish this?

  • databaseMenuItems.sortedBy { it.title } (CORRECT)
  • databaseMenuItems.filter { it.title }

That’s correct. This is how you define the dish property.

3. What is the purpose of creating the menuItems helper variable?

var menuItems = if (orderMenuItems) {
 databaseMenuItems.sortedBy { it.title }
 } else {
 databaseMenuItems
 }
MenuItemsList(menuItems)
  • Allows you to always store a list of sorted menu items.
  • Allows you to store a list of sorted menu items if sorting is enabled (CORRECT)

That’s correct. This approach facilitates sorting of menu items.

FINAL GRADED QUIZ: WORKING WITH DATA IN ANDROID

1. Which signing mechanism is used to sign an API call? 

  • SHA
  • TOKEN
  • JWT
  • HMAC (CORRECT)

Correct! HMAC is a popular signing mechanism used by modern applications to sign API calls.

2. In Android, network calls are performed on a background thread and the result is presented on the main thread. True or false?

  • True (CORRECT)
  • False

That’s correct! Network calls are long running processes and must not block the user interface (UI). Once a result is obtained, the UI must be updated on the main thread.

3. After querying a REST API, the following object is retrieved:

{
  "menu": [
    {
      "title": "Spinach Artichoke Dip",
      "price": "10"
    },
    {
      "title": "Hummus",
      "price": "10"
    },
    {
      "title": "Fried Calamari Rings",
      "price": "51"
    }
  ]
}
  • What is needed to decode this in terms of classes?
  • A class to represent the menu and another one to represent the menu items. (CORRECT)
  • Only one class is needed.

That’s correct. First, the menu will be decoded then its menu items.

4. What is SQL?

  • A database
  • A standard language for interacting with databases (CORRECT)
  • A sequential list of items

Correct! Structured Query Language (SQL) is a standard language used to interact with databases.

5. When referencing the following SQL statement to insert data into the Players table, what is the missing keyword?

INSERT INTO Players (playerID, playerName, age) … (1, "Jack", 25);
  • VALUES (CORRECT)
  • PROPERTIES

Correct! VALUES is the missing keyword to insert data into the Players table.

6. Observe the following SQL statement:

SELECT * FROM  menuItems  WHERE type = "Beverages"; 

The output result returns the data of all the menu items in the table of type Beverages. True or false?

  • True (CORRECT)
  • False

Correct! The output result of this statement returns the data of all menu items that are beverages. The ‘*’ symbol means all columns in the table.

7. Which class is used for updating SharedPreferences?

  • SharedPreferences.Composer
  • SharedPreferences
  • SharedPreferences.Editor (CORRECT)
  • SharedPreferences.Persistence

Correct! SharedPreferences.Editor is the class for updating SharedPreferences.

8. PascalCase is the ideal naming convention for writing API endpoint names. True or false?

  • True
  • False (CORRECT)

Correct! Lowercase is the preferred naming convention for URLs as they are easy to read and understand.

9. ____ is one of the most popular and most used signing mechanisms used by modern day API projects.

  • HMAC (CORRECT)
  • TOKEN
  • JWT
  • SHA

That’s correct! HMAC is one of the most popular and commonly used signing mechanisms used by modern applications to sign API calls.

10. True or false? The JSON given below is a valid JSON code snippet.

{
  "menu": [
    {
      "id": 1,
      "title": "Cola",
      "price": "3",
      "category": {
        "title": "Drinks"
      }
    },
    {
      "id": 2,
      "title": "Club Soda",
      "price": "2.50",
      "category": {
        "title": "Drinks"
      }
    }
  ]
}
  • True (CORRECT)
  • False

Correct! This is valid JSON. It contains an array of menu items and each item in the array contains a valid JSON object with properties.

11. The following query has valid SQL syntax:

SELECT * FROM users WHERE name="Joe";

True or false?

  • True (CORRECT)
  • False

Correct! This query represents valid SQL syntax.

12. Complete the following sentence: The complete information about one specific menu item in a restaurant’s menu database is referred to as a ______________

  • Column (CORRECT)
  • Table
  • Record

Correct! Each row of the table will have a record of information that refers to a specific staff.

13. What’s the SQL keyword that allows you to insert new rows into the table?

  • The UPDATE keyword
  • The NEW keyword
  • The INSERT keyword  (CORRECT)

Correct! INSERT is the instruction to insert new rows into a table.

14. What is SQLite?

  • A library for caching network responses
  • A lightweight database engine (CORRECT)
  • A store for JSON data
  • A file storage system

Correct! SQLite is a fast and popular database engine.

15. Which one of the following API clients and tools offers both web and desktop versions?

  • Insomnia
  • Curl
  • Postman (CORRECT)

Correct! Postman utilizes a graphical interface rather than a command line and can be used as a desktop application or on the web.

16. What are the benefits of signing an API call? Select all that apply.

  • Signed API calls are sanitized.
  • Signed API calls can increase API security. (CORRECT)
  • Signed API calls are automatically validated.
  • Signed API calls ensure data authenticity. (CORRECT)
  • Signed API calls can give access to a resource for a certain period of time. (CORRECT)

Correct! API developers use signed API calls to ensure data authenticity and prevent API abuse. So, it plays an important role in securing API endpoints.
Correct! With a signed API call, Server-side code can verify the signature and ensure that the call comes from an authentic source.
Correct! With a signed API call, Server-side code can verify the signature and ensure access to a resource that was used to create the signature, for a particular amount of time.

17. Which of the following is a networking library?

  • Room
  • Ktor Client (CORRECT)
  • GSON

That’s correct! Ktor Client is a Kotlin networking library.

18. Which of the following are common SQL commands? Select all that apply.

  • DELETE
  • SELECT (CORRECT)
  • CREATE (CORRECT)
  • DROP (CORRECT)
  • RENAME

Correct! SELECT is a common SQL command.
Correct! CREATE is a common SQL command.

Correct! DROP is a common SQL command.

19. Which of the following data types can be stored in SharedPreferences? Select all that apply.

  • List
  • Class
  • String (CORRECT)
  • Boolean (CORRECT)

Correct! Strings can be stored in SharedPreferences.
Correct! Booleans can be stored in SharedPreferences.

20. A restaurant’s menu database includes a menu table with two columns: price and menu item name. What is the correct data type for each column? Select all that apply.  

  • The menu item name column data type is DECIMAL.
  • The price column data type is INT.
  • The menu item name column data type is VARCHAR.  (CORRECT)
  • The price column data type is DECIMAL.  (CORRECT)

Correct! VARCHAR is the right data type for the menu item name.
Correct! DECIMAL is the right data type for price.

21. What is an entity class in Room?

  • A representation of a person in a database
  • A class that represents a database
  • A class that provides methods for accessing data in a database
  • A class that defines the structure of the data in a database (CORRECT)

Correct! Entity defines the data structure in a database.

22. Which of the following best describes Ktor Client?

  • A JSON processing library
  • A database management library
  • A networking library (CORRECT)

That’s correct! Ktor Client is a Kotlin networking library.

23. What is Room for Android?

  • A part of a House architecture
  • A networking library
  • A database
  • A library for managing data (CORRECT)

Correct! Room is a library for managing data using a SQLite database.

24. You have a table named Players with two columns: playerId and playerName. What is the correct SQL statement that outputs all the player names in the Players table? 
Note: When you run the right SQL query, you should have the following output result:

G gIGePftcwy4smaughByvoffgC5vijSjQexPosB4WfdAfOxUCEWuwI0OPUmVMpfD57Hsfkg680zCO78tENxFj OUdO8tCUyPv da6CIJRXBgxdMCpngcmW

  • SELECT * FROM Players;
  • SELECT playerName TABLE Players;
  • SELECT playerName FROM Players; (CORRECT)

Correct! This is the right syntax to output all players names existing in the Players table.

25. Room is an abstraction layer over what database?

  • SQLite (CORRECT)
  • MySQL
  • MongoDB
  • SQL Server

Correct! Room is a library for abstracting the access to SQLite databases.

26. What command would you use to update the UI on the main thread?

  • lifecycleScope.launch
  • runOnUiThread (CORRECT)
  • runOnMainThread

Correct! runOnUiThread is the command for updating the UI on the main thread.

27. What is SharedPreferences?

  • A mechanism to enable or disable notifications
  • A database
  • An interface for configuring the device
  • A file storage interface (CORRECT)

Correct! SharedPreferences is a file storage interface.

28. What would you store using SharedPreferences?

  • Databases
  • Binary data
  • Simple data (CORRECT).
  • Files

Correct! SharedPreferences is used to store simple data.

Meta Android Dev. Final Project CONCLUSION

TBW

Subscribe to our site

Get new content delivered directly to your inbox.

Liking our content? Then, don’t forget to ad us to your BOOKMARKS so you can find us easily!