jakiro

Temp higher or lower

Mar 19th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package com.example.uorjaipur.higherorlower;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.EditText;
  8. import android.widget.Toast;
  9.  
  10. import java.util.Random;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.  
  14.     Random random = new Random();
  15.     int randNum = random.nextInt(19) + 1;
  16.    
  17.     public void guess(View view){
  18.  
  19.  
  20.         EditText editText = (EditText) findViewById(R.id.editText);
  21.         int numInput = Integer.parseInt(editText.getText().toString());
  22.  
  23.         //Log.i("Variable type",editText.getText().getClass().toString());
  24.         //Log.i("EditText",editText.getText().toString())
  25.         //Log.i("int value",Integer.toString(randNum));
  26.         Log.i("Random number",Integer.toString(randNum));
  27.  
  28.         if (numInput==randNum){
  29.             Toast.makeText(this, "You've got the right number : "+randNum, Toast.LENGTH_LONG).show();
  30.         } else if (numInput>randNum){
  31.             Toast.makeText(this, "Lower", Toast.LENGTH_SHORT).show();
  32.         } else{
  33.             Toast.makeText(this, "Higher", Toast.LENGTH_SHORT).show();
  34.         }
  35.     }
Add Comment
Please, Sign In to add comment