[Solved] I need to create an array list in java i think?


public class Persons {

int id;//persons id
String name;//persons name
String email;//persons email

public Persons(int idNum, String student, String eAddress){
    this.id = idNum;
    this.name = student;
    this.email = eAddress;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
 * Id number
 * @return  integer of the id
 */
public int getId(){
    return id;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
 * name of person
 * @return  string of the name
 */
public String getName(){
    return name;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
 * Email address for person
 * @return string of the email
 */
public String getEmail(){
    return email;
} 
}

That’s the person class with the 3 pieces of data. I’m not sure what to do with the other data in your question. Not sure if it is relevant. The following is the tester class.

import java.util.ArrayList;

public class Tester{
public static void main(String[] args){
    Persons philip = new Persons(1, "Philip", "[email protected]");
    Persons steve = new Persons(2, "Steve", "[email protected]");
    Persons samatha = new Persons(3, "Samatha", "samathaemail.com");

    ArrayList<Persons> list = new ArrayList<>();
    list.add(philip);
    list.add(steve);
    list.add(samatha);

    for(int i=0;i<3;i++){
        System.out.println("ID number: " + list.get(i).getId());
        System.out.println("Name: " + list.get(i).getName());
        System.out.println("Email: " + list.get(i).getEmail());
    }
}
}

This then creates the following output.

ID number: 1
Name: Philip
Email: [email protected]
ID number: 2
Name: Steve
Email: [email protected]
ID number: 3
Name: Samatha
Email: samathaemail.com

2

solved I need to create an array list in java i think?