reenadak

2018-12-22-android-higher-or-lower-number

Dec 21st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package com.mukeshdak.higher_or_lower;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.EditText;
  7. import android.widget.Toast;
  8.  
  9. import java.util.Random;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13.     Random rand = new Random();
  14.     public int rand1 = rand.nextInt(20);
  15.     public String msg;
  16.  
  17.     public void funGuess(View view){
  18.        EditText et1 = (EditText) findViewById(R.id.editText1);
  19.        String str = et1.getText().toString();
  20.         int intNum = Integer.parseInt(str);
  21.         String str_rand1 = Integer.toString(rand1);
  22.  
  23.         msg = "no message is set";
  24.  
  25.  
  26.         if( rand1 > intNum ) {
  27.             msg = "Guess Higher number";
  28.         } else if ( rand1 < intNum ){
  29.             msg = "Guess Lower number";
  30.         } else {
  31.             msg = "Congratulations !!!!\nYou have made this happen\n\nTry Again";
  32.             rand1 = rand.nextInt(20);
  33.         }
  34.  
  35.         Toast.makeText(this, msg, 1).show();
  36.     }
  37.  
  38.     @Override
  39.     protected void onCreate(Bundle savedInstanceState) {
  40.         super.onCreate(savedInstanceState);
  41.         setContentView(R.layout.activity_main);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment