Last active
August 29, 2015 14:23
-
-
Save heat/2359f79e11241c27e264 to your computer and use it in GitHub Desktop.
This file contains 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
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