Q:

Need help making ArrayList

I am trying to create an ArrayList using at least six Person objects that will contain user inputted name and age resulting in information being printed out in alphabetical order.
Array list that contains person:
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Categorization  
{
    public static Scanner input = new Scanner(System.in);
    public static void main(String[] args) 
    {
        List<Person> people = new ArrayList<Person>();

        System.out.println("Please enter a name " + name); // Can't return values
        String nameEntry = input.toString();

        System.out.println("Please enter an age " + age);
        int ageEntry = input.nextInt();

    }
  }

I am unfamiliar with creating classes and feel like this is where most of my errors occur.
    class Person
    {
        private String name;
        private int age;

        public Person(String name, int age)
        {
            this.name = name;
            this.age = age;

        }

Tried to return name and age but they are not going back to the Public Class
        public String getName() 
        {
            return name;
        }

        public int getAge()
        {
            return age;
        }

    }

}

A:

You can try this:
public class Categorization {

    public static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {

        List<Person> people = new ArrayList<Person>();

        for(int i=1; i<=6; i++) {

            System.out.print("Please enter name for person " + i + " : ");
            String nameEntry = input.next();

            System.out.print("Please enter an age for person " + i + " : ");
            int ageEntry = input.nextInt();
            Person obj = new Person(nameEntry, ageEntry);
            people.add(obj);
        }

        System.out.println("List of entries you entered: ");
        for(Person obj: people) {
            System.out.println("Name: " + obj.getName() + " " + "Age: " + obj.getAge());
        }
    }

}

Output:

You need to create a Person object using new keyword to store respective values and then finally add it to the people list. 

