Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- /**
- *
- * @author Home-pc
- */
- public class RandomPeopleTest {
- public static void main(String[] args) {
- String[] manNames = new String[] {
- "Andrey",
- "Dmitry",
- "Ivan",
- "Petr",
- "Slava",
- "Victor",
- "Robert",
- "Eugene"
- };
- String[] womanNames = new String[] {
- "Lika",
- "Elena",
- "Anna",
- "Nina",
- "Vlada"
- };
- Random rnd = new Random();
- for (int i = 0; i < 10; i++) {
- boolean isMan = rnd.nextBoolean();
- String name;
- if (isMan) {
- int index = rnd.nextInt(manNames.length);
- name = manNames[index];
- } else {
- int index = rnd.nextInt(womanNames.length);
- name = womanNames[index];
- }
- int age = 20+rnd.nextInt(20);
- Human h;
- if (isMan) {
- h = new Man(name, age);
- } else {
- h = new Woman(name, age);
- }
- System.out.println(h);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement