Skip to content

Commit 1b05c85

Browse files
Add metodo para cliente ter varias contas
1 parent 706d4c2 commit 1b05c85

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
/bin/

src/model/Cliente.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package model;
22

3+
import java.util.ArrayList;
4+
35
public class Cliente {
46
/**
57
* O nome do cliente.
@@ -15,7 +17,7 @@ public class Cliente {
1517
/**
1618
* A conta do cliente.
1719
*/
18-
private Conta conta;
20+
private ArrayList<Conta> contas = new ArrayList<>();
1921

2022
/**
2123
* Construtor.
@@ -24,8 +26,20 @@ public class Cliente {
2426
* @param sobrenome
2527
*/
2628
public Cliente(Conta conta, String nome, String sobrenome) {
27-
this.conta = conta;
29+
this.addConta(conta);
2830
this.nome = nome;
2931
this.sobrenome = sobrenome;
3032
}
33+
34+
public ArrayList<Conta> getConta() {
35+
return this.contas;
36+
}
37+
38+
public String getNome() {
39+
return this.nome;
40+
}
41+
42+
public void addConta(Conta conta) {
43+
this.contas.add(conta);
44+
}
3145
}

src/model/Conta.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ public Conta(Agencia agencia, String numero) {
2121
this.agencia = agencia;
2222
this.numero = numero;
2323
}
24+
25+
public Agencia getAgencia() {
26+
return this.agencia;
27+
}
28+
29+
public String getNumero() {
30+
return this.numero;
31+
}
2432
}

src/view/App.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package view;
22

3+
import model.Agencia;
4+
import model.Cliente;
5+
import model.Conta;
6+
37
public class App {
48

59
public static void main(String[] args) {
@@ -8,6 +12,14 @@ public static void main(String[] args) {
812
System.out.println("+------------------------------+");
913
System.out.println("| 1. Criar Cliente |");
1014
System.out.println("+------------------------------+");
15+
16+
Agencia agencia = new Agencia();
17+
Conta conta = new Conta(agencia, "1234");
18+
Conta conta1 = new Conta(agencia, "4321");
19+
Cliente cli = new Cliente(conta, "NomeCliBoladao","SobrenomeBoladao");
20+
System.out.println("Nome: " + cli.getNome() + " Numero Agencia: " + cli.getConta().get(0).getNumero());
21+
cli.addConta(conta1);
22+
System.out.println("Nome: " + cli.getNome() + " Numero Agencia: " + cli.getConta().get(1).getNumero());
1123
}
1224

1325
}

0 commit comments

Comments
 (0)