Download presentation
Presentation is loading. Please wait.
Published byAshley Neal Modified over 9 years ago
1
Revisão Herança Polimorfismo Classes Abstratas Interface
2
2 Desafio – Aula05
3
3 1.public class Principal{ 2. // Método main 3. public static void main ( String argv[]) { 4. 5. Object objetos[] = new Object[3];// array 6. objetos[0] = new CartaoProva (75, 25); O que aconteceria se fosse do tipo Pontucao?
4
4 Desafio – Aula05 1. for ( Object esteObjeto : objetos ){ 2. if (esteObjeto instanceof CartaoProva) { 3. CartaoProva prova = (CartaoProva)esteObjeto; 4. System.out.printf ("\nPontos da prova: %.0f\n",prova.calcularPontos()); 5. } 6. if (esteObjeto instanceof ClubeFutebol) { 7. ClubeFutebol futebol = (ClubeFutebol)esteObjeto; 8. System.out.printf ("\nPontos do campeonato: %.0f\n",futebol.calcularPontos()); 9. } 10. if (esteObjeto instanceof ClubeInvestimentos) { 11. ClubeInvestimentos investimento = (ClubeInvestimentos)esteObjeto; 12. System.out.printf ("\nPontos no mercado: %.2f\n\n",investimento.calcularPontos()); 13. } 14. } // fim do for
5
5 Exercício Empregado
6
6 public class Principal{ // Testando o projeto public static void main ( String argv[]) { Pagamento pagamentos[] = new Pagamento[5];// array O que aconteceria se fosse do tipo Empregado?
7
7 Exercício Empregado 1.for (Pagamento pagamentoCorrente : pagamentos){ 2. if (pagamentoCorrente instanceof Empregado) { 3. Empregado emp = (Empregado) pagamentoCorrente; 4. System.out.println ("Empregado:" + emp.getNome()); 5. } 6. else { 7. Fatura fatura = (Fatura) pagamentoCorrente; 8. System.out.println("Fatura:" + fatura.getNome()); 9. } 10. System.out.println("Pagamento: R$ " + 11. String.format("%.2f",pagamentoCorrente.calcularPagamento())); 12. } // fim do for
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.