Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mukeshdak.higher_or_lower;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- import java.util.Random;
- public class MainActivity extends AppCompatActivity {
- Random rand = new Random();
- public int rand1 = rand.nextInt(20);
- public String msg;
- public void funGuess(View view){
- EditText et1 = (EditText) findViewById(R.id.editText1);
- String str = et1.getText().toString();
- int intNum = Integer.parseInt(str);
- String str_rand1 = Integer.toString(rand1);
- msg = "no message is set";
- if( rand1 > intNum ) {
- msg = "Guess Higher number";
- } else if ( rand1 < intNum ){
- msg = "Guess Lower number";
- } else {
- msg = "Congratulations !!!!\nYou have made this happen\n\nTry Again";
- rand1 = rand.nextInt(20);
- }
- Toast.makeText(this, msg, 1).show();
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment