Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider that you are a developing an app for your university that stores the co

ID: 3721942 • Letter: C

Question

Consider that you are a developing an app for your university that stores the contacts details for all faculty members.

Complete the DatabaseHandler class

Complete the missing code (1) & (2)

Create the Contacts table (3). The static variables in the code represent the column names for the table to store the information.

Complete the DataSource class

Complete the missing code (4) & (5)

Insert a record into the Contacts table. Use any values for each table column (6)

Retrieve the contact last_name of a specific id (passed as parameter) (7)

Update the contact mobile phone of a specific user_id (8)

public class DatabaseHandler extends SQLiteOpenHelper //(1)

    // Database Version
   
private static final int DATABASE_VERSION = 1 ;
    // Database Name
   
private static final String DATABASE_NAME = "seu";

    // Contacts table name
   
private static final String TABLE_CONTACTS = "Contacts";

    // Contacts Table Columns names
   
private static final String KEY_ID = "id";
    private static final String KEY_FIRST_NAME = "first_name";
    private static final String KEY_LAST_NAME = "last_name";
    private static final String KEY_MOBILE_NUMBER = "mobile_number";
    private static final String KEY_EMAIL_ID = "email_id";
    private static final String KEY_USER_ID = "user_id";
    private static final String KEY_PASSWORD = "password";
    private static final String KEY_ROLE = "user_role";

    public DatabaseHandler(Context context) {


        (context, DATABASE_NAME, null, DATABASE_VERSION); //(2)
    }

   // Creating Table Contacts
   
@Override

    public void onCreate(SQLiteDatabase db) { //(3)

          String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_FIRST_NAME + " TEXT," + KEY_Last_NAME + " TEXT," + KEY_MOBILE_NUMBER + " INTEGER," + KEY_EMALL_ID + " TEXT," + KEY_USER_ID + " TEXT," + KEY_PASSWORD + " TEXT," + KEY_ROLE + " TEXE" ")";

          db.execSQL(CREATE_CONTACTS_TABLE);

    }

}

public class DataSource {

    private SQLiteDatabase database ;

      

    private DatabaseHandler dbHelper ;

    public DataSource(Context context) {

    ___________________________________________ //(4)

}

   public void open() throws SQLException {

_______________________________________________//(5)

}

// Insert one record information into Contacts Table. Put any value for each column
    public boolean addContact( ) { //(6)
   

  
    }

     // Update the contact mobile phone of the passed contact_id parameter. Put any value for the updated contact mobile phone

       public boolean updateContact(int contact_id)   // (7)

             }

      // Retrieve the contact last_name of the passed id parameter

      public String getContactName(int contact_id) // (8)

{

      }

}

Explanation / Answer

DatabaseHandler class has been modified by making some of the fields package accessible, to remove redundancy of defining the same in DataSource class. Also, onUpgrade() method needs to be overridden for successful compilation.

Below are the classes implemented -

/***** DatabaseHandler Class *****/

/***** DataSource Class *****/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote