As user Bradimus mentioned in the comments, this is perfect for using classes.
If you look at the data in your file they are all the "same" type - every line has a first name, surname, age, weight and height. You can bundle them into an object and make them easier to use in your code.
Example:
public class Person {
public String firstName;
public String surname;
public int age;
public int height;
public int weight;
public Person(String input) {
//You can parse the input here. One 'input' is for example "Gordon, Byron, 37, 82, 178"
String[] splitString = input.split(", ");
this.firstName = splitString[0];
this.surname = splitString[1];
this.age = Integer.parseInt(splitString[2]);
this.height = Integer.parseInt(splitString[3]);
this.weight = Integer.parseInt(splitString[4]);
}
}
Then in your main class, you can just add them to an list like so. I added an example for how to calculate the oldest person, you can copy this logic (iterate over all the persons in the personList, perform check, return desired result) for the other tasks.
// Other code
public static void main(String[] args) {
List<People> peopleList = new ArrayList<>();
File file = new File("/Users/Len/Desktop/TextReader/src/example.txt");
try {
Scanner input = new Scanner(file);
while (input.hasNext()) {
String num = input.nextLine();
System.out.println(num);
peopleList.add(new Person(num));
} catch (FileNotFoundException e) {
System.err.format("File Does Not Exist\n");
}
Person oldestPerson = getOldestPerson(peopleList);
System.out.println("Oldest person: " + oldestPerson.firstName + " " + oldestPerson.surname);
}
public static Person getOldestPerson(List<Person> people) {
Person oldestPerson = null;
for (Person person: people) {
if (oldestPerson == null || person.age > oldestPerson.age) {
oldestPerson = person;
}
}
return oldestPerson;
}
Personobject to hold your data.