Skip to content

Instantly share code, notes, and snippets.

@heat
Last active August 29, 2015 14:23
Show Gist options
  • Save heat/2359f79e11241c27e264 to your computer and use it in GitHub Desktop.
Save heat/2359f79e11241c27e264 to your computer and use it in GitHub Desktop.
class Jogador {
String nome;
Integer idade;
Bola bola;
public Jogador(String nome, Integer idade) {
this.nome = nome;
this.idade = idade;
}
public Jogador(String nome, Integer idade, Bola bola) {
this(nome, idade);
this.bola = bola;
}
public void passe(Jogador alvo){
alvo.bola = this.bola;
this.bola = null;
}
public boolean isPosseBola() {
if( bola == null) {
return false;
} else {
return true;
}
}
}
class Bola {
}
class Fifa {
public static void main(String[] args) {
Bola bola = new Bola();
Jogador ronaldinho = new Jogador("Ronaldinho", 29, bola);
Jogador neymar = new Jogador("Neymar Jr.", 29);
//ronaldinho passar a bola para neymar
System.out.println("ronaldinho tem a bola" + ronaldinho.isPosseBola());
// true
ronaldinho.passe(neymar);
System.out.println("ronaldinho tem a bola" + ronaldinho.isPosseBola());
//false
System.out.println("neymar tem a bola" + ronaldinho.isPosseBola());
//true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment