Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AdditionEasy extends AppCompatActivity {
- int countCNumAddE = 0;
- int countWNumAddE = 0;
- boolean hasAnswered;
- public static final String MY_PREFS_NAME = "MyPrefsFile";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.addition);
- final TextView count = (TextView) findViewById(R.id.Count);
- final TextView count2 = (TextView) findViewById(R.id.Count2);
- Button homeButton = (Button) findViewById(R.id.homeButton);
- super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- final TextView textOne = (TextView) findViewById(R.id.textView);
- final TextView textTwo = (TextView) findViewById(R.id.textView2);
- final Button pushMe1 = (Button) findViewById(R.id.button1);
- final Button pushMe2 = (Button) findViewById(R.id.button2);
- final Button pushMe3 = (Button) findViewById(R.id.button3);
- final Button pushMe4 = (Button) findViewById(R.id.button4);
- final Button begin = (Button) findViewById(R.id.begin);
- begin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- hasAnswered = false;
- pushMe1.setEnabled(true);
- pushMe2.setEnabled(true);
- pushMe3.setEnabled(true);
- pushMe4.setEnabled(true);
- begin.setVisibility(View.INVISIBLE);
- pushMe1.setVisibility(View.VISIBLE);
- pushMe2.setVisibility(View.VISIBLE);
- pushMe3.setVisibility(View.VISIBLE);
- pushMe4.setVisibility(View.VISIBLE);
- pushMe1.setTextColor(Color.BLACK);
- pushMe2.setTextColor(Color.BLACK);
- pushMe3.setTextColor(Color.BLACK);
- pushMe4.setTextColor(Color.BLACK);
- pushMe1.setTextSize(20);
- pushMe2.setTextSize(20);
- pushMe3.setTextSize(20);
- pushMe4.setTextSize(20);
- textTwo.setText("");
- String randGenChoice1 = "";
- String randGenChoice2 = "";
- String randGenChoice3 = "";
- String randGenChoice4 = "";
- String randText2 = "";
- String randText3 = "";
- Random RandomNum = new Random();
- int randChoice1 = RandomNum.nextInt(40) + 1;
- int randChoice2 = RandomNum.nextInt(40) + 1;
- int randChoice3 = RandomNum.nextInt(40) + 1;
- int randChoice4 = RandomNum.nextInt(40) + 1;
- int rando2 = RandomNum.nextInt(20) + 1;
- int rando3 = RandomNum.nextInt(20) + 1;
- int pick = RandomNum.nextInt(4);
- randGenChoice1 = Integer.toString(randChoice1);
- randGenChoice2 = Integer.toString(randChoice2);
- randGenChoice3 = Integer.toString(randChoice3);
- randGenChoice4 = Integer.toString(randChoice4);
- randText2 = Integer.toString(rando2);
- randText3 = Integer.toString(rando3);
- int value1;
- int value2;
- value1 = Integer.parseInt(randText2);
- value2 = Integer.parseInt(randText3);
- final int value = value1 + value2;
- String line = randText2 + " + " + randText3;
- textOne.setText(line);
- final String answer;
- answer = Integer.toString(value);
- pushMe1.setText(randGenChoice1);
- pushMe2.setText(randGenChoice2);
- pushMe3.setText(randGenChoice3);
- pushMe4.setText(randGenChoice4);
- Button[] choice = {pushMe1, pushMe2, pushMe3, pushMe4};
- Button display = choice[pick];
- display.setText(answer);
- pushMe1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int buttonAnswer = Integer.parseInt(pushMe1.getText().toString());
- if (buttonAnswer == value) {
- begin.setVisibility(View.VISIBLE);
- textTwo.setText("Correct!");
- textTwo.setTextColor(Color.BLACK);
- pushMe1.setTextColor(Color.GREEN);
- pushMe1.setTextSize(30);
- if (hasAnswered != true) {
- String AdditionEasyRight = Integer.toString(++countCNumAddE);
- count.setText(AdditionEasyRight);
- hasAnswered = true;
- }
- begin.setText("New Question");
- begin.setTextSize(20);
- pushMe2.setVisibility(View.INVISIBLE);
- pushMe3.setVisibility(View.INVISIBLE);
- pushMe4.setVisibility(View.INVISIBLE);
- pushMe1.setEnabled(false);
- pushMe2.setEnabled(false);
- pushMe3.setEnabled(false);
- pushMe4.setEnabled(false);
- }else{
- textTwo.setText("Wrong!");
- textTwo.setTextColor(Color.BLACK);
- pushMe1.setTextColor(Color.RED);
- pushMe1.setTextSize(30);
- if (hasAnswered != true) {
- String AdditionEasyWrong = Integer.toString(++countWNumAddE);
- count2.setText(AdditionEasyWrong);
- hasAnswered = true;
- }
- pushMe1.setEnabled(false);
- }
- }
- });
- pushMe2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int buttonAnswer = Integer.parseInt(pushMe2.getText().toString());
- if (buttonAnswer == value) {
- begin.setVisibility(View.VISIBLE);
- textTwo.setText("Correct!");
- textTwo.setTextColor(Color.BLACK);
- pushMe2.setTextColor(Color.GREEN);
- pushMe2.setTextSize(30);
- if (hasAnswered != true) {
- String AdditionEasyRight = Integer.toString(++countCNumAddE);
- count.setText(AdditionEasyRight);
- hasAnswered = true;
- }
- begin.setText("New Question");
- begin.setTextSize(20);
- pushMe1.setVisibility(View.INVISIBLE);
- pushMe3.setVisibility(View.INVISIBLE);
- pushMe4.setVisibility(View.INVISIBLE);
- pushMe1.setEnabled(false);
- pushMe2.setEnabled(false);
- pushMe3.setEnabled(false);
- pushMe4.setEnabled(false);
- }else{
- textTwo.setText("Wrong!");
- textTwo.setTextColor(Color.BLACK);
- pushMe2.setTextColor(Color.RED);
- pushMe2.setTextSize(30);
- if (hasAnswered != true) {
- String AdditionEasyWrong = Integer.toString(++countWNumAddE);
- count2.setText(AdditionEasyWrong);
- hasAnswered = true;
- }
- pushMe2.setEnabled(false);
- }
- }
- });
- pushMe3.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int buttonAnswer = Integer.parseInt(pushMe3.getText().toString());
- if (buttonAnswer == value) {
- begin.setVisibility(View.VISIBLE);
- textTwo.setText("Correct!");
- textTwo.setTextColor(Color.BLACK);
- pushMe3.setTextColor(Color.GREEN);
- pushMe3.setTextSize(30);
- if (hasAnswered != true) {
- String AdditionEasyRight = Integer.toString(++countCNumAddE);
- count.setText(AdditionEasyRight);
- hasAnswered = true;
- }
- begin.setText("New Question");
- begin.setTextSize(20);
- pushMe1.setVisibility(View.INVISIBLE);
- pushMe2.setVisibility(View.INVISIBLE);
- pushMe4.setVisibility(View.INVISIBLE);
- pushMe1.setEnabled(false);
- pushMe2.setEnabled(false);
- pushMe3.setEnabled(false);
- pushMe4.setEnabled(false);
- }else{
- textTwo.setText("Wrong!");
- textTwo.setTextColor(Color.BLACK);
- pushMe3.setTextColor(Color.RED);
- pushMe3.setTextSize(30);
- if (hasAnswered != true) {
- String AdditionEasyWrong = Integer.toString(++countWNumAddE);
- count2.setText(AdditionEasyWrong);
- hasAnswered = true;
- }
- pushMe3.setEnabled(false);
- }
- }
- });
- pushMe4.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int buttonAnswer = Integer.parseInt(pushMe4.getText().toString());
- if (buttonAnswer == value) {
- begin.setVisibility(View.VISIBLE);
- textTwo.setText("Correct!");
- textTwo.setTextColor(Color.BLACK);
- pushMe4.setTextColor(Color.GREEN);
- pushMe4.setTextSize(30);
- if (hasAnswered != true) {
- String AdditionEasyRight = Integer.toString(++countCNumAddE);
- count.setText(AdditionEasyRight);
- hasAnswered = true;
- }
- begin.setText("New Question");
- begin.setTextSize(20);
- pushMe1.setVisibility(View.INVISIBLE);
- pushMe2.setVisibility(View.INVISIBLE);
- pushMe3.setVisibility(View.INVISIBLE);
- pushMe1.setEnabled(false);
- pushMe2.setEnabled(false);
- pushMe3.setEnabled(false);
- pushMe4.setEnabled(false);
- }else{
- textTwo.setText("Wrong!");
- textTwo.setTextColor(Color.BLACK);
- pushMe4.setTextColor(Color.RED);
- pushMe4.setTextSize(30);
- if (hasAnswered != true) {
- String AdditionEasyWrong = Integer.toString(++countWNumAddE);
- count2.setText(AdditionEasyWrong);
- hasAnswered = true;
- }
- pushMe4.setEnabled(false);
- }
- }
- });
- }
- });
- homeButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent homepage = new Intent(AdditionEasy.this , Menu.class);
- startActivity(homepage);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement