I have a Java program that stores a max of 10 arrayList items of both name (String) and age (integer), the program accepts a max of 10 items unless the user enters 'done' or 'DONE', then outputs the items of the Array.
After the array output, I now want the program to output the youngest and oldest members of the array.
I can't seem to work out how to fetch this data and display it.
Any suggestions?
Thank you.
import java.util.Scanner;
import javafx.util.Pair;
import java.util.ArrayList;
import java.util.List;
public class AgeName {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
List<Pair<String, Integer>> names = new ArrayList<>();
for (int i = 0; i < 10; i++) {
System.out.print("Enter name " + (i + 1) + ": ");
String line = input.nextLine();
if (line.toUpperCase().equals("DONE"))
break;
System.out.print("Enter age for user " + line + ": ");
Integer age = Integer.parseInt(input.nextLine());
names.add(new Pair<String, Integer>(line, age));
}
System.out.print("\n");
System.out.print("Names are: " + names );
}
}