Android : Jeux Trouver un Nombre

Générer un nombre aléatoire puis essayer de le trouver

1.Layout

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFEB3B" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start"
android:backgroundTint="#E91E63"
android:textSize="35dp"
android:id="@+id/nstart"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:inputType="number"
android:textSize="40dp"
android:gravity="center"
android:hint="Enter un nombre"
android:id="@+id/nnombre"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Trouver"
android:backgroundTint="#0E980E"
android:textSize="35dp"
android:id="@+id/nbutton"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="message"
android:gravity="center"
android:textSize="30dp"
android:id="@+id/nmessage"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="88dp"
android:text="0"
android:textColor="#f00"
android:id="@+id/nessaye"/>

</LinearLayout>


2.Java



import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import org.w3c.dom.Text;

public class TrouverNombre extends AppCompatActivity implements View.OnClickListener{
EditText nmombre;
Button btrouver,nstart;
TextView nmessage,nessaye;
int n=0,essaye=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trouver_nombre);
nmombre=findViewById(R.id.nnombre);
nmessage=findViewById(R.id.nnombre);
btrouver=findViewById(R.id.nbutton);
nstart=findViewById(R.id.nstart);
nmessage=findViewById(R.id.nmessage);
nessaye=findViewById(R.id.nessaye);

btrouver.setOnClickListener(this);
nstart.setOnClickListener(this);
}

@Override
public void onClick(View view) {
if(view.getId()==nstart.getId())
{
essaye=0;
n=(int)(Math.random()*100);
}
if(view.getId()==btrouver.getId())
{
essaye++;
nessaye.setText(""+essaye);
int a=Integer.parseInt(nmombre.getText().toString());
if(n>a){
nmessage.setText("Plus Grand");
}
else if(n<a){
nmessage.setText("Plus petit");
}
else {
nmessage.setText("You Win");
}

}
}
}