Advertisement
Sketchware

Gera nomes aleatórios de menino e menina e fala qual saiu mais

Jan 23rd, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1.  
  2. button.setOnClickListener(new View.OnClickListener() {
  3.     int menCount = 0;
  4.     int girlCount = 0;
  5.     int count = 0;
  6.     @Override
  7.     public void onClick(View view) {
  8.         count++;
  9.         // List of boy names
  10.         List<String> boyNames = Arrays.asList("João", "Pedro", "Carlos", "Lucas", "Rafael");
  11.         // List of girl names
  12.         List<String> girlNames = Arrays.asList("Maria", "Ana", "Juliana", "Carla", "Mariana");
  13.         Random rand = new Random();
  14.         // Generate a random number between 0 and 4
  15.         int randomNumber = rand.nextInt(5);
  16.         // Choose a random boy or girl name
  17.         String randomName = rand.nextBoolean() ? boyNames.get(randomNumber) : girlNames.get(randomNumber);
  18.         textView.setText(randomName);
  19.         if (boyNames.contains(randomName)) {
  20.             menCount++;
  21.         } else {
  22.             girlCount++;
  23.         }
  24.         if(count == 10){
  25.             if(menCount>girlCount){
  26.                 Toast.makeText(getApplicationContext(), "NOME DE HOMEM SAIU MAIS", Toast.LENGTH_SHORT).show();
  27.             }else{
  28.                 Toast.makeText(getApplicationContext(), "NOME DE MULHER SAIU MAIS", Toast.LENGTH_SHORT).show();
  29.             }
  30.         }
  31.     }
  32. });
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement