15/06/2021 Week 7: Workshop Quiz: Attempt review
FIT2081 Mobile application development – S1 2021
Dashboard / My units / FIT2081_S1_2021 / Assessments / Week 7: Workshop Quiz
Started on State Completed on Time taken Grade
Print friendly format
Question 1
Monday, 19 April 2021, 9:46 PM Finished
Monday, 19 April 2021, 11:50 PM 2 hours 4 mins
9.17 out of 10.00 (92%)
Question 1
Complete
Mark 9.17 out of 10.00
Q1- Briefly describe the roles of each of the annotations?
a) @Dao: It is required to consider the interface as a DAO or an abstract class.
b) @Entity: It is required to define the class as a Room Entity and it also specifies the table name.
c) @ColoumnInfo: It specifies the column name in the database.
d) @Database: It is required to consider the current class as a Room database and it specifies the list of entities and the current version.
Comment:
(Q1=100% Q2=100% Q3=67% )
Question 2 Complete Not graded
https://lms.monash.edu/mod/quiz/review.php?attempt=19382686&cmid=8331153 1/4
15/06/2021 Week 7: Workshop Quiz: Attempt review
Question 2
Q2 – a) Why does getAllCars() method have the .observe() method in its return?
Because the output of this method is LiveData, the caller has to observe. Inside observe method we put all the changes that we want to implement on data change.
First of all, I need to create the live data instance in ViewModel and then we set the data using methods like setValue and
postValue. Then I have to return the live data in order to see them by the users in either form of activity or fragments. Finally, I see the data through the views which are placed in our UI through the observe method.
b) What is the role/effect of .observe() in the provided code?
The observe method invokes the callback method that is provided in the second parameter each time the data gets changes.
Those observers will be notified that are active. When an observer comes from an inactive to an active state, then the updated data will be sent to it. Therefore the updated data will be shown in the user interface.
Question 3 Complete Not graded
Question 3
Q3 – Assume you have a table named ‘cars’ with three attributes: • Id: int (primary key)
• maker: varchar(20)
• year: int
Write a piece of code that represents a method in a Dao interface which is part of a Room database implementation. If the method gets invoked, all cars with ‘year’ less than 1970 must be deleted.
import androidx.annotation.NonNull; import androidx.room.ColumnInfo; import androidx.room.Entity;
import androidx.room.PrimaryKey;
import androidx.lifecycle.LiveData; import androidx.room.Dao;
import androidx.room.Insert; import androidx.room.Query;
import java.util.List;
@Entity(tableName = “cars”) public class Customer {
@PrimaryKey(autoGenerate = true) @NonNull
https://lms.monash.edu/mod/quiz/review.php?attempt=19382686&cmid=8331153 2/4
15/06/2021 Week 7: Workshop Quiz: Attempt review
@ColumnInfo(name = “carId”) privateint id;
@ColumnInfo(name = “carmaker”) private String maker;
@ColumnInfo(name = “caryear”) private int year;
public int getId(){ return id;
}
public String getmaker(){
return maker; }
public int getyear(){ return year;
}
publicvoidsetId(@NonNullint id){ this.id = id;
}
@Dao
public interface CarDao {
}
@Query(“select maker from cars”) LiveData> getcar();
@Query(“select maker from cars where year< 1970") List
@Query(“delete from maker where year <1970") void deleteCars(String name);
@Query("delete FROM cars") void deleteCars();
Question 4 Not answered Not graded
Question 4
https://lms.monash.edu/mod/quiz/review.php?attempt=19382686&cmid=8331153 3/4
15/06/2021 Week 7: Workshop Quiz: Attempt review
Question 5 Not answered Not graded
Question 5
◄ Week 6: Workshop Quiz
Jump to...
Week 8: Workshop Quiz ►
https://lms.monash.edu/mod/quiz/review.php?attempt=19382686&cmid=8331153 4/4