Guest User

Untitled

a guest
Nov 21st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public String[] getCategoryAndProgress(String subject) {
  2. DataBaseHelper dbHelperCount = new DataBaseHelper(this);
  3. dbHelperCount = new DataBaseHelper(this);
  4. int count = 0;
  5.  
  6. try {
  7. dbHelperCount.openDataBase();
  8. Cursor cursor = dbHelperCount.getCategoryProcess(subject);
  9. if (cursor != null) {
  10. if (cursor.moveToFirst()) {
  11. do {
  12. count = cursor.getInt(cursor.getColumnIndex("count(*)"));
  13. } while (cursor.moveToNext());
  14. }
  15. }
  16. cursor.close();
  17. }
  18. catch(SQLException sqle) {throw sqle;}
  19. finally {dbHelperCount.close();}
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. DataBaseHelper dbHelperProgress = new DataBaseHelper(this);
  27. dbHelperProgress = new DataBaseHelper(this);
  28. String category = "";
  29. int correct = 0;
  30. int attempted = 0;
  31. double score = 0.0;
  32.  
  33. String[] returnString = new String[count];
  34.  
  35.  
  36.  
  37. try {
  38. dbHelperProgress.openDataBase();
  39. Cursor cursor = dbHelperProgress.getCategoryProcess(subject);
  40. if (cursor != null) {
  41. if (cursor.moveToFirst()) {
  42. do {
  43. category = cursor.getString(cursor.getColumnIndex("category"));
  44. attempted = cursor.getInt(cursor.getColumnIndex("attempted"));
  45. correct = cursor.getInt(cursor.getColumnIndex("correct"));
  46. score = ((double)correct/(double)attempted)*100;
  47. returnString[count] = {category, Double.toString(score)};
  48. } while (cursor.moveToNext());
  49. }
  50. }
  51. cursor.close();
  52. }
  53. catch(SQLException sqle) {throw sqle;}
  54. finally {dbHelperProgress.close();}
  55.  
  56. return returnString;
  57.  
  58. }
Add Comment
Please, Sign In to add comment