Advertisement
RosamaryDiaz

Untitled

May 3rd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. package Application;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.util.Scanner;
  7. import java.util.StringTokenizer;
  8. import java.io.BufferedReader;
  9. import java.io.FileReader;
  10. import java.io.FileNotFoundException;
  11. import java.util.ArrayList;
  12. import java.util.Arrays;
  13. import java.util.Collections;
  14. import java.util.Random;
  15.  
  16. /**
  17. * @author olayaperezlozano
  18. * @author rosamary
  19. *
  20. */
  21. public class BasicQuestions{
  22.  
  23. public static Scanner input = new Scanner(System.in);
  24. //i = row
  25. //j = column
  26.  
  27. /**
  28. * @param args
  29. * The csv file needs to be added to locate it and to read it.
  30. * @throws IOException
  31. *
  32. */
  33. public static void basicQuestions( ) throws IOException{
  34. BufferedReader stdIn = new BufferedReader (new InputStreamReader(System.in));
  35. String[][] aOneQuestions = new String[30][5];
  36. String aQuestions = "OrganicChemistryOneQuestions.csv";
  37. String line = null;
  38. BufferedReader br = null;
  39. StringTokenizer st;
  40. int i=0;
  41. int j=0;
  42.  
  43. //System.out.println("entrando al loop");
  44. try{
  45. br = new BufferedReader(new FileReader(aQuestions));
  46.  
  47. while ((line=br.readLine()) !=null){
  48. st = new StringTokenizer(line, ",");
  49. // System.out.println("Loop 1 " +i);
  50. while (st.hasMoreTokens())
  51. {
  52. aOneQuestions[i][j]= st.nextToken();
  53. // System.out.println("Loop 2 " +j);
  54. j++;
  55. }
  56. j = 0;
  57. i++;
  58. }
  59. // System.out.println("Salio");
  60. }
  61.  
  62.  
  63. catch (FileNotFoundException e){
  64. e.printStackTrace();
  65. }catch (IOException e){
  66. e.printStackTrace();
  67. }
  68. finally{
  69. if (br != null){
  70. try{
  71. br.close();
  72. }catch (IOException e) {
  73. e.printStackTrace();
  74. }
  75.  
  76.  
  77. }
  78.  
  79. }
  80.  
  81.  
  82. //insert it here
  83. System.out.println("This is the basic chemistry questions quiz.");
  84. System.out.println(" ");
  85. System.out.println("For every question please insert the letter of the correct answer.");
  86. System.out.println(" ");
  87.  
  88.  
  89. ArrayList<Integer> list = new ArrayList<Integer>();
  90. for (int r =1; r<30; r++) {
  91. list.add(new Integer(r));
  92. }
  93. Collections.shuffle(list);
  94. for (int r=0; r<10; r++) {
  95. //System.out.println(list.get(r));
  96. }
  97.  
  98.  
  99. String[][] quiz = new String[10][5];
  100.  
  101. int a = list.get(0);
  102. quiz[0][0] = aOneQuestions[a][0];
  103. quiz[0][1] = aOneQuestions[a][1];
  104. quiz[0][2] = aOneQuestions[a][2];
  105. quiz[0][3] = aOneQuestions[a][3];
  106. quiz[0][4] = aOneQuestions[a][4];
  107.  
  108. int b = list.get(1);
  109. quiz[1][0] = aOneQuestions[b][0];
  110. quiz[1][1] = aOneQuestions[b][1];
  111. quiz[1][2] = aOneQuestions[b][2];
  112. quiz[1][3] = aOneQuestions[b][3];
  113. quiz[1][4] = aOneQuestions[b][4];
  114.  
  115. int c = list.get(2);
  116. quiz[2][0] = aOneQuestions[c][0];
  117. quiz[2][1] = aOneQuestions[c][1];
  118. quiz[2][2] = aOneQuestions[c][2];
  119. quiz[2][3] = aOneQuestions[c][3];
  120. quiz[2][4] = aOneQuestions[c][4];
  121.  
  122. int d = list.get(3);
  123. quiz[3][0] = aOneQuestions[d][0];
  124. quiz[3][1] = aOneQuestions[d][1];
  125. quiz[3][2] = aOneQuestions[d][2];
  126. quiz[3][3] = aOneQuestions[d][3];
  127. quiz[3][4] = aOneQuestions[d][4];
  128.  
  129. int e = list.get(4);
  130. quiz[4][0] = aOneQuestions[e][0];
  131. quiz[4][1] = aOneQuestions[e][1];
  132. quiz[4][2] = aOneQuestions[e][2];
  133. quiz[4][3] = aOneQuestions[e][3];
  134. quiz[4][4] = aOneQuestions[e][4];
  135.  
  136. int f = list.get(5);
  137. quiz[5][0] = aOneQuestions[f][0];
  138. quiz[5][1] = aOneQuestions[f][1];
  139. quiz[5][2] = aOneQuestions[f][2];
  140. quiz[5][3] = aOneQuestions[f][3];
  141. quiz[5][4] = aOneQuestions[f][4];
  142.  
  143. int g = list.get(6);
  144. quiz[6][0] = aOneQuestions[g][0];
  145. quiz[6][1] = aOneQuestions[g][1];
  146. quiz[6][2] = aOneQuestions[g][2];
  147. quiz[6][3] = aOneQuestions[g][3];
  148. quiz[6][4] = aOneQuestions[g][4];
  149.  
  150. int h = list.get(7);
  151. quiz[7][0] = aOneQuestions[h][0];
  152. quiz[7][1] = aOneQuestions[h][1];
  153. quiz[7][2] = aOneQuestions[h][2];
  154. quiz[7][3] = aOneQuestions[h][3];
  155. quiz[7][4] = aOneQuestions[h][4];
  156.  
  157. int k = list.get(8);
  158. quiz[8][0] = aOneQuestions[k][0];
  159. quiz[8][1] = aOneQuestions[k][1];
  160. quiz[8][2] = aOneQuestions[k][2];
  161. quiz[8][3] = aOneQuestions[k][3];
  162. quiz[8][4] = aOneQuestions[k][4];
  163.  
  164. int l = list.get(9);
  165. quiz[9][0] = aOneQuestions[l][0];
  166. quiz[9][1] = aOneQuestions[l][1];
  167. quiz[9][2] = aOneQuestions[l][2];
  168. quiz[9][3] = aOneQuestions[l][3];
  169.  
  170.  
  171. int total = 0;
  172.  
  173. char answer = 0;
  174.  
  175.  
  176. //System.out.println(answer + quiz[9][3]);
  177.  
  178.  
  179. for(int p=0;p < quiz.length; p++){
  180.  
  181. System.out.println(p+"."+quiz[p][0]);
  182.  
  183. System.out.println("a. " + quiz[p][1]);
  184.  
  185. System.out.println("b. " + quiz[p][2]);
  186.  
  187. System.out.println("c. " + quiz[p][3]);
  188.  
  189. System.out.println(p);
  190.  
  191. answer = input.next().charAt(0);
  192.  
  193.  
  194. switch(answer){
  195.  
  196. case 'a' :
  197.  
  198. if(quiz[p][4].equals("a")){
  199.  
  200. total = total+10;
  201.  
  202. System.out.println("Right answer!");
  203.  
  204. } else{
  205.  
  206.  
  207. System.out.println("Wrong answer!");
  208.  
  209. }
  210.  
  211. break;
  212.  
  213.  
  214. case 'b':
  215.  
  216. if(quiz[p][4].equals("b")){
  217.  
  218. total = total+10;
  219.  
  220. System.out.println("Right answer!");
  221.  
  222. } else{
  223.  
  224. System.out.println("Wrong answer!");
  225.  
  226. }
  227.  
  228. break;
  229.  
  230.  
  231. case 'c':
  232.  
  233. if(quiz[p][4].equals("c")){
  234.  
  235. total = total+10;
  236.  
  237. System.out.println("Right answer!");
  238.  
  239. } else{
  240.  
  241. System.out.println("Wrong answer!");
  242.  
  243. }
  244.  
  245.  
  246. break;
  247.  
  248. default:
  249.  
  250. System.out.println("Invalid input, please try again.");
  251.  
  252. break;
  253.  
  254.  
  255. }
  256.  
  257.  
  258.  
  259. }
  260.  
  261. System.out.println("You grade is: " + total);
  262.  
  263. System.out.println("Have an excellent day");
  264. }
  265.  
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement