Edwin Mhoy Silva Edwin Mhoy Silva - 1 year ago 55
Java Question

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

A school needs a system to manage the persons related to the school. All persons has an id number, a name, and an email address.
Beside this, all students has registered a grade-Report, which is a list containing all the grades obtained at the school. A Grade in the list is composed of subject name and the obtained grade.
All teachers has a list of subjects, they can teach, and their salary and initials are registered too.
A class hierarchy for the persons at the school is shown below:

Exercise 1
Implement the Person class.
Add a class to the project, that can test the Person class.
The test class should have a list of Person type. Now add 3 person objects to the list.
Use a loop to print out information about the 3 persons using the person’s toString() method.
enter image description here

Answer Source
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", "philipemail@email.com");
    Persons steve = new Persons(2, "Steve", "steveemail@email.com");
    Persons samatha = new Persons(3, "Samatha", "samathaemail.com");

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

    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: philipemail@email.com ID number: 2 Name: Steve Email: steveemail@email.com ID number: 3 Name: Samatha Email: samathaemail.com

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download