import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
// To generate random information
Random random = new Random(); // necessary for this project
// To get the names and surnames .txt files in local directory
Scanner male = new Scanner(
new File("/storage/emulated/0/Download/male.txt")); // male names .txt
Scanner female = new Scanner(
new File("/storage/emulated/0/Download/female.txt")); // female names .txt
Scanner surname = new Scanner(
new File("/storage/emulated/0/Download/surnames.txt")); // surname lists .txt
// Each name and surname will be stored here for easier use
LinkedList<String> maleNames = new LinkedList<String>(); // male names
LinkedList<String> femaleNames = new LinkedList<String>(); // female names
LinkedList<String> surnameLists = new LinkedList<String>(); // surname lists
// Loops are used to automatically store each name and surname into the list
while (male.hasNext()) {
maleNames.add(male.next()); // auto store each male name into the list
}
while (female.hasNext()) {
femaleNames.add(female.next()); // auto store each female name into the list
}
while (surname.hasNext()) {
surnameLists.add(surname.next()); // auto store each surname into the list
}
// Sorting Elements is optional
surnameLists.sort(Comparator.naturalOrder()); // optional
femaleNames.sort(Comparator.naturalOrder()); // optional
maleNames.sort(Comparator.naturalOrder()); // optional
// Closing these objects is necessary
surname.close(); // necessary
female.close(); // necessary
male.close(); // necessary
// For loop is used to generate multiple information
for (int index = 0; index < 10000; index++) { // optional
String firstName = "", lastName = "", completeName = "", gender = ""; // temporary storage
byte age = (byte)(random.nextInt(99 - 18 + 1) + 18); // generates random age between 18 to 99 years old
// If boolean value is true, it is male
if (random.nextBoolean()) {
firstName += maleNames.get(random.nextInt(maleNames.size())); // generates random name
lastName += surnameLists.get(random.nextInt(surnameLists.size())); // generates random surname
firstName = (firstName.substring(0, 1).toUpperCase() + firstName.substring(1)); // uppercase first letter
lastName = (lastName.substring(0, 1).toUpperCase() + lastName.substring(1)); // uppercase first letter
completeName = firstName + " " + lastName; // creates a complete name
gender = "Male"; // sets the gender into male
// Otherwise, it is female
} else {
firstName += femaleNames.get(random.nextInt(femaleNames.size())); // generates random name
lastName += surnameLists.get(random.nextInt(surnameLists.size())); // generates random surname
firstName = (firstName.substring(0, 1).toUpperCase() + firstName.substring(1)); // uppercase first letter
lastName = (lastName.substring(0, 1).toUpperCase() + lastName.substring(1)); // uppercase first letter
completeName = firstName + " " + lastName; // creates a complete name
gender = "Female"; // sets the gender into female
}
// Finally, printing out the results
System.out.printf("Name: %s%nAge: %d%nSex: %s%n%n", completeName, age, gender);
}
}
}