Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.57 KB | None | 0 0
  1. public class AdditionEasy extends AppCompatActivity {
  2.  
  3. int countCNumAddE = 0;
  4. int countWNumAddE = 0;
  5. boolean hasAnswered;
  6. public static final String MY_PREFS_NAME = "MyPrefsFile";
  7.  
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.addition);
  12.  
  13. final TextView count = (TextView) findViewById(R.id.Count);
  14. final TextView count2 = (TextView) findViewById(R.id.Count2);
  15. Button homeButton = (Button) findViewById(R.id.homeButton);
  16.  
  17. super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  18.  
  19. final TextView textOne = (TextView) findViewById(R.id.textView);
  20. final TextView textTwo = (TextView) findViewById(R.id.textView2);
  21. final Button pushMe1 = (Button) findViewById(R.id.button1);
  22. final Button pushMe2 = (Button) findViewById(R.id.button2);
  23. final Button pushMe3 = (Button) findViewById(R.id.button3);
  24. final Button pushMe4 = (Button) findViewById(R.id.button4);
  25.  
  26. final Button begin = (Button) findViewById(R.id.begin);
  27.  
  28.  
  29.  
  30. begin.setOnClickListener(new View.OnClickListener() {
  31. @Override
  32. public void onClick(View view) {
  33.  
  34.  
  35.  
  36.  
  37. hasAnswered = false;
  38.  
  39. pushMe1.setEnabled(true);
  40. pushMe2.setEnabled(true);
  41. pushMe3.setEnabled(true);
  42. pushMe4.setEnabled(true);
  43.  
  44. begin.setVisibility(View.INVISIBLE);
  45.  
  46. pushMe1.setVisibility(View.VISIBLE);
  47. pushMe2.setVisibility(View.VISIBLE);
  48. pushMe3.setVisibility(View.VISIBLE);
  49. pushMe4.setVisibility(View.VISIBLE);
  50.  
  51. pushMe1.setTextColor(Color.BLACK);
  52. pushMe2.setTextColor(Color.BLACK);
  53. pushMe3.setTextColor(Color.BLACK);
  54. pushMe4.setTextColor(Color.BLACK);
  55.  
  56. pushMe1.setTextSize(20);
  57. pushMe2.setTextSize(20);
  58. pushMe3.setTextSize(20);
  59. pushMe4.setTextSize(20);
  60.  
  61. textTwo.setText("");
  62.  
  63. String randGenChoice1 = "";
  64. String randGenChoice2 = "";
  65. String randGenChoice3 = "";
  66. String randGenChoice4 = "";
  67.  
  68. String randText2 = "";
  69. String randText3 = "";
  70.  
  71. Random RandomNum = new Random();
  72.  
  73. int randChoice1 = RandomNum.nextInt(40) + 1;
  74. int randChoice2 = RandomNum.nextInt(40) + 1;
  75. int randChoice3 = RandomNum.nextInt(40) + 1;
  76. int randChoice4 = RandomNum.nextInt(40) + 1;
  77.  
  78. int rando2 = RandomNum.nextInt(20) + 1;
  79. int rando3 = RandomNum.nextInt(20) + 1;
  80.  
  81. int pick = RandomNum.nextInt(4);
  82.  
  83. randGenChoice1 = Integer.toString(randChoice1);
  84. randGenChoice2 = Integer.toString(randChoice2);
  85. randGenChoice3 = Integer.toString(randChoice3);
  86. randGenChoice4 = Integer.toString(randChoice4);
  87.  
  88. randText2 = Integer.toString(rando2);
  89. randText3 = Integer.toString(rando3);
  90.  
  91. int value1;
  92. int value2;
  93. value1 = Integer.parseInt(randText2);
  94. value2 = Integer.parseInt(randText3);
  95. final int value = value1 + value2;
  96.  
  97. String line = randText2 + " + " + randText3;
  98. textOne.setText(line);
  99.  
  100. final String answer;
  101. answer = Integer.toString(value);
  102.  
  103. pushMe1.setText(randGenChoice1);
  104. pushMe2.setText(randGenChoice2);
  105. pushMe3.setText(randGenChoice3);
  106. pushMe4.setText(randGenChoice4);
  107.  
  108. Button[] choice = {pushMe1, pushMe2, pushMe3, pushMe4};
  109. Button display = choice[pick];
  110. display.setText(answer);
  111.  
  112. pushMe1.setOnClickListener(new View.OnClickListener() {
  113. @Override
  114. public void onClick(View view) {
  115.  
  116. int buttonAnswer = Integer.parseInt(pushMe1.getText().toString());
  117. if (buttonAnswer == value) {
  118.  
  119. begin.setVisibility(View.VISIBLE);
  120. textTwo.setText("Correct!");
  121. textTwo.setTextColor(Color.BLACK);
  122. pushMe1.setTextColor(Color.GREEN);
  123. pushMe1.setTextSize(30);
  124.  
  125. if (hasAnswered != true) {
  126. String AdditionEasyRight = Integer.toString(++countCNumAddE);
  127. count.setText(AdditionEasyRight);
  128. hasAnswered = true;
  129.  
  130. }
  131.  
  132. begin.setText("New Question");
  133. begin.setTextSize(20);
  134.  
  135. pushMe2.setVisibility(View.INVISIBLE);
  136. pushMe3.setVisibility(View.INVISIBLE);
  137. pushMe4.setVisibility(View.INVISIBLE);
  138.  
  139. pushMe1.setEnabled(false);
  140. pushMe2.setEnabled(false);
  141. pushMe3.setEnabled(false);
  142. pushMe4.setEnabled(false);
  143.  
  144. }else{
  145. textTwo.setText("Wrong!");
  146. textTwo.setTextColor(Color.BLACK);
  147. pushMe1.setTextColor(Color.RED);
  148. pushMe1.setTextSize(30);
  149.  
  150. if (hasAnswered != true) {
  151. String AdditionEasyWrong = Integer.toString(++countWNumAddE);
  152. count2.setText(AdditionEasyWrong);
  153. hasAnswered = true;
  154. }
  155.  
  156. pushMe1.setEnabled(false);
  157.  
  158.  
  159. }
  160. }
  161.  
  162.  
  163. });
  164. pushMe2.setOnClickListener(new View.OnClickListener() {
  165. @Override
  166. public void onClick(View view) {
  167.  
  168. int buttonAnswer = Integer.parseInt(pushMe2.getText().toString());
  169. if (buttonAnswer == value) {
  170.  
  171. begin.setVisibility(View.VISIBLE);
  172. textTwo.setText("Correct!");
  173. textTwo.setTextColor(Color.BLACK);
  174. pushMe2.setTextColor(Color.GREEN);
  175. pushMe2.setTextSize(30);
  176.  
  177. if (hasAnswered != true) {
  178. String AdditionEasyRight = Integer.toString(++countCNumAddE);
  179. count.setText(AdditionEasyRight);
  180. hasAnswered = true;
  181. }
  182.  
  183. begin.setText("New Question");
  184. begin.setTextSize(20);
  185.  
  186. pushMe1.setVisibility(View.INVISIBLE);
  187. pushMe3.setVisibility(View.INVISIBLE);
  188. pushMe4.setVisibility(View.INVISIBLE);
  189.  
  190. pushMe1.setEnabled(false);
  191. pushMe2.setEnabled(false);
  192. pushMe3.setEnabled(false);
  193. pushMe4.setEnabled(false);
  194.  
  195. }else{
  196. textTwo.setText("Wrong!");
  197. textTwo.setTextColor(Color.BLACK);
  198. pushMe2.setTextColor(Color.RED);
  199. pushMe2.setTextSize(30);
  200.  
  201. if (hasAnswered != true) {
  202. String AdditionEasyWrong = Integer.toString(++countWNumAddE);
  203. count2.setText(AdditionEasyWrong);
  204. hasAnswered = true;
  205. }
  206.  
  207. pushMe2.setEnabled(false);
  208.  
  209.  
  210. }
  211.  
  212.  
  213. }
  214. });
  215. pushMe3.setOnClickListener(new View.OnClickListener() {
  216. @Override
  217. public void onClick(View view) {
  218.  
  219. int buttonAnswer = Integer.parseInt(pushMe3.getText().toString());
  220. if (buttonAnswer == value) {
  221.  
  222. begin.setVisibility(View.VISIBLE);
  223. textTwo.setText("Correct!");
  224. textTwo.setTextColor(Color.BLACK);
  225. pushMe3.setTextColor(Color.GREEN);
  226. pushMe3.setTextSize(30);
  227.  
  228. if (hasAnswered != true) {
  229. String AdditionEasyRight = Integer.toString(++countCNumAddE);
  230. count.setText(AdditionEasyRight);
  231. hasAnswered = true;
  232. }
  233.  
  234. begin.setText("New Question");
  235. begin.setTextSize(20);
  236.  
  237. pushMe1.setVisibility(View.INVISIBLE);
  238. pushMe2.setVisibility(View.INVISIBLE);
  239. pushMe4.setVisibility(View.INVISIBLE);
  240.  
  241. pushMe1.setEnabled(false);
  242. pushMe2.setEnabled(false);
  243. pushMe3.setEnabled(false);
  244. pushMe4.setEnabled(false);
  245.  
  246. }else{
  247. textTwo.setText("Wrong!");
  248. textTwo.setTextColor(Color.BLACK);
  249. pushMe3.setTextColor(Color.RED);
  250. pushMe3.setTextSize(30);
  251.  
  252. if (hasAnswered != true) {
  253. String AdditionEasyWrong = Integer.toString(++countWNumAddE);
  254. count2.setText(AdditionEasyWrong);
  255. hasAnswered = true;
  256. }
  257.  
  258. pushMe3.setEnabled(false);
  259.  
  260. }
  261.  
  262.  
  263. }
  264. });
  265. pushMe4.setOnClickListener(new View.OnClickListener() {
  266. @Override
  267. public void onClick(View view) {
  268.  
  269. int buttonAnswer = Integer.parseInt(pushMe4.getText().toString());
  270. if (buttonAnswer == value) {
  271.  
  272. begin.setVisibility(View.VISIBLE);
  273. textTwo.setText("Correct!");
  274. textTwo.setTextColor(Color.BLACK);
  275. pushMe4.setTextColor(Color.GREEN);
  276. pushMe4.setTextSize(30);
  277.  
  278. if (hasAnswered != true) {
  279. String AdditionEasyRight = Integer.toString(++countCNumAddE);
  280. count.setText(AdditionEasyRight);
  281. hasAnswered = true;
  282. }
  283.  
  284. begin.setText("New Question");
  285. begin.setTextSize(20);
  286.  
  287. pushMe1.setVisibility(View.INVISIBLE);
  288. pushMe2.setVisibility(View.INVISIBLE);
  289. pushMe3.setVisibility(View.INVISIBLE);
  290.  
  291. pushMe1.setEnabled(false);
  292. pushMe2.setEnabled(false);
  293. pushMe3.setEnabled(false);
  294. pushMe4.setEnabled(false);
  295.  
  296. }else{
  297. textTwo.setText("Wrong!");
  298. textTwo.setTextColor(Color.BLACK);
  299. pushMe4.setTextColor(Color.RED);
  300. pushMe4.setTextSize(30);
  301.  
  302. if (hasAnswered != true) {
  303. String AdditionEasyWrong = Integer.toString(++countWNumAddE);
  304. count2.setText(AdditionEasyWrong);
  305. hasAnswered = true;
  306. }
  307.  
  308. pushMe4.setEnabled(false);
  309.  
  310.  
  311.  
  312. }
  313.  
  314. }
  315. });
  316.  
  317.  
  318.  
  319. }
  320. });
  321.  
  322. homeButton.setOnClickListener(new View.OnClickListener() {
  323. @Override
  324. public void onClick(View view) {
  325.  
  326. Intent homepage = new Intent(AdditionEasy.this , Menu.class);
  327. startActivity(homepage);
  328.  
  329. }
  330.  
  331.  
  332. });
  333.  
  334. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement