Last active
May 8, 2020 20:11
-
-
Save jcbombardelli/f060e9c9006c3104be4c9b03f8a4bb4b to your computer and use it in GitHub Desktop.
Exemplos apresentado no dia 04 do curso de Java
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
| package zoologico; | |
| public class Animal { | |
| private double tamanho; // em centimetros | |
| private double peso; // em kgs | |
| private String cor; | |
| private String raca; | |
| private String especie; | |
| private boolean agressivo; | |
| public void setCor(String novaCor) { | |
| cor = novaCor; | |
| } | |
| public String getCor() { | |
| return cor; | |
| } | |
| public void setRaca(String novaRaca) { | |
| raca = novaRaca; | |
| } | |
| public String getRaca() { | |
| return raca; | |
| } | |
| public Animal() { | |
| } | |
| public void emitirSom() { | |
| } | |
| public void comer() { | |
| } | |
| public void xixi() { | |
| } | |
| public void coco() { | |
| } | |
| public void beber() { | |
| } | |
| } |
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
| package zoologico; | |
| public class Ave extends Animal { | |
| public double bico; // em centimetros | |
| public String corPenas; | |
| public int pernas; | |
| public void botarOvo() { | |
| } | |
| public void voar() { | |
| } | |
| } |
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
| package zoologico; | |
| public class Avenstruz extends Ave { | |
| } |
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
| package zoologico; | |
| public class Cachorro extends Mamifero { | |
| public void emitirSom() { | |
| System.out.println("AU AU AU AU !"); | |
| } | |
| // public Cachorro() { | |
| // } | |
| } |
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
| package zoologico; | |
| public class Gato extends Mamifero { | |
| public void emitirSom() { | |
| System.out.println("MIAIU MIAU MIAU !!!"); | |
| } | |
| } |
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
| package zoologico; | |
| /** | |
| * Mamifero | |
| */ | |
| public class Mamifero extends Animal { | |
| public void morder() { | |
| System.out.println("MORDEU!!!!!"); | |
| } | |
| } |
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
| package zoologico; | |
| public class Pato extends Ave { | |
| public void bicar() { | |
| System.out.println("Pato bicando !!"); | |
| } | |
| } |
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
| package zoologico; | |
| public class ProgramaAnimal { | |
| public static void main(String[] args) { | |
| Cachorro cao = new Cachorro(); | |
| cao.setCor("caramelo"); | |
| cao.setRaca("vira-lata"); | |
| System.out.println(cao.getCor()); | |
| System.out.println(cao.getRaca()); | |
| cao.emitirSom(); | |
| cao.morder(); | |
| Gato gato = new Gato(); | |
| gato.setCor("preto"); | |
| gato.setRaca("siames"); | |
| System.out.println(gato.getCor()); | |
| System.out.println(gato.getRaca()); | |
| gato.emitirSom(); | |
| gato.morder(); | |
| Pato patinho = new Pato(); | |
| patinho.setCor("Amarelo"); | |
| patinho.voar(); | |
| System.out.println(patinho.getCor()); | |
| patinho.bicar(); | |
| Avenstruz avenstruz = new Avenstruz(); | |
| avenstruz.corPenas = "Cinza"; | |
| // TODO: Refactor | |
| avenstruz.voar(); | |
| System.out.println(avenstruz.corPenas); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment