Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. //**********************************************************
  2. // Nom: Marven Regimbald
  3. // Date: 2018-01-17
  4. // Description:
  5. //**********************************************************
  6. // Packages d'extension Java.
  7. import javax.swing.JOptionPane;
  8.  
  9.  
  10. public class ExamenMarvenRegimbald {
  11.  
  12. // La methode main debute l'execution de l'appl. Java.
  13. public static void main( String args[] ) {
  14.  
  15. int UnInt;
  16. int essai=0;
  17. int num=0;
  18. int num1;
  19. int num2;
  20. int op = 0;
  21. int somme = 0;
  22. String str1;
  23. boolean debugg =true ;
  24. boolean correct = false;
  25.  
  26. int count = 0; //stores how many correct answers
  27.  
  28. for(int i = 0; i < 10; i++)
  29. {
  30. num1 = (int) (Math.random() * 10 + 0);
  31. num2 = (int) (Math.random() * 10 + 0);
  32. op = (int) (Math.random() * 5 + 1);
  33.  
  34. int e = 0;
  35. correct = false;
  36.  
  37. while(e < 3 && !correct) {
  38. if (op == 1) {
  39. somme = num1 + num2;
  40. String input = JOptionPane.showInputDialog(null, "Quelle est la réponse de "+num1+" + "+num2+" = ");
  41. if (Integer.toString(somme).equals(input)){
  42. count++;
  43. correct = true;
  44. }
  45. else
  46. e++;
  47. } else
  48. if (op == 2){
  49. somme = num1 - num2;
  50. String input = JOptionPane.showInputDialog(null, "Quelle est la réponse de "+num1+" - "+num2+" = ");
  51. if (Integer.toString(somme).equals(input)){
  52. count++;
  53. correct = true;
  54. }
  55. else
  56. e++;
  57. }
  58. if (op == 3){
  59. somme = num1 * num2;
  60. String input = JOptionPane.showInputDialog(null, "Quelle est la réponse de "+num1+" * "+num2+" = ");
  61. if (Integer.toString(somme).equals(input)){
  62. count++;
  63. correct = true;
  64. }
  65. else
  66. e++;
  67. }
  68. if (op == 4){
  69. somme = num1 / num2;
  70. String input = JOptionPane.showInputDialog(null, "Quelle est la réponse de "+num1+" / "+num2+" = ");
  71. if (Integer.toString(somme).equals(input)){
  72. count++;
  73. correct = true;
  74. }
  75. else
  76. e++;
  77. }
  78. if (op == 5){
  79. somme = num1 % num2;
  80. String input = JOptionPane.showInputDialog(null, "Quelle est la réponse de "+num1+" % "+num2+" = ");
  81. if (Integer.toString(somme).equals(input)){
  82. count++;
  83. correct = true;
  84. }
  85. else
  86. e++;
  87. }
  88. }
  89. }
  90. System.out.println(count);
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement