Last active
March 26, 2018 11:38
-
-
Save marufmax/02e9622a4941798872add7c5ea92b6ae to your computer and use it in GitHub Desktop.
Android Random Number Guessing Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.marufalom.calculator; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import java.util.Random; | |
public class MainActivity extends AppCompatActivity { | |
int randomNumber; | |
public void guess(View view) { | |
EditText numberInput = (EditText) findViewById(R.id.numberInput); | |
int numberInt = Integer.parseInt(numberInput.getText().toString()); | |
if (numberInt > randomNumber) { | |
Toast.makeText(MainActivity.this, "Lower", Toast.LENGTH_SHORT).show(); | |
} else if (numberInt < randomNumber) { | |
Toast.makeText(MainActivity.this, "Higher", Toast.LENGTH_SHORT).show(); | |
} else { | |
Toast.makeText(MainActivity.this, "Correct! Lucky you.. Try Again", Toast.LENGTH_SHORT).show(); | |
Random random = new Random(); | |
randomNumber = random.nextInt(50)+1; | |
} | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Random random = new Random(); | |
randomNumber = random.nextInt(50)+1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment