I'm using a random number generator and IF Statements to switch between activities. It iterates through the first if statement and stops there. I don't think my random number generator is generating any random numbers. Thanks in advance.
package app.com.example.android.oraclethedeciscionmaker;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import java.util.Random;
public class HomeScreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
}
public void onClick(View view){
Random guess = new Random();
int guesser0 = guess.nextInt(0) + 1;
int guesser1 = guess.nextInt(0) + 1;
int guesser2 = guess.nextInt(0) + 1;
int guesser3 = guess.nextInt(0) + 1;
int guesser4 = guess.nextInt(0) + 1;
int result = guesser0 + guesser1 + guesser2 + guesser3 + guesser4;
// 0 out of 0
if(result == 0){
Intent intent = new Intent(HomeScreen.this, ZeroOfFive.class);
startActivity(intent);
// If this statement is true go to this activity
}
// 1 out of 5
else if(result == 1){
Intent intent = new Intent(HomeScreen.this, OneOfFive.class);
startActivity(intent);
// If this statement is true go to this activity
}
//2 out of 5
else if(result == 2){
Intent intent = new Intent(HomeScreen.this, TwoOfFive.class);
startActivity(intent);
// If this statement is true go to this activity
}
//3 out of 5
else if(result == 3){
Intent intent = new Intent(HomeScreen.this, ThreeOfFive.class);
startActivity(intent);
// If this statement is true go to this activity
}
//4 out of 5
else if(result == 4){
Intent intent = new Intent(HomeScreen.this, FourOfFive.class);
startActivity(intent);
// If this statement is true go to this activity
}
//5 out of 5
else {
Intent intent = new Intent(HomeScreen.this, FiveOfFive.class);
startActivity(intent);
}
}
}
Aucun commentaire:
Enregistrer un commentaire