Advertisement
Guest User

Random people test

a guest
Apr 23rd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. /**
  4.  *
  5.  * @author Home-pc
  6.  */
  7. public class RandomPeopleTest {
  8.     public static void main(String[] args) {
  9.         String[] manNames = new String[] {
  10.             "Andrey",
  11.             "Dmitry",
  12.             "Ivan",
  13.             "Petr",
  14.             "Slava",
  15.             "Victor",
  16.             "Robert",
  17.             "Eugene"
  18.         };
  19.        
  20.         String[] womanNames = new String[] {
  21.             "Lika",
  22.             "Elena",
  23.             "Anna",
  24.             "Nina",
  25.             "Vlada"
  26.         };
  27.        
  28.         Random rnd = new Random();
  29.        
  30.         for (int i = 0; i < 10; i++) {
  31.             boolean isMan = rnd.nextBoolean();
  32.             String name;
  33.             if (isMan) {
  34.                 int index = rnd.nextInt(manNames.length);
  35.                 name = manNames[index];
  36.             } else {
  37.                 int index = rnd.nextInt(womanNames.length);
  38.                 name = womanNames[index];
  39.             }
  40.             int age = 20+rnd.nextInt(20);
  41.            
  42.             Human h;
  43.             if (isMan) {
  44.                 h = new Man(name, age);
  45.             } else {
  46.                 h = new Woman(name, age);
  47.             }
  48.             System.out.println(h);
  49.         }
  50.        
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement