arraylist with method

As my last question obviously was a little bit unclear (I applogise for that), I'm making a new try, and this time I will really try to be clear.

Here is the code I have written so far

Main class:

import java.util.*;

public class Head {
public static void main(String[] args) {
    Scanner scan = new Scanner(;

    String fname, lname;
    int choice;

    ArrayList<People>list = new ArrayList<>();

    People p1 = new People("Mia", "Wallace", "1111");
    People p2 = new People("Marcellus", "Wallace", "2222");



    System.out.println("1) Add person \n2) Last name \n3) Print list");
    choice = scan.nextInt();
    case 1:
        People.walk(); //calling the method
    case 2:;
    case 3:

People class:

import java.util.*;

public class People {
static Scanner scan = new Scanner(;

private static String fname;
private static String lname;
private static String dob;

public People(String fname, String lname, String dob){
    this.fname = fname;
    this.lname = lname;
    this.dob = dob;
public String getFname(){
    return fname;
public String getLname(){
    return lname;
public String getDob(){
    return dob;
public static void walk(){
    System.out.println("Enter first name: ");
    fname =;
    System.out.println("Enter last name: ");
    lname =;
    System.out.println("Enter dob: ");
    dob =;
    list.add(new People(fname, lname, dob));  **//list cannot be resolved**     
public static void run(){
    System.out.println("Remove people");        
public static void crawl(){
    int peoplenumber = 0;
    System.out.println("\nNumber of peoples: " + list.size()); **//list cannot     be resolved**
    for(People p : list){ **//list cannot be resolved**
        peoplenumber += 1;
        System.out.println("#" + peoplenumber + "\n" + p.toString());
public String toString(){
    return "First name: " + this.fname + "\nLast name: " + this.lname + "\nDateOfBirth: " + this.dob;

I do understand why I get the error, but I don't know how to get around it. Any help?

Am I right when I try to move code from the main-class to the costructors?

If you guys have any comments or ideas how I should solve this, or move on with java, I will gladly here them.

Thank you very much for your time and your help :)


The arraylist should be in the main class. If it were in the person class, it would be created once for every person object you create. To access a method for that person, you want to call the name of the OBJECT (not the type), the .method(parameters).

If you wanted to call run on p1 (not really sure what you want to call it on), you would use:;

That would perform the code in the run method where it is defined.

Need Your Help

How to convert a char[] to a std::string


I´m trying to convert a char[] into a std::string. Everywhere I looked, I found the same answer, that string has a constructor doing this exact thing.

How to update chart when data is changing?

excel vba excel-vba charts onchange

I have two columns were is information that I use in chart and it is changing according to what time range I choose. The main problem is that the columns length can be different, it can be 5 rows and