0% found this document useful (0 votes)
39 views

Week 4: Android:Text Android:Onclick

This document provides steps and code for a mobile application that performs math calculations. It generates random numbers for addition problems, displays the numbers, and allows the user to enter their answer. The application then checks if the user's answer matches the sum of the random numbers and displays whether the answer is correct or wrong. The code uses buttons to generate new numbers and check the answer, and retrieves the random numbers and user input from text views and edit texts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Week 4: Android:Text Android:Onclick

This document provides steps and code for a mobile application that performs math calculations. It generates random numbers for addition problems, displays the numbers, and allows the user to enter their answer. The application then checks if the user's answer matches the sum of the random numbers and displays whether the answer is correct or wrong. The code uses buttons to generate new numbers and check the answer, and retrieves the random numbers and user input from text views and edit texts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

DFP 6223 MOBILE APPLICATION DEVELOPMENT

--------------------------------------------------------------------------------------------------------------------------------------
WEEK 4

MATH CALCULATION

Step 1

Step 2 Button 1

android:text="another number"
android:onClick="next"

Step 3 Button 2

android:onClick="result"
android:text="Check Result"

Step 4 File *java

public void next(View v) {


EditText clear1 = (EditText) findViewById(R.id.editText1);
clear1.setText("");

Random randomGen = new Random();

int random1 =randomGen.nextInt(100);


int random2 =randomGen.nextInt(100);
jwp = random1 + random2;

TextView num1 = (TextView) findViewById(R.id.textView1);


num1.setText(Integer.toString(random1));

BY: PN FARIHAN ELYANA BT ZAHARI


DFP 6223 MOBILE APPLICATION DEVELOPMENT
--------------------------------------------------------------------------------------------------------------------------------------
TextView num2 = (TextView) findViewById(R.id.textView4);
num2.setText(Integer.toString(random2));
}

public void result(View v){

EditText value1 = (EditText) findViewById(R.id.editText1);


int jwpUser = Integer.parseInt(value1.getText().toString());

TextView display = (TextView) findViewById(R.id.textView5);

if (jwpUser == jwp)
display.setText("CORRECT");
else
display.setText("WRONG");

BY: PN FARIHAN ELYANA BT ZAHARI

You might also like