public void dialog_success{ Dialog dialog=new Dialogthis dialog.requestWindowFeatureWindow.FEATURE_NO_TITLE dialog.setContentViewR.layout.dialog_success dialog.show; Button btnok=Butt
Trang 1TRƯỜNG ĐẠI HỌC CÔNG NGHỆ GIAO THÔNG VẬN TẢI
KHOA CÔNG NGHỆ THÔNG TIN
Hà Nội, tháng 12 năm 2022
Trang 2M;c l;c
1.Giới thiệu 1
1.1 Mục tiêu 1
1.2 Actors và Use Cases 1
1.3 Mô tả 2
2 Thiết kế cơ sở dữ liệu và chức năng 2
2.1.SQL 2
2.1.1 Category 2
2.1.2 User 4
2.1.3 Quiz Contract 9
2.2.Giao diện và code 14
2.2.1 Đăng Nhập, Đăng Ký 14
2.2.2 Thêm Câu hỏi môn Toán 27
2.2.3 Thêm câu hỏi môn Văn 32
2.2.4 Cập nhật câu hỏi Toán, Tiếng Việt 36
2.2.5 Danh sách toàn bộ câu hỏi Toán và Tiếng Việt 45
2.6 Màn hình khi làm trắc nghiệm 51
3.Phân công công việc 62
Trang 31.Giới thiệu
1.1 M;c tiêu
Trong thời kì hiện nay, những ứng dụng trên điện thoại đang đóng góp không nhỏ vào đời sống của con người bởi sự tiện ích, nhỏ gọn nhưng hiệu quả không kém gì những trang Web Một trong những ứng dụng có thể kể đến là trong học tập, hiện tại đã và đang có nhiều phần mềm hỗ trợ học tập cho mọi lứa tuổi, mọi môn học.
Do đó, em xin lựa chọn đề tài phát triển ứng dụng thi trắc nghiệm Toán và Tiếng Việt cho các bé.
1.2 Actors và Use Cases
1
Trang 41.3 Mô tả
Ứng dụng cho phép bé làm câu hỏi trắc nghiệm môn Toán và Tiếng Việt, có chấm điểm và hiển thị kết quả ngay sau khi làm Bé có thể nhìn thấy danh sách câu hỏi.
Admin có thể đăng nhập, đăng ký, quản lý các câu hỏi
2 Thiết kế cơ sở dữ liệu và chức năng
private DBHelper dbHelper;
public static final String SQL_CREATE_CAT = "CREATE TABLE tbl_category(\n" +
"\t id INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
"\t name TEXT NOT NULL);";
public static final String TBL_CAT = "tbl_category";
public static final String TAG = "CategotyDAO";
public categoryDao(Context context){
2
Trang 5db dbHelper= getWritableDatabase();
}
public int insertCat(Category category){
ContentValues values = new ContentValues();
public List<Category> allCat(){
List<Category> categories=new ArrayList<>();
Cursor c=db.query(TBL_CAT,null,null,null,null,null,null ;) c.moveToFirst();
while (c.isAfterLast() == false) {
Category category = new Category(
}
}
2.1.2 User
3
Trang 6import tktsp.example.a17dtha2_aptracnghiem.endcode.enCode;public class userDao {
private SQLiteDatabase db;
private DBHelper dbHelper;
public static final String SQL_CREATE_USER = "CREATE TABLE tbl_user(\n" + "\t username text PRIMARY KEY,\n" +
"\t password text NOT NULL,\n" +
"\t name_user text NOT NULL,\n" +
"\t email text NOT NULL UNIQUE,\n" +
"\t permission INTEGER NOT NULL);";
public static final String TBL_USER = "tbl_user";
public static final String TAG = "UserDAO";
//kh i t o DB, cho phép ghi sqlở ạ
public userDao(Context context) {
dbHelper = new DBHelper(context);
db = dbHelper.getWritableDatabase();
}
public int insertUser(User user) {
enCode enCode = new enCode();
String pass = enCode.md5(user.getPassword().toString());
ContentValues values = new ContentValues();
values.put("username", user.getUsername());
values.put("password", pass);
4
Trang 7public List<User> getallUser() {
List<User> dsuser = new ArrayList<>();
Cursor cursor = db.query(TBL_USER, null, null, null, null, null, null)
cursor.moveToFirst();//bắắt đầầu t hàng đầầu tiênừ
while (cursor.isAfterLast() == false) { //nêắu qua kh i phầần t cuốắi cùngỏ ừ User u = new User(
public boolean checkUsername(String username) {
String sql = "SELECT * FROM " + TBL_USER + " WHERE username='" + username + "'"; Cursor c = db.rawQuery(sql, null)
Log.d("giatri", String.valueOf(c.getCount()));
5
Trang 8public Boolean checkLogin(String username String pass) {,
List<User> listuser = new ArrayList<>();
enCode edCode = new enCode();
String password = edCode.md5(pass);
String sql = "SELECT * FROM " + TBL_USER + " WHERE username='" + username + "' and password='"+ password + "'";
Cursor c = db.rawQuery(sql, null)
public User getProfile(String username) {
// String sql = "SELECT * FROM " + TBL_USER + " WHERE username='" + username + "'"; // WHERE username='" + username + "'
String where="username = ?";
String[] whereArgs={username};
// Cursor c = db.rawQuery(sql, null);
Cursor c=db.query(TBL_USER,null,where whereArgs, ,null,null,null ;)
Trang 9public class quizcontractDao {
private SQLiteDatabase db;
private DBHelper dbHelper;
public static final String SQL_CREATE_QUIZ = "CREATE TABLE tbl_quiz(\n" + "\t id INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
"\t question text NOT NULL,\n" +
"\t option1 text NOT NULL,\n" +
"\t option2 text NOT NULL ,\n" +
"\t option3 text NOT NULL ,\n" +
"\t answer text NOT NULL, \n" +
"\t category INTEGER NOT NULL);";
public static final String TBL_QUIZ = "tbl_quiz";
public static final String TAG = "QuizContractDAO";
7
Trang 10dbHelper= new DBHelper(context);
db dbHelper= getWritableDatabase();
}
public int insertQuiz(QuizContract quiz){
ContentValues values=new ContentValues();
public List<QuizContract> getQuizbyCat(int id){
List<QuizContract> listQuiz=new ArrayList<>();
Trang 11if (db.delete(TBL_QUIZ,where,whereArgs)< ){0 return -1;
}
}catch (Exception e){
Log.e( TAG, e.toString());
}
return ;1
}
public int updateQuiz(QuizContract quiz){
ContentValues values=new ContentValues();
if (db.update(TBL_QUIZ,values where whereArgs)==-, , 1) { return -1;
Trang 122.2.Giao diện và code
2.2.1 Đăng Nhập, Đăng Ký
2.2.1.1 Đăng Ký
Code mẫu:
10
Trang 13public void onClick(View view) {
Intent Main=new Intent(registerUser.this,MainActivity.class) startActivity(Main);
finish();
11
Trang 14//kh i t o userDao đ bắắt đầầu th c hi n nghi p vở ạ ể ự ệ ệ ụ
userDao=new userDao(registerUser.this ;)
//check điêầu ki nệ
if (edtName.getText().toString().isEmpty() || edtUsename.getText().toString().isEmpty() || edtPassword.getText().toString().isEmpty() || edtRPassword.getText().toString().isEmpty() || edtEmail.getText().toString().isEmpty()){
Toast.makeText(registerUser.this,"Khống Được B Tróng"ỏ ,Toast.LENGTH_LONG).show(); else if } (edtUsename.getText().toString().length()<5 || edtPassword.getText().toString().length()< ){5
Trang 15public void dialog_success(){
Dialog dialog=new Dialog(this)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.dialog_success)
dialog.show();
Button btnok=(Button) dialog.findViewById(R.id.btnOk) btnok.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
intent=new Intent(registerUser.this,MainActivity.class) startActivity(intent)
Trang 16Code mẫu:
mport androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;import android.app.Dialog;
Trang 17Button btnDangky btnLogin, ;
EditText edtUsername edtPassword, ;
userDao user;
15
Trang 18user=new userDao(MainActivity.this)
FacebookSdk.sdkInitialize(getApplicationContext());
btnloginf.setReadPermissions(Arrays.asList("public_profile" "email", ));
btnloginf.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override
public void onSuccess(LoginResult loginResult) {
Paper.init(MainActivity.this ;)
Paper.book().write(General.USER_CHECK,"Facebook")
Paper.book().write(General.USER_NAME,"null");
Trang 19public void onClick(View view) {
Intent AcRegister=new Intent(MainActivity.this,registerUser.class ;)
user=new userDao(MainActivity.this ;)
Boolean taikhoan= user.checkLogin(username password), ;
if (taikhoan==true || username.equals("admin") && password.equals("admin")){
Paper.init(MainActivity.this ;)
Paper.book().write(General.USER_NAME, username);
// Intent AcRegister=new Intent(MainActivity.this,processbar_Activity.class);
Intent AcRegister = new Intent(MainActivity.this,bottomNavigation.class ;)
startActivity(AcRegister);
finish();
else } {
Toast.makeText(MainActivity.this,"Vui Lòng Ki m Tra l i Tài ể ạ
Kh a"ỏ ,Toast.LENGTH_SHORT).show();
Trang 20Paper.book().write(General.USER_EMAIL, email1);
Trang 21Code mẫu:
import androidx.appcompat.app.AppCompatActivity;import android.app.Dialog;
Trang 22import android.widget.Toast;
import tktsp.example.a17dtha2_aptracnghiem.DAO.quizcontractDao;
import tktsp.example.a17dtha2_aptracnghiem.model.QuizContract;
public class addQuestionToan extends AppCompatActivity {
EditText txtcauhoi txtoption1 txtoption2 txtoption3 txtcaudung, , , , ;
Button btnadd btnback, ;
public void onClick(View view) {
Intent intent=new Intent(addQuestionToan.this,quanlyTracNghiem.class)
Trang 23public void showdialog(){
Dialog dialog = new Dialog(addQuestionToan.this)
public void onClick(View view) {
Intent intent=new Intent(addQuestionToan.this,listTracNghiemToan.class) startActivity(intent);
Trang 24Code mẫu:
import androidx.appcompat.app.AppCompatActivity;import android.app.Dialog;
Trang 25import tktsp.example.a17dtha2_aptracnghiem.DAO.quizcontractDao;
import tktsp.example.a17dtha2_aptracnghiem.model.QuizContract;
public class addQuestionVan extends AppCompatActivity {
EditText txtcauhoi txtoption1 txtoption2 txtoption3 txtcaudung, , , , ;
public void onClick(View view) {
Intent intent=new Intent(addQuestionVan.this,quanlyTracNghiem.class ;)
}catch (Exception e){
Log.e("loi",e.toString());
}
}
23
Trang 26public void showdialog(){
Dialog dialog = new Dialog(addQuestionVan.this)
public void onClick(View view) {
Intent intent=new Intent(addQuestionVan.this,listTracNghiemVan.class) startActivity(intent);
Trang 27Code mẫu:
import androidx.appcompat.app.AppCompatActivity;import android.app.Dialog;
Trang 28import tktsp.example.a17dtha2_aptracnghiem.DAO.quizcontractDao;
import tktsp.example.a17dtha2_aptracnghiem.model.QuizContract;
public class detailTracNghiemToan extends AppCompatActivity {
EditText txtcauhoi txtoption1 txtoption2 txtoption3 txtcaudung, , , , ;
Button btnUpdate btnback, ;
public void onClick(View view) {
QuizContract quiz=new QuizContract(
Trang 29});
btnback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(detailTracNghiemToan.this,listTracNghiemToan.class ;) startActivity(intent);
public void showdialog(){
Dialog dialog = new Dialog(detailTracNghiemToan.this)
Trang 30Intent intent=new Intent(detailTracNghiemToan.this,listTracNghiemToan.class ;) startActivity(intent);
public class detailTracNghiemVan extends AppCompatActivity {
EditText txtcauhoi txtoption1 txtoption2 txtoption3 txtcaudung, , , , ;
Button btnUpdate btnback, ;
Trang 31public void onClick(View view) {
QuizContract quiz=new QuizContract(
});
btnback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(detailTracNghiemVan.this,listTracNghiemVan.class ;)
startActivity(intent);
29
Trang 32public void showdialog(){
Dialog dialog = new Dialog(detailTracNghiemVan.this ;)
public void onClick(View view) {
Intent intent=new Intent(detailTracNghiemVan.this,listTracNghiemVan.class ;) startActivity(intent);
Trang 33-List toán:
import androidx.appcompat.app.AppCompatActivity;import androidx.recyclerview.widget.LinearLayoutManager;import androidx.recyclerview.widget.RecyclerView;import android.content.Intent;
Trang 34import tktsp.example.a17dtha2_aptracnghiem.adapter.tracnghiemtoanAdapter;import tktsp.example.a17dtha2_aptracnghiem.model.QuizContract;
public class listTracNghiemToan extends AppCompatActivity {
recyclerView = (RecyclerView) findViewById(R.id.listquiz)
recyclerView.setLayoutManager(new LinearLayoutManager(listTracNghiemToan.this ;)) quizcontractDao=new quizcontractDao(listTracNghiemToan.this)
listquiz quizcontractDao= getQuizbyCat(1)
adapter=new tracnghiemtoanAdapter(listquiz,this ;)
public void onClick(View view) {
Intent intent=new Intent(listTracNghiemToan.this,addQuestionToan.class ;) startActivity(intent);
}
});
btnback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(listTracNghiemToan.this,quanlyTracNghiem.class) startActivity(intent);
Trang 35- List tiếng việt:
import androidx.appcompat.app.AppCompatActivity;import androidx.recyclerview.widget.LinearLayoutManager;import androidx.recyclerview.widget.RecyclerView;import android.content.Intent;
Trang 36import tktsp.example.a17dtha2_aptracnghiem.adapter.tracnghiemtoanAdapter;import tktsp.example.a17dtha2_aptracnghiem.model.QuizContract;
public class listTracNghiemVan extends AppCompatActivity {
recyclerView = (RecyclerView) findViewById(R.id.listquiz)
recyclerView.setLayoutManager(new LinearLayoutManager(listTracNghiemVan.this ;)) quizcontractDao=new quizcontractDao(listTracNghiemVan.this ;)
listquiz quizcontractDao= getQuizbyCat(2)
adapter=new tracnghiemtoanAdapter(listquiz,this ;)
public void onClick(View view) {
Intent intent=new Intent(listTracNghiemVan.this,addQuestionVan.class ;) startActivity(intent);
}
});
btnback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(listTracNghiemVan.this,quanlyTracNghiem.class ;) startActivity(intent);
Trang 372.6 Màn hình khi làm trắc nghiệm
Code mẫu:
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;import android.annotation.SuppressLint;
import android.app.Dialog;
35
Trang 38public class QuizActivity extends AppCompatActivity {
Button btnHuy btnNext, ;
Trang 39private List<QuizContract> quizContractList;
private int questionCounter;
private int questionTotal;
private QuizContract questionCurrent;
private int score;
private boolean answered;
quizcontractDao quizcontractDao;
private CountDownTimer countDownTimer;
private long timeLeftInMillis;
textColorDefaultCd txtCountDown= getTextColors();
quizcontractDao=new quizcontractDao(QuizActivity.this ;)
Paper.init(QuizActivity.this)
int id_cat= Paper.book().read(General.CATEGORY)
quizContractList quizcontractDao= getQuizbyCat(id_cat);
questionTotal quizContractList= size();
Collections.shuffle(quizContractList); //dòng này cho phép sáo tr n phầần t trong m ngộ ử ả showNextQuestion();