Last active
May 8, 2020 20:15
-
-
Save jcbombardelli/17c30b9fad21ab2bf3d278db9ecdd83e to your computer and use it in GitHub Desktop.
Dia 5 curso java Orientação a Objetos Herança , Polimorfismo e Interfaces
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 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() { | |
| System.out.println("Animal"); | |
| } | |
| 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
| 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
| public class Avestruz 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
| public class Leao extends Mamifero { | |
| public void comer() { | |
| System.out.println("Leão Comendo"); | |
| } | |
| } |
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
| /** | |
| * 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
| public class Pinguim extends Ave { | |
| private String nome; | |
| public void setNome(String novoNome) { | |
| nome = novoNome; | |
| } | |
| public String getNome() { | |
| return nome; | |
| } | |
| public void comer() { | |
| System.out.println("Pinguim Comendo"); | |
| } | |
| public Pinguim(String nomePinguim) { | |
| nome = nomePinguim; | |
| } | |
| public Pinguim() { | |
| nome = ""; | |
| } | |
| } |
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
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.Scanner; | |
| public class Zoologico { | |
| public static void main(String[] args) { | |
| Scanner leitor = new Scanner(System.in); | |
| List<Leao> listaLeoes = new ArrayList<Leao>(); | |
| List<Pinguim> listaPinguins = new ArrayList<Pinguim>(); | |
| List<Avestruz> listaAvestruzes = new ArrayList<Avestruz>(); | |
| int opcaoSelecionada; | |
| do { | |
| menuPrincipal(); | |
| opcaoSelecionada = leitor.nextInt(); | |
| switch (opcaoSelecionada) { | |
| case 1: | |
| System.out.println("-------------------------------------"); | |
| System.out.println("Selecione o animal que deseja incluir"); | |
| System.out.println("1 - Leao"); | |
| System.out.println("2 - Pinguim"); | |
| System.out.println("3 - Avestruz"); | |
| System.out.print("Deigite aqui > "); | |
| int animalSelecionado = leitor.nextInt(); | |
| switch (animalSelecionado) { | |
| case 1: | |
| Leao novoLeao = new Leao(); | |
| listaLeoes.add(novoLeao); | |
| break; | |
| case 2: | |
| Pinguim novoPinguim = new Pinguim(); | |
| listaPinguins.add(novoPinguim); | |
| break; | |
| case 3: | |
| Avestruz novoAvestruz = new Avestruz(); | |
| listaAvestruzes.add(novoAvestruz); | |
| break; | |
| default: | |
| break; | |
| } | |
| break; | |
| case 2: | |
| for (int contador = 0; contador < listaLeoes.size(); contador++) { | |
| Leao elemento = listaLeoes.get(contador); | |
| elemento.comer(); | |
| } | |
| for (int contador = 0; contador < listaPinguins.size(); contador++) { | |
| Pinguim elemento = listaPinguins.get(contador); | |
| elemento.comer(); | |
| } | |
| for (int contador = 0; contador < listaAvestruzes.size(); contador++) { | |
| Avestruz elemento = listaAvestruzes.get(contador); | |
| elemento.comer(); | |
| } | |
| break; | |
| case 3: | |
| System.out.println("----REALIZAR CUIDADOS MÉDICOS----"); | |
| System.out.println("Selecione o animal que deseja incluir"); | |
| int ids = 1; | |
| for (int contador = 0; contador < listaLeoes.size(); contador++) { | |
| Leao elemento = listaLeoes.get(contador); | |
| System.out.println(ids + "- Leão "); | |
| ids++; | |
| } | |
| for (int contador = 0; contador < listaPinguins.size(); contador++) { | |
| Pinguim elemento = listaPinguins.get(contador); | |
| System.out.println(ids + "- Pinguim " + elemento.getNome()); | |
| ids++; | |
| } | |
| for (int contador = 0; contador < listaAvestruzes.size(); contador++) { | |
| Avestruz elemento = listaAvestruzes.get(contador); | |
| System.out.println(ids + " - Avestruz "); | |
| ids++; | |
| } | |
| System.out.print("Deigite aqui > "); | |
| int animalAserCuidado = leitor.nextInt(); | |
| break; | |
| case 99: | |
| Leao leo = new Leao(); | |
| listaLeoes.add(leo); | |
| Pinguim pingo = new Pinguim("pingo"); | |
| listaPinguins.add(pingo); | |
| Pinguim pongo = new Pinguim("pongo"); | |
| listaPinguins.add(pongo); | |
| Avestruz avenildo = new Avestruz(); | |
| listaAvestruzes.add(avenildo); | |
| break; | |
| default: | |
| System.out.println("Opção Invalida. Digite novamente!"); | |
| break; | |
| } | |
| } while (opcaoSelecionada != 0); | |
| } | |
| public static void adicionarNovoAnimal() { | |
| } | |
| public static void cuidadosMedicos() { | |
| } | |
| public static void alimentar() { | |
| } | |
| public static void menuPrincipal() { | |
| System.out.println("---NOSSO ZOOLOGICO---"); | |
| System.out.println("1 - Incluir novo Animal"); | |
| System.out.println("2 - Alimentar o animal"); | |
| System.out.println("3 - Cuidados Médicos"); | |
| System.out.println("99 - Carregar Dados (apenas para testes)"); | |
| System.out.println("0 - Sair"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment