Hi I am having trouble with Array Lists. What should the for loop header be for filling Array Lists?
I am trying to use an explicit value Constant Names in the condition.
Any help would be greatly appreciated. Thank you.
Here is my code.
< public class PersonTester { public static void main(String[] args) { PersonTester tester = new PersonTester(); // ArrayList<Person> persons = new ArrayList<Person>(20); String ELEMENT = ""; for (int i = 0;i<ELEMENT.length(); i++) { char gender = tester.getRandomGender(); String fName = tester.getRandomFirstName(gender); String lName = tester.getRandomLastName(); int age = tester.getRandomAge(); ArrayList<Person> persons = new ArrayList<Person>(20); persons[i] = new Person(fName, lName, gender, age); persons.size(); //ArrayList<Person>people = new ArrayList<Person>(fName, lName, gender, age); System.out.println(persons); } } private char getRandomGender() { return Math.random() > 0.5? 'f':'m'; } private String getRandomFirstName(char gender) { String firstName = ""; if (gender == 'f') { firstName = femaleFirstNames[SingleRandom.getInstance(). nextInt(femaleFirstNames.length)]; } else { firstName = maleFirstNames[SingleRandom.getInstance(). nextInt(maleFirstNames.length)]; } return firstName; } private String getRandomLastName() { return lastNames[SingleRandom.getInstance().nextInt(lastNames.length)]; } private int getRandomAge() { return SingleRandom.getInstance().nextInt(99) + 1; } >