Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
public class Animal { | ||
|
||
private String especie; | ||
|
||
private String filo; | ||
|
||
private String genero; | ||
|
||
private String classe; | ||
|
||
private int anoNascimento; | ||
|
||
public Animal(String especie, String classe) { | ||
this.especie = especie; | ||
this.classe = classe; | ||
} | ||
|
||
public void dormir() { | ||
System.out.println("Dormindo..."); | ||
} | ||
|
||
public void mover(int velocidadeEmMilimetrosPorSegundo) { | ||
System.out.println("Movendo-se a " | ||
+ velocidadeEmMilimetrosPorSegundo | ||
+ " mm/s..."); | ||
} | ||
|
||
public void comer() { | ||
System.out.println("Comendo..."); | ||
} | ||
|
||
public String getEspecie() { | ||
return especie; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class Cachorro extends Mamifero { | ||
|
||
public Cachorro() { | ||
super("Canídeo"); | ||
} | ||
|
||
private String raca; | ||
|
||
public void roerOsso() { | ||
System.out.println("Roendo osso..."); | ||
} | ||
|
||
public void latir(int volumeEmDecibeis) { | ||
System.out.println("Latindo a " + volumeEmDecibeis + "decibéis..."); | ||
} | ||
|
||
@Override | ||
public void emitirSom() { | ||
latir(20); | ||
} | ||
|
||
public void pular() { | ||
System.out.println("Pulando..."); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Mamifero extends Animal { | ||
|
||
public Mamifero(String especie) { | ||
super(especie, "Mamífero"); | ||
} | ||
|
||
@Override | ||
public void comer() { | ||
System.out.println("Bebendo leite..."); | ||
} | ||
|
||
public void emitirSom() { | ||
System.out.println("Emitindo algum som genérico de mamífero..."); | ||
} | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Morcego extends Mamifero { | ||
|
||
public Morcego() { | ||
super("Morceguídeo"); | ||
} | ||
|
||
public void voar() { | ||
System.out.println("Voando..."); | ||
} | ||
|
||
@Override | ||
public void emitirSom() { | ||
System.out.println("Emitindo ultrassom de morcego..."); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
public class Principal { | ||
|
||
public static void main(String[] args) { | ||
|
||
Zoologico zoo = new Zoologico(); | ||
|
||
Cachorro caozinho1 = new Cachorro(); | ||
Cachorro caozinho2 = new Cachorro(); | ||
Morcego morcego1 = new Morcego(); | ||
Zebra zebra1 = new Zebra(); | ||
|
||
Animal animalEstranho = new Animal( | ||
"Ornitorrinco da Montanha", "Nem Ele Sabe"); | ||
|
||
zoo.incluirAnimal(caozinho1); | ||
zoo.incluirAnimal(caozinho2); | ||
zoo.incluirAnimal(morcego1); | ||
zoo.incluirAnimal(zebra1); | ||
|
||
// zoo.incluirAnimal(animalEstranho); // não seria aceito! | ||
|
||
for (int i = 0; i < 10; i++) { | ||
Mamifero mamiferoSorteado = zoo.sortearBicho(); | ||
System.out.println("\n" + mamiferoSorteado.getEspecie()); | ||
mamiferoSorteado.emitirSom(); | ||
} | ||
|
||
// mamiferoSorteado.latir(80); // não seria aceito, porque alguns Mamiferos não sabem latir! | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class Zebra extends Mamifero { | ||
|
||
public Zebra() { | ||
super("Zebra"); | ||
} | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import java.util.ArrayList; | ||
import java.util.Random; | ||
|
||
public class Zoologico { | ||
|
||
private static Random random = new Random(); | ||
|
||
private ArrayList<Mamifero> bichos; | ||
|
||
public Zoologico() { | ||
this.bichos = new ArrayList<>(); | ||
} | ||
|
||
public Mamifero sortearBicho() { | ||
int posicao = random.nextInt(this.bichos.size()); | ||
return this.bichos.get(posicao); | ||
} | ||
|
||
public void incluirAnimal(Mamifero bicho) { | ||
this.bichos.add(bicho); | ||
} | ||
} |