Created
December 7, 2019 18:36
-
-
Save canattofilipe/64e555a904c4c27be106e6c55c70e86a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Pessoa { | |
String nome; | |
String sobrenome; | |
public Pessoa(String nome, String sobrenome) { | |
super(); | |
this.nome = nome; | |
this.sobrenome = sobrenome; | |
} | |
@Override | |
public int hashCode() { | |
final int prime = 31; | |
int result = 1; | |
result = prime * result + ((sobrenome == null) ? 0 : sobrenome.hashCode()); | |
return result; | |
} | |
@Override | |
public boolean equals(Object obj) { | |
Pessoa outro = (Pessoa) obj; | |
if (this.sobrenome.equals(outro.sobrenome)) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} | |
public static void main(String[] args) { | |
/* | |
* regras: | |
* - Pessoas da mesma familia sao iguais, devem poder ver a o saldo da conta corrente da familia. | |
* - Pessoas de familia da familia x nao podem ver o saldo da familia y. | |
*/ | |
Map<Pessoa, Long> contaCorrenteCompartilhada = new HashMap<>(); | |
Pessoa filipe = new Pessoa("Filipe", "Canatto"); | |
Pessoa kamily = new Pessoa("Kamily", "Canatto"); | |
Pessoa joao = new Pessoa("Joao", "Doria"); | |
contaCorrenteCompartilhada.put(filipe, Long.valueOf(10000)); | |
System.out.println(contaCorrenteCompartilhada.get(kamily)); | |
System.out.println(contaCorrenteCompartilhada.get(joao)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment