0
respostas

[Projeto] 07 Agenda de contatos

public class Contato {

private String nome;
private String telefone;

public Contato(String nome, String telefone) {
    this.nome = nome;
    this.telefone = telefone;
}

public String getNome() {
    return nome;
}

public String getTelefone() {
    return telefone;
}

}


import java.util.ArrayList;

public class Principal {

public static void main(String[] args) {

    ArrayList<Contato> contatos = new ArrayList<>();

    contatos.add(new Contato("João", "123456789"));
    contatos.add(new Contato("Maria", "987654321"));
    contatos.add(new Contato("Pedro", "555555555"));

    System.out.println("Contatos na agenda:");

    int indice = 1;
    for (Contato contato : contatos) {

        System.out.printf("%d . %s - %s\n", indice++,
                contato.getNome(),
                contato.getTelefone()
        );

    }

}

Output:

Contatos na agenda:
1 . João - 123456789
2 . Maria - 987654321
3 . Pedro - 555555555